|
[code]一、AutoCAD的实体类
AcDbEntity类常用的查询函数
1)AcDbObjectId AcDbEntity::blockId() const 函数
说明:该函数返回实体拥有者的对象ID,实体拥有者一定是 AcDbBlockTableRecord 类对象。
实例:假定我们定义了 AcDbLine *pLine,且实体是在模型空间,则下面的代码返回*MODEL_SPACE(也可以写为ACDB_MODEL_SPACE)块表记录的对象ID:
AcDbObjectId btrId;
btrId = pLine->blockId();
2)AcDbEntity::color() 函数
说明:用一个AcCmColor类的实体返回实体的AutoCAD颜色号。颜色号的取值范围是:0-256。AcCmColor类是AutoCAD的颜色模型类,它是AcCmComplexColor类的“外壳”。直接对实体使用AcCmColor类不太可能,它有一个成员函数AcCmColor::colorIndex(),返回Adesk::Uint16数据类型。你最可能使用AcDbEntity::colorIndex()函数,它也返回Adesk::Uint16数据类型直接得到颜色号。程序代码如下:
void createLineAndGetColor()
{
AcGePoint3d startPt(4.0, 2.0, 0.0);
AcGePoint3d endPt(5.0, 12.0, 0.0);
AcDbLine *pLine = new AcDbLine(startPt, endPt);
AcDbBlockTable *pBlkTable;
AcDbDatabase *pCurDb;
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTableRecord;
pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);
pBlkTable->close();
AcDbObjectId lineId;
pBlkTableRecord->appendAcDbEntity(lineId, pLine);
Adesk::UInt16 colVal;
AcCmColor col;
col = pLine->color();
// 获取颜色号的两种写法
colVal = col.colorIndex();
colVal = pLine->colorIndex();
pBlkTableRecord->close();
pLine->close();
}[/code] |
|