天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 76|回复: 0

选择实体面然后移动 ARX 代码

[复制链接]
  • TA的每日心情
    开心
    2024-8-31 15:58
  • 签到天数: 89 天

    [LV.6]常住居民II

    488

    主题

    207

    回帖

    3366

    积分

    管理员

    积分
    3366
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    1. #include "StdAfx.h"
    2. // Function declaration
    3. Acad::ErrorStatus acedGetSelFaces(AcDbObjectId& selectedSolidId, AcArray<AcDbSubentId*>& faceSet);
    4. // Function definition
    5. Acad::ErrorStatus acedGetSelFaces(AcDbObjectId& selectedSolidId, AcArray<AcDbSubentId*>& faceSet) {
    6.     // Initialize result to invalid input
    7.     Acad::ErrorStatus result = Acad::eInvalidInput;
    8.     // Prompt the user to select a solid
    9.     ads_name ss;
    10.     int rc = acedSSGet(NULL, NULL, NULL, NULL, ss);
    11.     if (rc != RTNORM) {
    12.         return Acad::eNotApplicable;  // User canceled
    13.     }
    14.     // Check if the selection set is empty
    15.     Adesk::Int32 length;
    16.     acedSSLength(ss, &length);
    17.     if (length == 0) {
    18.         acedSSFree(ss);
    19.         return Acad::eInvalidInput;  // No solids selected
    20.     }
    21.     // Get the first selected entity
    22.     ads_name ent;
    23.     acedSSName(ss, 0, ent);
    24.     // Open the selected entity
    25.     AcDbObjectId objId;
    26.     acdbGetObjectId(objId, ent);
    27.     AcDb3dSolid* solid = nullptr;
    28.     if (acdbOpenObject(solid, objId, AcDb::kForRead) != Acad::eOk) {
    29.         acedSSFree(ss);
    30.         return Acad::eInvalidInput;  // Selected entity is not a solid
    31.     }
    32.     // Store the selected solid ID
    33.     selectedSolidId = objId;
    34.     // Use the selector to select faces
    35.     AcEdSolidSubentitySelector selector;
    36.     result = selector.selectFaces(selectedSolidId, faceSet);
    37.     // Clean up
    38.     acedSSFree(ss);
    39.     solid->close();
    40.     return result;
    41. }
    42. // mycommand
    43. void mySelectFacesCommand() {
    44.     AcDbObjectId selectedSolidId;
    45.     AcArray<AcDbSubentId*> faceSet;
    46.     // Call the custom function
    47.     Acad::ErrorStatus es = acedGetSelFaces(selectedSolidId, faceSet);
    48.     if (es != Acad::eOk) {
    49.         // Handle error cases
    50.         acedAlert(es == Acad::eInvalidInput ? _T("No solids selected.") :
    51.             es == Acad::eNotApplicable ? _T("User canceled input.") :
    52.             _T("Unexpected error occurred."));
    53.         return;
    54.     }
    55.     // Open the solid for write
    56.     AcDb3dSolid* solid = nullptr;
    57.     if (acdbOpenObject(solid, selectedSolidId, AcDb::kForWrite) != Acad::eOk) {
    58.         acedAlert(_T("Failed to open solid for writing."));
    59.         return;
    60.     }
    61.     ads_point basePoint, secondPoint;
    62.     // Prompt the user to select the base point for extrusion
    63.     if (acedGetPoint(NULL, _T("\nSpecify the base point for extrusion: "), basePoint) != RTNORM) {
    64.         acedAlert(_T("Failed to get base point."));
    65.         solid->close();
    66.         return;
    67.     }
    68.     // Prompt the user to select the second point to define the extrusion direction
    69.     if (acedGetPoint(basePoint, _T("\nSpecify the second point for extrusion direction: "), secondPoint) != RTNORM) {
    70.         acedAlert(_T("Failed to get second point."));
    71.         solid->close();
    72.         return;
    73.     }
    74.     // Calculate extrusion direction and distance
    75.     AcGeVector3d extrusionDir(secondPoint[0] - basePoint[0], secondPoint[1] - basePoint[1], secondPoint[2] - basePoint[2]);
    76.     double extrusionDistance = extrusionDir.length();
    77.     // Extrude in the negative direction if necessary
    78.     if (extrusionDir.x < 0 || extrusionDir.y < 0 || extrusionDir.z < 0) {
    79.         extrusionDistance *= -1;
    80.     }
    81.     // Extrude the faces with taper angle set to 0
    82.     Acad::ErrorStatus extrudeStatus = solid->extrudeFaces(faceSet, extrusionDistance, 0.0);
    83.     if (extrudeStatus == Acad::eOk) {
    84.         acutPrintf(_T("\nFaces extruded successfully."));
    85.     }
    86.     else {
    87.         acedAlert(_T("Failed to extrude faces."));
    88.     }
    89.     solid->close();
    90.     // Clean up memory allocated for faceSet
    91.     for (int i = 0; i < faceSet.length(); ++i) {
    92.         delete faceSet[i];
    93.     }
    94.     faceSet.setLogicalLength(0);  // Clear the array
    95. }
    96. // Entry point function
    97. extern "C" __declspec(dllexport)
    98. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) {
    99.     switch (msg) {
    100.     case AcRx::kInitAppMsg:
    101.         acrxDynamicLinker->unlockApplication(pkt);
    102.         acrxDynamicLinker->registerAppMDIAware(pkt);
    103.         acedRegCmds->addCommand(_T("MYCOMMANDS"), _T("MYSELECTFACES"), _T("SELECTFACES"), ACRX_CMD_MODAL, mySelectFacesCommand);
    104.         break;
    105.     case AcRx::kUnloadAppMsg:
    106.         acedRegCmds->removeGroup(_T("MYCOMMANDS"));
    107.         break;
    108.     default:
    109.         break;
    110.     }
    111.     return AcRx::kRetOK;
    112. }
    复制代码

     

     

     

     

    选择实体面然后移动 ARX 代码
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池| |网站地图

    GMT+8, 2024-9-8 09:18 , Processed in 0.073257 second(s), 26 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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