<?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: make existing layer as active layer in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360599#M16322</link>
    <description>&lt;P&gt;Thanks.&amp;nbsp; I see you are completely right to add to the table.&lt;/P&gt;&lt;P&gt;I modified this line&lt;/P&gt;&lt;P&gt;Dim layer = New LayerTableRecord With {.Name = LayerName, .LineWeight = LineWeight.ByLayer, .IsLocked = False, .Description = LayerDescription, .IsPlottable = IsItPlottable, .IsFrozen = False}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help&lt;/P&gt;</description>
    <pubDate>Thu, 03 Jun 2021 09:47:28 GMT</pubDate>
    <dc:creator>jaboone</dc:creator>
    <dc:date>2021-06-03T09:47:28Z</dc:date>
    <item>
      <title>make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10349203#M16317</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;there is some thing wrong with this code, I cant figure it&amp;nbsp;&lt;BR /&gt;when layer exist , it dosen't make it as active layer&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void Layercreate(string Layer_Name)
{
using (var dbs = HostApplicationServices.WorkingDatabase)
using (var Trans = dbs.TransactionManager.StartTransaction())
{
try
{
LayerTable Layer_Table = (LayerTable)Trans.GetObject(dbs.LayerTableId, OpenMode.ForRead);
LayerTableRecord layer_chk;
foreach (ObjectId layer_chk_id in Layer_Table)
{
layer_chk = Trans.GetObject(layer_chk_id, OpenMode.ForRead) as LayerTableRecord;
if (Layer_Table.Has(Layer_Name))// check if layer exist
{
string Active_Layer = Convert.ToString(dbs.Clayer);
if (Active_Layer != Layer_Name)//check if requsted layer is the current layer
{
dbs.Clayer = Layer_Table[Layer_Name];//make existing layer as current
break;
}
else
{
Trans.Commit();
break;
}
}
else
{	//create layer if it is not exist
ObjectId Layer_Object_ID = dbs.LayerTableId;
Layer_Table = Trans.GetObject(Layer_Object_ID, OpenMode.ForWrite) as LayerTable;
LayerTableRecord Layer_Tablerec = new LayerTableRecord
{
Name = Layer_Name
};
Layer_Table.Add(Layer_Tablerec);
Trans.AddNewlyCreatedDBObject(Layer_Tablerec, true);
Application.SetSystemVariable("clayer", Layer_Name);//make it current, is there better way to do this ??
Trans.Commit();
break;
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception _Exeption)
{
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
editor.WriteMessage("\n" + Convert.ToString(_Exeption));
}
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 03:24:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10349203#M16317</guid>
      <dc:creator>almutaz_86</dc:creator>
      <dc:date>2021-05-29T03:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10349305#M16318</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Try to make the things as simple as possible. You shoud not get the working database in a using statement, you do not really need to check which is the current layer (anyway, Convert.ToString(dbs.Clayer) always return false because dbs.Clayer is an ObjectId) and overall you do not need to iterate through the layer table and do all the stuff for each layer (even committing the transaction).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private void CreateLayer(string layerName)
{
    var db = HostApplicationServices.WorkingDatabase;
    using (var tr = db.TransactionManager.StartTransaction())
    {
        var layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
        // if the layer table does not already contain the layer, create it
        if (!layerTable.Has(layerName))
        {
            tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
            var layer = new LayerTableRecord { Name = layerName };
            layerTable.Add(layer);
            tr.AddNewlyCreatedDBObject(layer, true);
        }
        // make layerName current
        db.Clayer = layerTable[layerName];
        tr.Commit();
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 05:32:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10349305#M16318</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-05-29T05:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10350003#M16319</link>
      <description>&lt;P&gt;I appreciate you very much&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;and thank you&amp;nbsp;&lt;BR /&gt;I'm really struggling to keep codes simple, but I dont have enough experience in .net&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you may please to recommend a toturial for AutoCAD .net api&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;Thanks again&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 15:43:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10350003#M16319</guid>
      <dc:creator>almutaz_86</dc:creator>
      <dc:date>2021-05-29T15:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360510#M16320</link>
      <description>&lt;P&gt;How would you apply all the other things to this function so that it modifies the color, lock, transparency, noplot, on/off, description and linestyle?&amp;nbsp; Did I miss anything?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 09:07:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360510#M16320</guid>
      <dc:creator>jaboone</dc:creator>
      <dc:date>2021-06-03T09:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360518#M16321</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/941286"&gt;@jaboone&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;How would you apply all the other things to this function so that it modifies the color, lock, transparency, noplot, on/off, description and linestyle?&amp;nbsp; Did I miss anything?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Simply set the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-__MEMBERTYPE_Properties_Autodesk_AutoCAD_DatabaseServices_LayerTableRecord" target="_blank" rel="noopener"&gt;properties&lt;/A&gt;&amp;nbsp; of the LayerTableRecord instance.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 09:13:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360518#M16321</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-06-03T09:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360599#M16322</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; I see you are completely right to add to the table.&lt;/P&gt;&lt;P&gt;I modified this line&lt;/P&gt;&lt;P&gt;Dim layer = New LayerTableRecord With {.Name = LayerName, .LineWeight = LineWeight.ByLayer, .IsLocked = False, .Description = LayerDescription, .IsPlottable = IsItPlottable, .IsFrozen = False}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 09:47:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360599#M16322</guid>
      <dc:creator>jaboone</dc:creator>
      <dc:date>2021-06-03T09:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: make existing layer as active layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360607#M16323</link>
      <description>&lt;P&gt;One problem I see with this layer table is that I can't set the layer created to a current layer with adding a new command line to do it.&amp;nbsp; Can you talk to your API group to add a .SetCurrent = True to make it a all for one, then I could use a create layer each time I want to set a layer?&amp;nbsp; Or maybe there is a better method?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 09:53:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/make-existing-layer-as-active-layer/m-p/10360607#M16323</guid>
      <dc:creator>jaboone</dc:creator>
      <dc:date>2021-06-03T09:53:07Z</dc:date>
    </item>
  </channel>
</rss>

