新建一个ObjectARX项目后,在acrxEntryPoint中的static void MyGroupMyCommand ()后面加上如下代码:
static void MyGroupMyCommand () {
AcDbObjectId lineId;
lineId = CreateLine();
ChangeColor(lineId, 1);
}
static AcDbObjectId 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;
}
static Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex)
{
AcDbEntity *pEntity;
acdbOpenObject(pEntity, entId, AcDb::kForWrite);
pEntity->setColorIndex(colorIndex);
pEntity->close();
return Acad::eOk;
}