1、创建工程CreateEnts
2、添加类CCreateEnt,在文件CreateEnt.h中添加函数声明,在CreateEnt.cpp添加函数实现代码:
static AcDbObjectId CreateLine();
AcDbObjectId CCreateEnt::CreateLine() { AcGePoint3d ptStart(0,0,0); AcGePoint3d ptEnd(100,100,0); AcDbLine *pLine = new AcDbLine(ptStart, ptEnd); AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlockTable,AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRocord; pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRocord, AcDb::kForWrite); AcDbObjectId lineId; pBlockTableRocord -> appendAcDbEntity(lineId, pLine); pBlockTable -> close(); pBlockTableRocord -> close(); pLine -> close(); return lineId; }
3、添加类CModifyEnt,在文件CModifyEnt.h中添加函数声明,在CModifyEnt.cpp添加函数实现代码:
static Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex);
Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex) { AcDbEntity *pEntity; //打开图像数据库中的对象 acdbOpenObject(pEntity, entId,AcDb::kForWrite); //修改实体颜色 pEntity->setColorIndex(colorIndex); pEntity->close(); return Acad::eOk; }
4、在ObjectARX中注册新命令_ChangColor。首先应用之前的两个头文件,最后添加命令的实现代码:
#include "CreateEnt.h" #include "ModifyEnt.h"
// - qxzyCreateEnts._ChangeColor command (do not rename) static void qxzyCreateEnts_ChangeColor(void) { // Add your code for command qxzyCreateEnts._ChangeColor here AcDbObjectId lineId; lineId = CCreateEnt::CreateLine(); CModifyEnt::ChangeColor(lineId, 1); }
最后编译
转载:http://blog.csdn.net/foreverling/article/details/26587933