TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
- // Function definition
- static Acad::ErrorStatus acedGetSelFaces(AcDbObjectId& selectedSolidId, AcArray<AcDbSubentId*>& faceSet) {
- // Initialize result to invalid input
- Acad::ErrorStatus result = Acad::eInvalidInput;
- // Prompt the user to select a solid
- ads采用name ss;
- int rc = acedSSGet(NULL, NULL, NULL, NULL, ss);
- if (rc != RTNORM) {
- return Acad::eNotApplicable; // User canceled
- }
- // Check if the selection set is empty
- Adesk::Int32 length;
- acedSSLength(ss, &length);
- if (length == 0) {
- acedSSFree(ss);
- return Acad::eInvalidInput; // No solids selected
- }
- // Get the first selected entity
- ads采用name ent;
- acedSSName(ss, 0, ent);
- // Open the selected entity
- AcDbObjectId objId;
- acdbGetObjectId(objId, ent);
- AcDb3dSolid* solid = nullptr;
- if (acdbOpenObject(solid, objId, AcDb::kForRead) != Acad::eOk) {
- acedSSFree(ss);
- return Acad::eInvalidInput; // Selected entity is not a solid
- }
- // Store the selected solid ID
- selectedSolidId = objId;
- // Use the selector to select faces
- AcEdSolidSubentitySelector selector;
- result = selector.selectFaces(selectedSolidId, faceSet);
- // Clean up
- acedSSFree(ss);
- solid->close();
- return result;
- }
- // mycommand 选择实体面然后移动
- static void mySelectFacesCommand() {
- AcDbObjectId selectedSolidId;
- AcArray<AcDbSubentId*> faceSet;
- // Call the custom function
- Acad::ErrorStatus es = acedGetSelFaces(selectedSolidId, faceSet);
- if (es != Acad::eOk) {
- // Handle error cases
- acedAlert(es == Acad::eInvalidInput ? 采用T("No solids selected.") :
- es == Acad::eNotApplicable ? 采用T("User canceled input.") :
- 采用T("Unexpected error occurred."));
- return;
- }
- // Open the solid for write
- AcDb3dSolid* solid = nullptr;
- if (acdbOpenObject(solid, selectedSolidId, AcDb::kForWrite) != Acad::eOk) {
- acedAlert(采用T("Failed to open solid for writing."));
- return;
- }
- ads采用point basePoint, secondPoint;
- // Prompt the user to select the base point for extrusion
- if (acedGetPoint(NULL, 采用T("\nSpecify the base point for extrusion: "), basePoint) != RTNORM) {
- acedAlert(采用T("Failed to get base point."));
- solid->close();
- return;
- }
- // Prompt the user to select the second point to define the extrusion direction
- if (acedGetPoint(basePoint, 采用T("\nSpecify the second point for extrusion direction: "), secondPoint) != RTNORM) {
- acedAlert(采用T("Failed to get second point."));
- solid->close();
- return;
- }
- // Calculate extrusion direction and distance
- AcGeVector3d extrusionDir(secondPoint[0] - basePoint[0], secondPoint[1] - basePoint[1], secondPoint[2] - basePoint[2]);
- double extrusionDistance = extrusionDir.length();
- // Extrude in the negative direction if necessary
- if (extrusionDir.x < 0 || extrusionDir.y < 0 || extrusionDir.z < 0) {
- extrusionDistance *= -1;
- }
- // Extrude the faces with taper angle set to 0
- Acad::ErrorStatus extrudeStatus = solid->extrudeFaces(faceSet, extrusionDistance, 0.0);
- if (extrudeStatus == Acad::eOk) {
- acutPrintf(采用T("\nFaces extruded successfully."));
- }
- else {
- acedAlert(采用T("Failed to extrude faces."));
- }
- solid->close();
- // Clean up memory allocated for faceSet
- for (int i = 0; i < faceSet.length(); ++i) {
- delete faceSet[i];
- }
- faceSet.setLogicalLength(0); // Clear the array
- }
复制代码 |
|