cpp文件:
#include "aced.h" #include "rxregsvc.h" #include "string.h" #include "aced.h" #include "dbents.h" #include "dbsymtb.h" #include "dbgroup.h" #include "dbapserv.h"
AcDbObjectId createNewLine(); AcDbObjectId createNewCircle(); AcDbObjectId createNewLayer();
void createNewGroup();
Acad::ErrorStatus changeColor(AcDbObjectId,Adesk::UInt16);
AcDbObjectId createNewLine() { AcGePoint3d startPoint(5.0,4.0,0.0); AcGePoint3d endPoint(15.0,10.0,0.0); AcDbLine *pLine=new AcDbLine(startPoint,endPoint); AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable,AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); pBlockTable->close(); AcDbObjectId lineId; pBlockTableRecord->appendAcDbEntity(lineId,pLine); pBlockTableRecord->close(); pLine->close(); return lineId;
}
AcDbObjectId createNewCircle() { AcGePoint3d center(10.0,7.0,0.0); AcGeVector3d normal(0.0,0.0,1.0); AcDbCircle *pCirc=new AcDbCircle(center,normal,4.5); AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable,AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); pBlockTable->close(); AcDbObjectId circleId; pBlockTableRecord->appendAcDbEntity(circleId,pCirc); pBlockTableRecord->close(); pCirc->close(); return circleId; }
AcDbObjectId createNewLayer() { AcDbLayerTable *pLayerTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTable,AcDb::kForWrite); AcDbLayerTableRecord *pLayerTableRecord=new AcDbLayerTableRecord; pLayerTableRecord->setName("MYNewLayer"); AcDbObjectId pLayerId; pLayerTable->add(pLayerId,pLayerTableRecord); pLayerTable->close(); pLayerTableRecord->close(); return pLayerId; }
Acad::ErrorStatus changeColor(AcDbObjectId entId,Adesk::UInt16 newColor) { AcDbEntity *pEntity; acdbOpenObject(pEntity,entId,AcDb::kForWrite); pEntity->setColorIndex(newColor); pEntity->close(); return Acad::eOk; }
void createNewGroup (AcDbObjectIdArray & objIds,char * pGroupName,AcDbObjectId pLayerId) { AcDbGroup *pGroup=new AcDbGroup(pGroupName); for(int i=0; i<objIds.length(); i++) { pGroup->append(objIds); } AcDbDictionary *pGroupDict; acdbHostApplicationServices()->workingDatabase() ->getGroupDictionary(pGroupDict,AcDb::kForWrite); AcDbObjectId pGroupId; pGroupDict->setAt(pGroupName,pGroup,pGroupId); pGroup->setLayer(pLayerId); pGroupDict->close(); pGroup->close(); }
void runIt() { AcDbObjectId newLayerId=createNewLayer(); AcDbObjectIdArray idArray; idArray.append(createNewLine()); idArray.append(createNewCircle()); changeColor(idArray.first(),1); changeColor(idArray.last(),3); createNewGroup(idArray,"MyNewGroup",newLayerId); }
void initApp() { acedRegCmds->addCommand("ASDK_MAKE_ENTITIES", "ASDK_MakeNewEnts", "MakeNewEnts", ACRX_CMD_MODAL, runIt); }
void unloadApp() { acedRegCmds->removeGroup("ASDK_MAKE_ENTITIES"); }
extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg,void * appId) { switch(msg) { case AcRx::kInitAppMsg: acrxDynamicLinker->unlockApplication(appId); acrxDynamicLinker->registerAppMDIAware(appId); initApp(); break; case AcRx::kUnloadAppMsg: unloadApp(); } return AcRx::kRetOK; } |