[原创][ARX]生成图层和设置线型(类型、颜色、线宽)
和大家一起分享生成图层和设置线型(类型、颜色、线宽)的简单东东。AcDbLayerTable *pLayerTable;
acdbCurDwg()->getLayerTable(pLayerTable, AcDb::kForWrite);
AcDbLayerTableRecord *pLayerTableRecord1 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord2 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord3 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord4 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord5 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord6 = new AcDbLayerTableRecord;
pLayerTableRecord1->setName("A");
pLayerTableRecord2->setName("B");
pLayerTableRecord3->setName("C");
pLayerTableRecord4->setName("D");
pLayerTableRecord5->setName("E");
pLayerTableRecord6->setName("F");
AcCmColor color;
color.setColorIndex(1);
pLayerTableRecord1->setColor(color);
pLayerTableRecord1->setLineWeight(AcDb:ineWeight::kLnWt018);//
color.setColorIndex(5);
pLayerTableRecord2->setColor(color);
pLayerTableRecord2->setLineWeight(AcDb:ineWeight::kLnWt050);
color.setColorIndex(4);
pLayerTableRecord3->setColor(color);
pLayerTableRecord3->setLineWeight(AcDb:ineWeight::kLnWt018);
color.setColorIndex(6);
pLayerTableRecord4->setColor(color);
pLayerTableRecord4->setLineWeight(AcDb:ineWeight::kLnWt018);
color.setColorIndex(3);
pLayerTableRecord5->setColor(color);
pLayerTableRecord5->setLineWeight(AcDb:ineWeight::kLnWt018);
color.setColorIndex(2);
pLayerTableRecord6->setColor(color);
pLayerTableRecord6->setLineWeight(AcDb:ineWeight::kLnWt018);
AcDbLinetypeTable *pLinetypeTbl;
AcDbObjectId DashedLineId, CenterLineId,DivideLineId;
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
if ((pLinetypeTbl->getAt("DASHED",DashedLineId))!=Acad::eOk);
{
pLinetypeTbl->close();
acdbCurDwg()->loadLineTypeFile("DASHED","acadiso.lin");
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl->getAt("DASHED",DashedLineId);
}
if ((pLinetypeTbl->getAt("CENTER",CenterLineId))!=Acad::eOk);
{
pLinetypeTbl->close();
acdbCurDwg()->loadLineTypeFile("CENTER","acadiso.lin");
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl->getAt("CENTER",CenterLineId);
}
if ((pLinetypeTbl->getAt("DIVIDE",DivideLineId))!=Acad::eOk);
{
pLinetypeTbl->close();
acdbCurDwg()->loadLineTypeFile("DIVIDE","acadiso.lin");
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl->getAt("DIVIDE",DivideLineId);
}
pLinetypeTbl->close();
pLayerTableRecord1->setLinetypeObjectId(CenterLineId);
pLayerTableRecord4->setLinetypeObjectId(DashedLineId);
pLayerTableRecord5->setLinetypeObjectId(DivideLineId);
pLayerTable->add(pLayerTableRecord1);
pLayerTable->add(pLayerTableRecord2);
pLayerTable->add(pLayerTableRecord3);
pLayerTable->add(pLayerTableRecord4);
pLayerTable->add(pLayerTableRecord5);
pLayerTable->add(pLayerTableRecord6);
pLayerTableRecord1->close();
pLayerTableRecord2->close();
pLayerTableRecord3->close();
pLayerTableRecord4->close();
pLayerTableRecord5->close();
pLayerTableRecord6->close();
pLayerTable->close(); 上述过程还可以用C语言格式书写.
生成新的图层.
ads_tblobjname("layer","0",ent);
rb=ads_entget(ent);
assoc_dxf_str(rb,1,new_layername);
assoc_dxf_int(rb,0,new_color);
ads_entmod(rb);
ads_relrb(rb);
其中assoc_dxf_int为链表替换程序!
累死了,可不可以这么写?
//添加层
AcDbObjectId CLjDwg::AddLayer(const char* LayerName,
const Adesk::Int16 LayerColor,
const char* Linetype,
AcDbDatabase* pDb)
{
if(pDb==NULL)
pDb=acdbCurDwg();
//装载线型
pDb->loadLineTypeFile(Linetype,LINETYPE_FILENAME);
AcDbObjectId LineTypeId=AddLineType(pDb,Linetype);
AcDbLayerTable* pLayerTable=NULL;
AcDbLayerTableRecord* pLayerRecord=NULL;
AcDbObjectId LayerId=AcDbObjectId::kNull;
pDb->getLayerTable(pLayerTable,AcDb::kForWrite);
if(!pLayerTable)
return FALSE;
if(pLayerTable->has(LayerName))
{
pLayerTable->getAt(LayerName,LayerId);
}
else
{
pLayerRecord=new AcDbLayerTableRecord;
AcCmColor color;
color.setColorIndex(LayerColor);
pLayerRecord->setColor(color);
pLayerRecord->setLinetypeObjectId(LineTypeId);
pLayerRecord->setName(LayerName);
pLayerTable->add(LayerId,pLayerRecord);
pLayerRecord->close();
}
pLayerTable->close();
return LayerId;
}
太好了,刚好在学这里,真是太感谢了!!
相当谢谢
很好,正需要这个呢
页:
[1]