找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 182|回复: 0

拉伸实体一个面

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-6-12 19:12:38 | 显示全部楼层 |阅读模式
  1. // Function definition
  2. static  Acad::ErrorStatus acedGetSelFaces(AcDbObjectId& selectedSolidId, AcArray<AcDbSubentId*>& faceSet) {
  3.         // Initialize result to invalid input
  4.         Acad::ErrorStatus result = Acad::eInvalidInput;
  5.         // Prompt the user to select a solid
  6.         ads采用name ss;
  7.         int rc = acedSSGet(NULL, NULL, NULL, NULL, ss);
  8.         if (rc != RTNORM) {
  9.                 return Acad::eNotApplicable;  // User canceled
  10.         }
  11.         // Check if the selection set is empty
  12.         Adesk::Int32 length;
  13.         acedSSLength(ss, &length);
  14.         if (length == 0) {
  15.                 acedSSFree(ss);
  16.                 return Acad::eInvalidInput;  // No solids selected
  17.         }
  18.         // Get the first selected entity
  19.         ads采用name ent;
  20.         acedSSName(ss, 0, ent);
  21.         // Open the selected entity
  22.         AcDbObjectId objId;
  23.         acdbGetObjectId(objId, ent);
  24.         AcDb3dSolid* solid = nullptr;
  25.         if (acdbOpenObject(solid, objId, AcDb::kForRead) != Acad::eOk) {
  26.                 acedSSFree(ss);
  27.                 return Acad::eInvalidInput;  // Selected entity is not a solid
  28.         }
  29.         // Store the selected solid ID
  30.         selectedSolidId = objId;
  31.         // Use the selector to select faces
  32.         AcEdSolidSubentitySelector selector;
  33.         result = selector.selectFaces(selectedSolidId, faceSet);
  34.         // Clean up
  35.         acedSSFree(ss);
  36.         solid->close();
  37.         return result;
  38. }
  39. // mycommand  选择实体面然后移动
  40. static  void mySelectFacesCommand() {
  41.         AcDbObjectId selectedSolidId;
  42.         AcArray<AcDbSubentId*> faceSet;
  43.         // Call the custom function
  44.         Acad::ErrorStatus es = acedGetSelFaces(selectedSolidId, faceSet);
  45.         if (es != Acad::eOk) {
  46.                 // Handle error cases
  47.                 acedAlert(es == Acad::eInvalidInput ? 采用T("No solids selected.") :
  48.                         es == Acad::eNotApplicable ? 采用T("User canceled input.") :
  49.                         采用T("Unexpected error occurred."));
  50.                 return;
  51.         }
  52.         // Open the solid for write
  53.         AcDb3dSolid* solid = nullptr;
  54.         if (acdbOpenObject(solid, selectedSolidId, AcDb::kForWrite) != Acad::eOk) {
  55.                 acedAlert(采用T("Failed to open solid for writing."));
  56.                 return;
  57.         }
  58.         ads采用point basePoint, secondPoint;
  59.         // Prompt the user to select the base point for extrusion
  60.         if (acedGetPoint(NULL, 采用T("\nSpecify the base point for extrusion: "), basePoint) != RTNORM) {
  61.                 acedAlert(采用T("Failed to get base point."));
  62.                 solid->close();
  63.                 return;
  64.         }
  65.         // Prompt the user to select the second point to define the extrusion direction
  66.         if (acedGetPoint(basePoint, 采用T("\nSpecify the second point for extrusion direction: "), secondPoint) != RTNORM) {
  67.                 acedAlert(采用T("Failed to get second point."));
  68.                 solid->close();
  69.                 return;
  70.         }
  71.         // Calculate extrusion direction and distance
  72.         AcGeVector3d extrusionDir(secondPoint[0] - basePoint[0], secondPoint[1] - basePoint[1], secondPoint[2] - basePoint[2]);
  73.         double extrusionDistance = extrusionDir.length();
  74.         // Extrude in the negative direction if necessary
  75.         if (extrusionDir.x < 0 || extrusionDir.y < 0 || extrusionDir.z < 0) {
  76.                 extrusionDistance *= -1;
  77.         }
  78.         // Extrude the faces with taper angle set to 0
  79.         Acad::ErrorStatus extrudeStatus = solid->extrudeFaces(faceSet, extrusionDistance, 0.0);
  80.         if (extrudeStatus == Acad::eOk) {
  81.                 acutPrintf(采用T("\nFaces extruded successfully."));
  82.         }
  83.         else {
  84.                 acedAlert(采用T("Failed to extrude faces."));
  85.         }
  86.         solid->close();
  87.         // Clean up memory allocated for faceSet
  88.         for (int i = 0; i < faceSet.length(); ++i) {
  89.                 delete faceSet[i];
  90.         }
  91.         faceSet.setLogicalLength(0);  // Clear the array
  92. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-6 15:28 , Processed in 0.123112 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表