c++ caxa批量标注圆的中心线
c我是一行都看不懂// CrxEntryPoint.cpp : MyCaxa CRX application entry point#includestdafx.h#includeresource.h#includecrxutcds.h#includecrxedcds.h#includecdscodes.h#includecrxdb.h#includedbapserv.h#includedbents.h#includedbsymtb.hstaticconstTCHAR*kCenterLayerNames[]{_T(中心线层),_T(中心线),_T(CENTER),_T(Center),nullptr};staticconstTCHAR*kCenterLinetypeNames[]{_T(CENTER),_T(CENTER2),_T(CENTERLINE),_T(中心线),nullptr};staticconstTCHAR*kDefaultCenterLayerName_T(中心线层);staticboolResolveCenterLayerId(CRxDbObjectIdlayerId,constTCHAR*outName){CRxDbDatabase*dbcrxdbHostApplicationServices()-workingDatabase();if(!db)returnfalse;CRxDbLayerTable*pLayerTblnullptr;if(db-getLayerTable(pLayerTbl,CRxDb::kForRead)!CDraft::eOk)returnfalse;for(inti0;kCenterLayerNames[i];i){if(pLayerTbl-has(kCenterLayerNames[i])){pLayerTbl-getAt(kCenterLayerNames[i],layerId);outNamekCenterLayerNames[i];pLayerTbl-close();returntrue;}}pLayerTbl-close();if(db-getLayerTable(pLayerTbl,CRxDb::kForWrite)!CDraft::eOk)returnfalse;CRxDbLayerTableRecord*pLayerRecnewCRxDbLayerTableRecord();pLayerRec-setName(kDefaultCenterLayerName);CRxDbLinetypeTable*pLtTblnullptr;if(db-getLinetypeTable(pLtTbl,CRxDb::kForRead)CDraft::eOk){CRxDbObjectId ltId;for(inti0;kCenterLinetypeNames[i];i){if(pLtTbl-has(kCenterLinetypeNames[i])){pLtTbl-getAt(kCenterLinetypeNames[i],ltId);pLayerRec-setLinetypeObjectId(ltId);break;}}pLtTbl-close();}if(pLayerTbl-add(layerId,pLayerRec)!CDraft::eOk){deletepLayerRec;pLayerTbl-close();returnfalse;}pLayerRec-close();pLayerTbl-close();outNamekDefaultCenterLayerName;returntrue;}staticboolAppendLineToModelSpace(constCRxGePoint3dptStart,constCRxGePoint3dptEnd,constCRxDbObjectIdlayerId){if(ptStart.distanceTo(ptEnd)1e-6)returnfalse;CRxDbLine*pLinenewCRxDbLine(ptStart,ptEnd);pLine-setLayer(layerId);pLine-setColorIndex(CRxCm::kACIByLayer);CRxDbDatabase*dbcrxdbHostApplicationServices()-workingDatabase();CRxDbBlockTable*pBlockTablenullptr;if(db-getSymbolTable(pBlockTable,CRxDb::kForRead)!CDraft::eOk){deletepLine;returnfalse;}CRxDbBlockTableRecord*pSpacenullptr;if(pBlockTable-getAt(CRXDB_MODEL_SPACE,pSpace,CRxDb::kForWrite)!CDraft::eOk){pBlockTable-close();deletepLine;returnfalse;}CRxDbObjectId newId;pSpace-appendAcDbEntity(newId,pLine);pSpace-close();pBlockTable-close();pLine-close();returntrue;}staticboolDrawCenterLinesOnCircle(CRxDbCircle*pCircle,constCRxDbObjectIdlayerId){if(!pCircle)returnfalse;constCRxGePoint3d cpCircle-center();constdoublerpCircle-radius();if(r1e-6)returnfalse;constdoubleextr*1.2;CRxGeVector3d axCRxGeVector3d::kXAxis;CRxGeVector3d ayCRxGeVector3d::kYAxis;constboolok1AppendLineToModelSpace(c-ax*ext,cax*ext,layerId);constboolok2AppendLineToModelSpace(c-ay*ext,cay*ext,layerId);returnok1||ok2;}staticboolDrawCenterLineOnCircleEntity(constcrx_name ent,constCRxDbObjectIdlayerId){CRxDbObjectId objId;if(crxdbGetObjectId(objId,ent)!CDraft::eOk)returnfalse;CRxDbEntity*pEntnullptr;if(crxdbOpenCRxDbEntity(pEnt,objId,CRxDb::kForRead)!CDraft::eOk)returnfalse;CRxDbCircle*pCircleCRxDbCircle::cast(pEnt);constboolokpCircle?DrawCenterLinesOnCircle(pCircle,layerId):false;pEnt-close();returnok;}voidCmdCrossCenter(){CRxDbObjectId layerId;constTCHAR*layerNamenullptr;if(!ResolveCenterLayerId(layerId,layerName)){crxutPrintf(_T(\n无法获取或创建中心线图层。));return;}// 不用 DXF0 过滤CAXA 2015 实体类型名与 AutoCAD 不一致会导致选不到任何对象。// 选线后在代码里只对圆CRxDbCircle画中心线直线等自动跳过。crx_name ss;intrtcrxedSSGet(_T(_I),NULL,NULL,NULL,ss);if(rt!RTNORM)rtcrxedSSGet(NULL,NULL,NULL,NULL,ss);if(rt!RTNORM){crxutPrintf(_T(\n未选择对象。));return;}longlength0;crxedSSLength(ss,length);intcount0;for(longi0;ilength;i){crx_name ent;crxedSSName(ss,i,ent);if(DrawCenterLineOnCircleEntity(ent,layerId))count;}crxedSSFree(ss);crxutPrintf(_T(\n已在图层 [%s] 为 %d 个圆绘制中心线共选 %ld 个对象非圆已跳过。),layerName,count,length);}classCMyCaxaApp:publicAcRxArxApp{public:CMyCaxaApp():AcRxArxApp(){}virtualAcRx::AppRetCodeOn_kInitAppMsg(void*pkt){AcRx::AppRetCode retCodeAcRxArxApp::On_kInitAppMsg(pkt);crxedRegCmds-addCommand(_T(MyCaxaApp),_T(GCrossCenter),_T(CrossCenter),ACRX_CMD_MODAL,CmdCrossCenter);returnretCode;}virtualAcRx::AppRetCodeOn_kUnloadAppMsg(void*pkt){AcRx::AppRetCode retCodeAcRxArxApp::On_kUnloadAppMsg(pkt);crxedRegCmds-removeGroup(_T(MyCaxaApp));returnretCode;}virtualvoidRegisterServerComponents(){}};IMPLEMENT_ARX_ENTRYPOINT(CMyCaxaApp)