拉伸实体一个面
// Function definitionstaticAcad::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选择实体面然后移动
staticvoid 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 - basePoint, secondPoint - basePoint, secondPoint - basePoint);
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;
}
faceSet.setLogicalLength(0);// Clear the array
}
页:
[1]