- UID
- 153624
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-6-29
- 最后登录
- 1970-1-1
|
发表于 2004-12-9 12:13:48
|
显示全部楼层
//*********************************************************************************
//** 函 数 名:SetCurLayer
//** 功能描述:设置指定层为当前层.如果没有则创建一个设置为当前层
//** 变量名:LayerName 变量类型:CString 变量说明:层名(输入)
//** 变量名:Colour 变量类型:int 变量说明:层颜色(输入)
//*********************************************************************************
void SetCurLayer(CString LayerName,int Colour)
{
AcDbLayerTable * pLayerTbl;//定义层表指针
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite); //以写方式打开层表,获得层表指针
AcDbObjectId LayerID;//定义层的ID号
if (Acad::eOk==(pLayerTbl->getAt(LayerName,LayerID,Adesk::kFalse)))
{//如层layname存在,则设为当前层
pLayerTbl->close();
acdbHostApplicationServices()->workingDatabase()->setClayer(LayerID);
}
else//没有外墙层
{
pLayerTbl->close();
CArxUtils::CreateLayer(LayerName,Colour);
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite); //以写方式打开层表,获得层表指针
if (Acad::eOk==(pLayerTbl->getAt(LayerName,LayerID,Adesk::kFalse)))
{
pLayerTbl->close();
acdbHostApplicationServices()->workingDatabase()->setClayer(LayerID);
}
}
pLayerTbl->close();
}
//*********************************************************************************
//** 函 数 名:CreateLayer
//** 功能描述:创建层
//** 变量名:LayerName 变量类型:CString 变量说明:层名(输入)
//** 变量名:color 变量类型:int 变量说明:层颜色(输入)
//*********************************************************************************
AcDbObjectId CArxUtils::CreateLayer(const CString LayerName, const int color)
{
AcDbObjectId recordId;
AcDbLayerTable *pLayerTable;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, AcDb::kForWrite);
if(pLayerTable->has((char*)LPCTSTR(LayerName)))//如果层存在
{
pLayerTable->getAt((char*)LPCTSTR(LayerName),recordId,FALSE);
pLayerTable->close();
return recordId;
}
else //如果层不存在
{
AcDbLayerTableRecord *pLayerTableRecord = new AcDbLayerTableRecord;
pLayerTableRecord->setName((char*)LPCTSTR(LayerName));
AcCmColor layerColor;
layerColor.setColorIndex(color);
pLayerTableRecord->setColor(layerColor);
AcDbLinetypeTable *pLinetypeTbl;
acdbHostApplicationServices()->workingDatabase()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
AcDbObjectId ltypeObjId;
pLinetypeTbl->getAt("CONTINUOUS", ltypeObjId); //设置层颜色
pLayerTableRecord->setLinetypeObjectId(ltypeObjId);
pLayerTable->add(recordId,pLayerTableRecord);
pLayerTable->close();
pLayerTableRecord->close();
return recordId;
}
} |
|