TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 2024-8-31 15:58 |
---|
签到天数: 89 天 [LV.6]常住居民II
管理员
- 积分
- 3366
|
- #include "StdAfx.h"
- // Function declaration
- Acad::ErrorStatus acedGetSelFaces(AcDbObjectId& selectedSolidId, AcArray<AcDbSubentId*>& faceSet);
- // Function definition
- 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
- 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
- }
- // Entry point function
- extern "C" __declspec(dllexport)
- AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) {
- switch (msg) {
- case AcRx::kInitAppMsg:
- acrxDynamicLinker->unlockApplication(pkt);
- acrxDynamicLinker->registerAppMDIAware(pkt);
- acedRegCmds->addCommand(_T("MYCOMMANDS"), _T("MYSELECTFACES"), _T("SELECTFACES"), ACRX_CMD_MODAL, mySelectFacesCommand);
- break;
- case AcRx::kUnloadAppMsg:
- acedRegCmds->removeGroup(_T("MYCOMMANDS"));
- break;
- default:
- break;
- }
- return AcRx::kRetOK;
- }
复制代码 |
|