ddpo1982 发表于 2006-5-29 11:45:00

[原创][ARX]生成图层和设置线型(类型、颜色、线宽)

<FONT face=宋体 size=2>和大家一起分享生成图层和设置线型(类型、颜色、线宽)的简单东东。<BR><BR>AcDbLayerTable *pLayerTable;<BR>acdbCurDwg()-&gt;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-&gt;setName("A");<BR>pLayerTableRecord2-&gt;setName("B");<BR>pLayerTableRecord3-&gt;setName("C");<BR>pLayerTableRecord4-&gt;setName("D");<BR>pLayerTableRecord5-&gt;setName("E");<BR>pLayerTableRecord6-&gt;setName("F");<BR><BR>AcCmColor color;<BR>color.setColorIndex(1);<BR>pLayerTableRecord1-&gt;setColor(color); <BR>pLayerTableRecord1-&gt;setLineWeight(AcDb::LineWeight::kLnWt018);//<BR><BR>color.setColorIndex(5);<BR>pLayerTableRecord2-&gt;setColor(color);<BR>pLayerTableRecord2-&gt;setLineWeight(AcDb::LineWeight::kLnWt050);<BR><BR>color.setColorIndex(4);<BR>pLayerTableRecord3-&gt;setColor(color);<BR>pLayerTableRecord3-&gt;setLineWeight(AcDb::LineWeight::kLnWt018);<BR><BR>color.setColorIndex(6);<BR>pLayerTableRecord4-&gt;setColor(color);<BR>pLayerTableRecord4-&gt;setLineWeight(AcDb::LineWeight::kLnWt018);<BR><BR>color.setColorIndex(3);<BR>pLayerTableRecord5-&gt;setColor(color);<BR>pLayerTableRecord5-&gt;setLineWeight(AcDb::LineWeight::kLnWt018);<BR><BR>color.setColorIndex(2);<BR>pLayerTableRecord6-&gt;setColor(color);<BR>pLayerTableRecord6-&gt;setLineWeight(AcDb::LineWeight::kLnWt018);<BR><BR>AcDbLinetypeTable *pLinetypeTbl; <BR>AcDbObjectId DashedLineId, CenterLineId,DivideLineId;<BR><BR>acdbCurDwg()-&gt;getLinetypeTable(pLinetypeTbl,AcDb::kForRead);<BR><BR>if ((pLinetypeTbl-&gt;getAt("DASHED",DashedLineId))!=Acad::eOk);<BR>{<BR>pLinetypeTbl-&gt;close();<BR>acdbCurDwg()-&gt;loadLineTypeFile("DASHED","acadiso.lin");<BR>acdbCurDwg()-&gt;getLinetypeTable(pLinetypeTbl,AcDb::kForRead);<BR>pLinetypeTbl-&gt;getAt("DASHED",DashedLineId);<BR>}<BR>if ((pLinetypeTbl-&gt;getAt("CENTER",CenterLineId))!=Acad::eOk);<BR>{<BR>pLinetypeTbl-&gt;close();<BR>acdbCurDwg()-&gt;loadLineTypeFile("CENTER","acadiso.lin");<BR>acdbCurDwg()-&gt;getLinetypeTable(pLinetypeTbl,AcDb::kForRead);<BR>pLinetypeTbl-&gt;getAt("CENTER",CenterLineId);<BR>}<BR>if ((pLinetypeTbl-&gt;getAt("DIVIDE",DivideLineId))!=Acad::eOk);<BR>{<BR>pLinetypeTbl-&gt;close();<BR>acdbCurDwg()-&gt;loadLineTypeFile("DIVIDE","acadiso.lin");<BR>acdbCurDwg()-&gt;getLinetypeTable(pLinetypeTbl,AcDb::kForRead);<BR>pLinetypeTbl-&gt;getAt("DIVIDE",DivideLineId);<BR>}<BR><BR>pLinetypeTbl-&gt;close();<BR>pLayerTableRecord1-&gt;setLinetypeObjectId(CenterLineId);<BR>pLayerTableRecord4-&gt;setLinetypeObjectId(DashedLineId);<BR>pLayerTableRecord5-&gt;setLinetypeObjectId(DivideLineId);<BR><BR>pLayerTable-&gt;add(pLayerTableRecord1);<BR>pLayerTable-&gt;add(pLayerTableRecord2);<BR>pLayerTable-&gt;add(pLayerTableRecord3);<BR>pLayerTable-&gt;add(pLayerTableRecord4);<BR>pLayerTable-&gt;add(pLayerTableRecord5);<BR>pLayerTable-&gt;add(pLayerTableRecord6);<BR><BR>pLayerTableRecord1-&gt;close();<BR>pLayerTableRecord2-&gt;close();<BR>pLayerTableRecord3-&gt;close();<BR>pLayerTableRecord4-&gt;close();<BR>pLayerTableRecord5-&gt;close();<BR>pLayerTableRecord6-&gt;close();<BR>pLayerTable-&gt;close();</FONT>

wzz1968 发表于 2006-6-2 08:14:00

<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>&nbsp;</P>

jingelou 发表于 2006-6-14 00:56:00

<P>累死了,可不可以这么写?</P>
<P>//添加层<BR>AcDbObjectId CLjDwg::AddLayer(const char* LayerName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const Adesk::Int16 LayerColor,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* Linetype,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbDatabase* pDb)<BR>{<BR>&nbsp;if(pDb==NULL)<BR>&nbsp;&nbsp;pDb=acdbCurDwg();<BR>&nbsp;//装载线型<BR>&nbsp;pDb-&gt;loadLineTypeFile(Linetype,LINETYPE_FILENAME);<BR>&nbsp;<BR>&nbsp;AcDbObjectId LineTypeId=AddLineType(pDb,Linetype);</P>
<P>&nbsp;AcDbLayerTable* pLayerTable=NULL;<BR>&nbsp;AcDbLayerTableRecord* pLayerRecord=NULL;<BR>&nbsp;AcDbObjectId LayerId=AcDbObjectId::kNull;<BR>&nbsp;pDb-&gt;getLayerTable(pLayerTable,AcDb::kForWrite);<BR>&nbsp;if(!pLayerTable)<BR>&nbsp;&nbsp;return FALSE;<BR>&nbsp;if(pLayerTable-&gt;has(LayerName))<BR>&nbsp;{<BR>&nbsp;&nbsp;pLayerTable-&gt;getAt(LayerName,LayerId);<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;pLayerRecord=new AcDbLayerTableRecord;<BR>&nbsp;&nbsp;AcCmColor color;<BR>&nbsp;&nbsp;color.setColorIndex(LayerColor);<BR>&nbsp;&nbsp;pLayerRecord-&gt;setColor(color);<BR>&nbsp;&nbsp;pLayerRecord-&gt;setLinetypeObjectId(LineTypeId);<BR>&nbsp;&nbsp;pLayerRecord-&gt;setName(LayerName);&nbsp;<BR>&nbsp;&nbsp;pLayerTable-&gt;add(LayerId,pLayerRecord);<BR>&nbsp;&nbsp;pLayerRecord-&gt;close();<BR>&nbsp;}<BR>&nbsp;pLayerTable-&gt;close();<BR>&nbsp;return LayerId;<BR>}</P>
<P>&nbsp;</P>

hbdzyy 发表于 2006-11-23 16:02:00

<P>太好了,刚好在学这里,真是太感谢了!!</P>

beyond2005 发表于 2007-3-8 14:48:00

<p>相当谢谢</p><p></p>

c735023723 发表于 2012-8-4 13:59:51

很好,正需要这个呢
页: [1]
查看完整版本: [原创][ARX]生成图层和设置线型(类型、颜色、线宽)