<?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: Create a layer and set as current using VB.NET in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190256#M75410</link>
    <description>rene,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the code and your help. It really helped me a lot.</description>
    <pubDate>Thu, 28 Feb 2008 12:45:57 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-02-28T12:45:57Z</dc:date>
    <item>
      <title>Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190248#M75402</link>
      <description>Can anyone advice me  a solution for the following scenario:&lt;BR /&gt;
&lt;BR /&gt;
User enters a layer name in a textbox. I need to pass this layer name to my command method, create a layer and set the layer as current programmatically.&lt;BR /&gt;
&lt;BR /&gt;
Here is the snippet of source code in VB.NET:&lt;BR /&gt;
&lt;BR /&gt;
 Dim myLayerTable As DatabaseServices.LayerTable&lt;BR /&gt;
 Dim myLayer As New DatabaseServices.LayerTableRecord&lt;BR /&gt;
&lt;BR /&gt;
myLayerTable = myDB.LayerTableId.GetObject(DatabaseServices.OpenMode.ForWrite)&lt;BR /&gt;
------------------------------------------------------&lt;BR /&gt;
myLayer.Name = "Test Layer"  &lt;BR /&gt;
---------------------------------------------------------&lt;BR /&gt;
myLayerTable.Add(myLayer)&lt;BR /&gt;
&lt;BR /&gt;
I need to set myLayer.Name to whatever user enters in the textbox .  I also need to set the newly created layer as current layer&lt;BR /&gt;
&lt;BR /&gt;
I know how to do it in object oriented programming. But looks like I ran out of ideas here.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your advice.</description>
      <pubDate>Wed, 27 Feb 2008 03:38:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190248#M75402</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T03:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190249#M75403</link>
      <description>This may be what you're looking for:&lt;BR /&gt;
To set the current layer, set the Clayer property of the database to the &lt;BR /&gt;
ObjectId of a LayerTableRecord.&lt;BR /&gt;
&lt;BR /&gt;
Greetings.&lt;BR /&gt;
&lt;BR /&gt;
&lt;USCH555&gt; wrote in message news:5859412@discussion.autodesk.com...&lt;BR /&gt;
Can anyone advice me  a solution for the following scenario:&lt;BR /&gt;
&lt;BR /&gt;
User enters a layer name in a textbox. I need to pass this layer name to my &lt;BR /&gt;
command method, create a layer and set the layer as current &lt;BR /&gt;
programmatically.&lt;BR /&gt;
&lt;BR /&gt;
Here is the snippet of source code in VB.NET:&lt;BR /&gt;
&lt;BR /&gt;
 Dim myLayerTable As DatabaseServices.LayerTable&lt;BR /&gt;
 Dim myLayer As New DatabaseServices.LayerTableRecord&lt;BR /&gt;
&lt;BR /&gt;
myLayerTable = &lt;BR /&gt;
myDB.LayerTableId.GetObject(DatabaseServices.OpenMode.ForWrite)&lt;BR /&gt;
------------------------------------------------------&lt;BR /&gt;
myLayer.Name = "Test Layer"&lt;BR /&gt;
---------------------------------------------------------&lt;BR /&gt;
myLayerTable.Add(myLayer)&lt;BR /&gt;
&lt;BR /&gt;
I need to set myLayer.Name to whatever user enters in the textbox .  I also &lt;BR /&gt;
need to set the newly created layer as current layer&lt;BR /&gt;
&lt;BR /&gt;
I know how to do it in object oriented programming. But looks like I ran out &lt;BR /&gt;
of ideas here.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your advice.&lt;/USCH555&gt;</description>
      <pubDate>Wed, 27 Feb 2008 06:35:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190249#M75403</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T06:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190250#M75404</link>
      <description>Sub SetMyLayerCurrent()&lt;BR /&gt;
        Dim myDWG As ApplicationServices.Document&lt;BR /&gt;
        Dim myDB As DatabaseServices.Database&lt;BR /&gt;
        Dim myTransMan As DatabaseServices.TransactionManager&lt;BR /&gt;
        Dim myTrans As DatabaseServices.Transaction&lt;BR /&gt;
&lt;BR /&gt;
        myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        myDB = myDWG.Database&lt;BR /&gt;
        myTransMan = myDWG.TransactionManager&lt;BR /&gt;
        myTrans = myTransMan.StartTransaction&lt;BR /&gt;
&lt;BR /&gt;
        Dim myLT As DatabaseServices.LayerTable&lt;BR /&gt;
        Dim myLayer As New DatabaseServices.LayerTableRecord&lt;BR /&gt;
        Dim myLayerId As ObjectId&lt;BR /&gt;
&lt;BR /&gt;
	Dim LayerName As String = "Test Layer"&lt;BR /&gt;
&lt;BR /&gt;
        ' Verifica se il Layer Esiste&lt;BR /&gt;
        Try&lt;BR /&gt;
            ' If Layer Exist recover LayerID&lt;BR /&gt;
            myLT = CType(myTransMan.GetObject(myDB.LayerTableId, OpenMode.ForRead, True, True), LayerTable)&lt;BR /&gt;
            myLayerId = myLT.Item(LayerName)&lt;BR /&gt;
            ' If Deleted =&amp;gt; Recover Layer&lt;BR /&gt;
            If myLayerId.IsErased Then&lt;BR /&gt;
                myLT.UpgradeOpen()&lt;BR /&gt;
                myLT.Item(LayerName).GetObject(OpenMode.ForWrite, True, True).Erase(False)&lt;BR /&gt;
            End If&lt;BR /&gt;
&lt;BR /&gt;
        Catch ex As Exception&lt;BR /&gt;
            ' Layer Doesn't Exist: Create it&lt;BR /&gt;
            myLT = myDB.LayerTableId.GetObject(DatabaseServices.OpenMode.ForWrite, True, True)&lt;BR /&gt;
            myLayer.Name = LayerName&lt;BR /&gt;
            myLT.Add(myLayer)&lt;BR /&gt;
            ' Add Layer to DB&lt;BR /&gt;
            myTrans.AddNewlyCreatedDBObject(myLayer, True)&lt;BR /&gt;
            ' Recover LayerID of newly created Layer&lt;BR /&gt;
            myLT = CType(myTransMan.GetObject(myDB.LayerTableId, OpenMode.ForRead, False), LayerTable)&lt;BR /&gt;
            myLayerId = myLT.Item(LayerName)&lt;BR /&gt;
        End Try&lt;BR /&gt;
&lt;BR /&gt;
        ' Set Layer as Current&lt;BR /&gt;
        myDB.Clayer = myLayerId&lt;BR /&gt;
&lt;BR /&gt;
        myTrans.Commit()&lt;BR /&gt;
        myTrans.Dispose()&lt;BR /&gt;
        myTransMan.Dispose()&lt;BR /&gt;
    End Sub       ' Set as Current Layer</description>
      <pubDate>Wed, 27 Feb 2008 11:04:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190250#M75404</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T11:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190251#M75405</link>
      <description>Thanks for the code. I appreciate it very much. &lt;BR /&gt;
&lt;BR /&gt;
I need to set the LayerName to whatever user enters in the textbox. &lt;BR /&gt;
&lt;BR /&gt;
Dim LayerName As String = "Test Layer"  'Textbox1.Text&lt;BR /&gt;
&lt;BR /&gt;
Could you please tell me how to pass the text parameter as LayerName to my command method.&lt;BR /&gt;
&lt;BR /&gt;
Thanks once again.</description>
      <pubDate>Wed, 27 Feb 2008 14:22:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190251#M75405</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T14:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190252#M75406</link>
      <description>Could you please let me know which assembly you are referring to for ObjectID in the following line of code:&lt;BR /&gt;
&lt;BR /&gt;
Dim myLayerId As ObjectId&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Wed, 27 Feb 2008 14:43:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190252#M75406</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T14:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190253#M75407</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
ObjectID (just like LayerTable and LayerTableRecord) can be found in the namespace: Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Assembly: acdbmgd.Dll&lt;BR /&gt;
&lt;BR /&gt;
(Look for it in the Object Browser in VS)&lt;BR /&gt;
&lt;BR /&gt;
As reply to you're other post: Call a Form (with the textbox on it) in you're commandMethod, and retrieve the value when the form is closed. (you can expose a public property in the form Class like: LayerName, and retrieve it after the form was closed, do check if the form was cancelled)&lt;BR /&gt;
&lt;BR /&gt;
A. Caddie</description>
      <pubDate>Wed, 27 Feb 2008 18:02:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190253#M75407</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T18:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190254#M75408</link>
      <description>thanks for your help.</description>
      <pubDate>Wed, 27 Feb 2008 20:19:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190254#M75408</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-27T20:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190255#M75409</link>
      <description>Here's part of my module&lt;BR /&gt;
&lt;BR /&gt;
the namespace for the myLayerId is:&lt;BR /&gt;
&lt;BR /&gt;
"Autodesk.AutoCAD.DatabaseServices.ObjectId"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
&lt;BR /&gt;
    Sub SetMyLayer(ByVal LayerName As String, _&lt;BR /&gt;
                          Optional ByVal LayOff As Boolean = False, _&lt;BR /&gt;
                          Optional ByVal LayFrozen As Boolean = False, _&lt;BR /&gt;
                          Optional ByVal LayLocked As Boolean = False, _&lt;BR /&gt;
                          Optional ByVal ColorByACI As Integer = 7, _&lt;BR /&gt;
                          Optional ByVal LayLType As String = "Continuous", _&lt;BR /&gt;
                          Optional ByVal LayLWeight As DatabaseServices.LineWeight = _&lt;BR /&gt;
                                         DatabaseServices.LineWeight.ByLineWeightDefault, _&lt;BR /&gt;
                          Optional ByVal LayIsPlottable As Boolean = True, _&lt;BR /&gt;
                          Optional ByVal LayDescription As String = "", _&lt;BR /&gt;
                          Optional ByVal SetCurrent As Boolean = True)&lt;BR /&gt;
        Dim myDWG As ApplicationServices.Document&lt;BR /&gt;
        Dim myDB As DatabaseServices.Database&lt;BR /&gt;
        Dim myTransMan As DatabaseServices.TransactionManager&lt;BR /&gt;
        Dim myTrans As DatabaseServices.Transaction&lt;BR /&gt;
&lt;BR /&gt;
        myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        myDB = myDWG.Database&lt;BR /&gt;
        myTransMan = myDWG.TransactionManager&lt;BR /&gt;
        myTrans = myTransMan.StartTransaction&lt;BR /&gt;
&lt;BR /&gt;
        Dim myLT As DatabaseServices.LayerTable&lt;BR /&gt;
        Dim myLayer As New DatabaseServices.LayerTableRecord&lt;BR /&gt;
        Dim myLayerId As ObjectId&lt;BR /&gt;
&lt;BR /&gt;
        ' Verifica se il Layer Esiste&lt;BR /&gt;
        Try&lt;BR /&gt;
            ' Se il Layer Esiste =&amp;gt; Recupera il suo ID&lt;BR /&gt;
            myLT = CType(myTransMan.GetObject(myDB.LayerTableId, OpenMode.ForRead, True, True), LayerTable)&lt;BR /&gt;
            myLayerId = myLT.Item(LayerName)&lt;BR /&gt;
            ' Se è stato cancellato =&amp;gt; Recupera il Layer&lt;BR /&gt;
            If myLayerId.IsErased Then&lt;BR /&gt;
                myLT.UpgradeOpen()&lt;BR /&gt;
                myLT.Item(LayerName).GetObject(OpenMode.ForWrite, True, True).Erase(False)&lt;BR /&gt;
            End If&lt;BR /&gt;
&lt;BR /&gt;
        Catch ex As Exception&lt;BR /&gt;
            ' Il Layer NON Esiste: Bisogna crearlo con tutte le sue caratteristiche&lt;BR /&gt;
            myLT = myDB.LayerTableId.GetObject(DatabaseServices.OpenMode.ForWrite, True, True)&lt;BR /&gt;
            myLayer.Name = LayerName&lt;BR /&gt;
            myLT.Add(myLayer)&lt;BR /&gt;
            'Aggiungere il Layer al Database del Disegno&lt;BR /&gt;
            myTrans.AddNewlyCreatedDBObject(myLayer, True)&lt;BR /&gt;
            ' Recupera l'ID del Layer appena creato&lt;BR /&gt;
            myLT = CType(myTransMan.GetObject(myDB.LayerTableId, OpenMode.ForRead, False), LayerTable)&lt;BR /&gt;
            myLayerId = myLT.Item(LayerName)&lt;BR /&gt;
        End Try&lt;BR /&gt;
&lt;BR /&gt;
        ' Impostazioni del Layer&lt;BR /&gt;
        Try&lt;BR /&gt;
            myLayer = myTransMan.GetObject(myLayerId, OpenMode.ForWrite, True, True)&lt;BR /&gt;
        Catch ex As Exception&lt;BR /&gt;
        End Try&lt;BR /&gt;
        myLayer.Color = Colors.Color.FromColorIndex(Colors.ColorMethod.ByAci, ColorByACI)&lt;BR /&gt;
        myLayer.LineWeight = LayLWeight&lt;BR /&gt;
        myLayer.IsOff = LayOff&lt;BR /&gt;
        myLayer.IsFrozen = LayFrozen&lt;BR /&gt;
        myLayer.IsLocked = LayLocked&lt;BR /&gt;
        myLayer.IsPlottable = LayIsPlottable&lt;BR /&gt;
        myLayer.LinetypeObjectId = GetLineTypeId(LayLType)&lt;BR /&gt;
        myLayer.Description = LayDescription&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
        ' Verifica se deve essere impostato come Layer Corrente&lt;BR /&gt;
        If SetCurrent Then myDB.Clayer = myLayerId&lt;BR /&gt;
        myTrans.Commit()&lt;BR /&gt;
        myTrans.Dispose()&lt;BR /&gt;
        myTransMan.Dispose()&lt;BR /&gt;
    End Sub              ' Reset Layer&lt;BR /&gt;
&lt;BR /&gt;
Hope it helps&lt;BR /&gt;
René</description>
      <pubDate>Thu, 28 Feb 2008 09:53:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190255#M75409</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-28T09:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create a layer and set as current using VB.NET</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190256#M75410</link>
      <description>rene,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the code and your help. It really helped me a lot.</description>
      <pubDate>Thu, 28 Feb 2008 12:45:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-layer-and-set-as-current-using-vb-net/m-p/2190256#M75410</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-02-28T12:45:57Z</dc:date>
    </item>
  </channel>
</rss>

