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