<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: change layer.color and layer.line weight by int and double in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647699#M18960</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; i has try&amp;nbsp;&lt;/P&gt;&lt;P&gt;Objectid idx; (but while compile allert idx unlocal variable) how to fix&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jul 2020 19:58:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-07-21T19:58:05Z</dc:date>
    <item>
      <title>change layer.color and layer.line weight by int and double</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647419#M18958</link>
      <description>&lt;P&gt;i am make function in net autocad using C#&lt;/P&gt;&lt;P&gt;i want change layer.color by int and change layer.lineweight by double&lt;/P&gt;&lt;P&gt;how to do this&lt;/P&gt;&lt;LI-CODE lang="general"&gt; public static ObjectId addlayer(string namalayer,double lineweight,int color)

        {
            var doc = app.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            ObjectId idx = db.LayerTableId;
            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(db.LayerTableId,OpenMode.ForRead) as LayerTable;  
                if (acLyrTbl.Has(namalayer) == false)
                {
                    LayerTableRecord acLyrTblRec = new LayerTableRecord();
                    acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByColor, color);
                    acLyrTblRec.LineWeight = lineweight;


                    acLyrTblRec.Name = namalayer;
                    acLyrTbl.UpgradeOpen();
                    idx= acLyrTbl.Add(acLyrTblRec);acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);   
                    db.Clayer = idx;
                }
                else
                {
                    db.Clayer = acLyrTbl[namalayer];
                }              
                acTrans.Commit();
                return idx;
            }

        }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 21 Jul 2020 18:06:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647419#M18958</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-07-21T18:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: change layer.color and layer.line weight by int and double</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647526#M18959</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About color, to pass an integer as color index, you have to use the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_Colors_ColorMethod" target="_blank" rel="noopener"&gt;ColorMethod.ByAci&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;About line weight, you have to use a member of the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_LineWeight" target="_blank" rel="noopener"&gt;LineWeight enumeration&lt;/A&gt; or its corresponding integer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public static ObjectId AddLayer(string name, double lineweight, int color)
{
    var doc = app.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    ObjectId idx;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        var layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
        if (layerTable.Has(name))
        {
            idx = layerTable[name];
        }
        else
        {
            var layer = new LayerTableRecord();
            layer.Color = Color.FromColorIndex(ColorMethod.ByAci, (short)color);
            try { layer.LineWeight = (LineWeight)(int)(lineweight * 100); }
            catch { layer.LineWeight = LineWeight.ByLayer; }
            layer.Name = name;
            layerTable.UpgradeOpen();
            idx = layerTable.Add(layer); 
            tr.AddNewlyCreatedDBObject(layer, true);
        }
            db.Clayer = idx;
        tr.Commit();
        return idx;
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 18:50:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647526#M18959</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-07-21T18:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: change layer.color and layer.line weight by int and double</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647699#M18960</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; i has try&amp;nbsp;&lt;/P&gt;&lt;P&gt;Objectid idx; (but while compile allert idx unlocal variable) how to fix&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 19:58:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647699#M18960</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-07-21T19:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: change layer.color and layer.line weight by int and double</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647720#M18961</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; i has try&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Objectid idx; (but while compile allert idx unlocal variable) how to fix&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sorry but I do not understand what you mean. The code I posted works as expected here.&lt;/P&gt;
&lt;P&gt;Either you copy the whole code or you only adapt the Color and LineWeight expressions to your code.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 20:08:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9647720#M18961</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-07-21T20:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: change layer.color and layer.line weight by int and double</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9648787#M18962</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; thankyou work like charm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 11:07:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-layer-color-and-layer-line-weight-by-int-and-double/m-p/9648787#M18962</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-07-22T11:07:27Z</dc:date>
    </item>
  </channel>
</rss>

