- 积分
- 12459
- 明经币
- 个
- 注册时间
- 2003-5-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-12-2 17:07:00
|
显示全部楼层
回复
参考:
void createNewLayer(char* lyrname, Adesk::UInt16 clr, AcDbObjectId ltypeId, Adesk::Boolean current)
{
// We need to check if the layer name exists
// If the layer name exists, apply the color
// linetype id and whither to make it current
// or not. In order to be current it cannot be
// frozen, so we need to check for this also.
// If the layer name does not exist we just create
// a new layer with the properties contained in the arguments
AcDbLayerTable *pLyrTable;
AcDbLayerTableRecord *pLyrTblRecord;
AcDbObjectId recId;
AcCmColor color;
color.setColorIndex(clr); // set color to parameter clr
AcDbDatabase *pCurDb = NULL;
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
// Check to see if the layer name exists
if(pLyrTable->has(lyrname))
{
pLyrTable->getAt(lyrname, pLyrTblRecord, AcDb::kForWrite, Adesk::kFalse);
// pLyrTblRecord now points at the layer table record
// which was opened for write
pLyrTblRecord->setIsFrozen(Adesk::kFalse);
pLyrTblRecord->setColor(color);
pLyrTblRecord->setLinetypeObjectId(ltypeId);
}
else
{
// Note how we can change the open mode
// of the layer table from AcDb::kForRead
// to AcDb::kForWrite
pLyrTable->upgradeOpen();
pLyrTblRecord = new AcDbLayerTableRecord;
pLyrTblRecord->setName(lyrname);
pLyrTblRecord->setColor(color);
pLyrTblRecord->setLinetypeObjectId(ltypeId);
pLyrTable->add(pLyrTblRecord);
}
// Get the layer Table ObjectId
recId = pLyrTblRecord->objectId();
pLyrTblRecord->close();
pLyrTable->close();
// Set the layer current if current
// is equal to Adesk::kTrue
// pCurDb is point to the current
// drawing database
// The database AcDbDatabase has a number of
// query and edit functions for the header variables
if(current)
{
pCurDb->setClayer(recId);
}
} |
|