<?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 layer programmatically in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469954#M83485</link>
    <description>Thanks weslleywang, it worked. My command ended like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
    ' Define command 'addlayer'&lt;BR /&gt;
    &amp;lt; CommandMethod("addlayer") &amp;gt; _&lt;BR /&gt;
    Public Function AddLayer()&lt;BR /&gt;
        Dim curdb As Database&lt;BR /&gt;
        Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager&lt;BR /&gt;
        Dim myT As Transaction&lt;BR /&gt;
        curdb = Application.DocumentManager.MdiActiveDocument.Database&lt;BR /&gt;
        tm = curdb.TransactionManager&lt;BR /&gt;
        myT = tm.StartTransaction()&lt;BR /&gt;
        Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable)&lt;BR /&gt;
        Dim x As New LayerTableRecord&lt;BR /&gt;
        x.Name = "Test Layer"&lt;BR /&gt;
        x.IsOff = True&lt;BR /&gt;
        x.IsFrozen = True&lt;BR /&gt;
        x.IsLocked = True&lt;BR /&gt;
        'Color RED&lt;BR /&gt;
        x.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0)&lt;BR /&gt;
        x.LineWeight = LineWeight.LineWeight120&lt;BR /&gt;
        x.IsPlottable = False&lt;BR /&gt;
        x.Description = "Layer insert sucessfully"&lt;BR /&gt;
        lt.Add(x)&lt;BR /&gt;
        myT.AddNewlyCreatedDBObject(x, True)&lt;BR /&gt;
        myT.Commit()&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;/CODE&gt;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Filipe Marcelino

null</description>
    <pubDate>Thu, 27 Oct 2005 09:28:43 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2005-10-27T09:28:43Z</dc:date>
    <item>
      <title>Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469950#M83481</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
i'm trying to create a layer programmatically with the following code:&lt;BR /&gt;
&lt;BR /&gt;
&amp;lt; CommandMethod("addlayer") &amp;gt; _&lt;BR /&gt;
  Public Function AddLayer()&lt;BR /&gt;
        Dim curdb As Database&lt;BR /&gt;
        Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager&lt;BR /&gt;
        Dim myT As Transaction&lt;BR /&gt;
&lt;BR /&gt;
            curdb = Application.DocumentManager.MdiActiveDocument.Database&lt;BR /&gt;
            tm = curdb.TransactionManager&lt;BR /&gt;
            myT = tm.StartTransaction()&lt;BR /&gt;
&lt;BR /&gt;
            Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable)&lt;BR /&gt;
            Dim x As New LayerTableRecord&lt;BR /&gt;
            x.Name = "Test1"&lt;BR /&gt;
&lt;BR /&gt;
            x.IsOff = chkON.Checked 'Checkbox&lt;BR /&gt;
            x.IsFrozen = chkFrozen.Checked 'Checkbox&lt;BR /&gt;
            x.IsLocked = chkLocked.Checked 'Checkbox&lt;BR /&gt;
&lt;BR /&gt;
            'Color RED&lt;BR /&gt;
            x.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0)&lt;BR /&gt;
&lt;BR /&gt;
            'Lineweight&lt;BR /&gt;
            x.LineWeight = LineWeight.LineWeight120&lt;BR /&gt;
&lt;BR /&gt;
            x.IsPlottable = chkPlottable.Checked 'Checkbox&lt;BR /&gt;
&lt;BR /&gt;
            x.Description = "Layer test1"&lt;BR /&gt;
            lt.Add(x)&lt;BR /&gt;
&lt;BR /&gt;
            myT.Commit()&lt;BR /&gt;
&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
This code actually inserts the layer, but first, the property 'DESCRIPTION' appears empty. Second, after I run this code the layer is inserted but, if I access the layer manager just to check if the layer were actually inserted and then click cancel, the insert layer gets removed!! I don't understand why. Maybe because the document database isn't updated automatically...I don't know.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your attention, I hope you can help me.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Filipe Marcelino</description>
      <pubDate>Wed, 26 Oct 2005 16:40:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469950#M83481</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-10-26T16:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469951#M83482</link>
      <description>add myT.AddNewlyCreatedDBObject before Commit.</description>
      <pubDate>Wed, 26 Oct 2005 17:09:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469951#M83482</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2005-10-26T17:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469952#M83483</link>
      <description>like this?&lt;BR /&gt;
&lt;BR /&gt;
finally&lt;BR /&gt;
    myT.AddNewlyCreatedDBObject(x, True) 'LayerTableRecord&lt;BR /&gt;
    myT.Commit()&lt;BR /&gt;
end try&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
&lt;BR /&gt;
finally&lt;BR /&gt;
    myT.AddNewlyCreatedDBObject(lt, True) 'LayerTable&lt;BR /&gt;
    myT.Commit()&lt;BR /&gt;
end try&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Filipe Marcelino</description>
      <pubDate>Wed, 26 Oct 2005 17:29:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469952#M83483</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-10-26T17:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469953#M83484</link>
      <description>myT.AddNewlyCreatedDBObject(x, True) 'LayerTableRecord</description>
      <pubDate>Wed, 26 Oct 2005 20:09:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469953#M83484</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2005-10-26T20:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469954#M83485</link>
      <description>Thanks weslleywang, it worked. My command ended like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
    ' Define command 'addlayer'&lt;BR /&gt;
    &amp;lt; CommandMethod("addlayer") &amp;gt; _&lt;BR /&gt;
    Public Function AddLayer()&lt;BR /&gt;
        Dim curdb As Database&lt;BR /&gt;
        Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager&lt;BR /&gt;
        Dim myT As Transaction&lt;BR /&gt;
        curdb = Application.DocumentManager.MdiActiveDocument.Database&lt;BR /&gt;
        tm = curdb.TransactionManager&lt;BR /&gt;
        myT = tm.StartTransaction()&lt;BR /&gt;
        Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable)&lt;BR /&gt;
        Dim x As New LayerTableRecord&lt;BR /&gt;
        x.Name = "Test Layer"&lt;BR /&gt;
        x.IsOff = True&lt;BR /&gt;
        x.IsFrozen = True&lt;BR /&gt;
        x.IsLocked = True&lt;BR /&gt;
        'Color RED&lt;BR /&gt;
        x.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0)&lt;BR /&gt;
        x.LineWeight = LineWeight.LineWeight120&lt;BR /&gt;
        x.IsPlottable = False&lt;BR /&gt;
        x.Description = "Layer insert sucessfully"&lt;BR /&gt;
        lt.Add(x)&lt;BR /&gt;
        myT.AddNewlyCreatedDBObject(x, True)&lt;BR /&gt;
        myT.Commit()&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;/CODE&gt;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Filipe Marcelino

null</description>
      <pubDate>Thu, 27 Oct 2005 09:28:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469954#M83485</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-10-27T09:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469955#M83486</link>
      <description>First, I think your "Function" should be "Shared Sub".&lt;BR /&gt;
Second, you probably should wrap your transaction in an error handler.&lt;BR /&gt;
Third, you should only "Commit" the transaction if there were no errors, otherwise, you should "Abort" the transaction.&lt;BR /&gt;
&lt;BR /&gt;
Attached is your code with error handling.</description>
      <pubDate>Fri, 28 Oct 2005 20:40:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469955#M83486</guid>
      <dc:creator>cgay</dc:creator>
      <dc:date>2005-10-28T20:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469956#M83487</link>
      <description>Hi.&lt;BR /&gt;
This code is great, but could somebody please show me how to add a linetype to this layer!!! &lt;BR /&gt;
I am using vb.net 2003 and autocad 2006.&lt;BR /&gt;
&lt;BR /&gt;
yours in anticipation&lt;BR /&gt;
Dave</description>
      <pubDate>Tue, 09 May 2006 11:51:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469956#M83487</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-09T11:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469957#M83488</link>
      <description>First search the curdb.LinetypeTableId.&lt;BR /&gt;
Search for the linetype you want in Linetypetable and fetch the LinetypeID in the variable MyLinetypeObjectID&lt;BR /&gt;
&lt;BR /&gt;
Finally add code in the part with x ...:&lt;BR /&gt;
                    .LinetypeObjectId = MyLinetypeObjectID</description>
      <pubDate>Wed, 10 May 2006 15:53:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469957#M83488</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-10T15:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469958#M83489</link>
      <description>I hope this can help.....&lt;BR /&gt;
Auto Layer Loading, just replace FUNCTIONNAME  to your desire descipline like "Archi, Civil or Struct.&lt;BR /&gt;
&lt;BR /&gt;
;;;=== Make Layer =================================&lt;BR /&gt;
(DEFUN C:FUNTIONNAME ()&lt;BR /&gt;
 (COMMAND "LAYER" "MakeLayer" " "LeyerName" "Color" "Red" "" "LineType" "center" ""&lt;BR /&gt;
"SET" "0" "")&lt;BR /&gt;
 (PRINC)&lt;BR /&gt;
 (PROMPT "\nFuntionName LAYERS LOADED......")&lt;BR /&gt;
 (PRINC)&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
**************************************************************&lt;BR /&gt;
HERE ARE THE SAMPLE&lt;BR /&gt;
&lt;BR /&gt;
(DEFUN C:ARCHI ()&lt;BR /&gt;
 (COMMAND "LAYER"&lt;BR /&gt;
"M" " "Wall" "C" "Green" "" "LT" "Continuous" ""&lt;BR /&gt;
"M" " "Window" "C" "11" "" "LT" "Hidden" ""&lt;BR /&gt;
"SET" "0" "")&lt;BR /&gt;
 (PRINC)&lt;BR /&gt;
 (PROMPT "\nARCHITECTURAL LAYERS LOADED......")&lt;BR /&gt;
 (PRINC)&lt;BR /&gt;
)</description>
      <pubDate>Thu, 11 May 2006 05:52:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469958#M83489</guid>
      <dc:creator>parcea89</dc:creator>
      <dc:date>2006-05-11T05:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469959#M83490</link>
      <description>Thanks Manfred&lt;BR /&gt;
I had the x.LinetypeObjectId = MyLinetypeObjectID part but i am strugeling with the search of the linetype table I have:-&lt;BR /&gt;
Dim MyLinetypeObjectID as LinetypeId = curdb.LinetypeTableId. &lt;BR /&gt;
but can't see the way forward.&lt;BR /&gt;
All help much appreciated.&lt;BR /&gt;
Regards&lt;BR /&gt;
Dave</description>
      <pubDate>Fri, 12 May 2006 07:00:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469959#M83490</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-12T07:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469960#M83491</link>
      <description>Thanks 'parcea'&lt;BR /&gt;
I have a lisp version already but here is something you could add to yours to place a description in your layer definition.&lt;BR /&gt;
;;;*Syntax (ldescription name desc)&lt;BR /&gt;
(DEFUN ldescription(LAYERNAME LAYERDESC)&lt;BR /&gt;
(setq myLayer (vla-Add (vla-Get-Layers (vla-Get-ActiveDocument&lt;BR /&gt;
(vlax-Get-Acad-Object))) LAYERNAME))&lt;BR /&gt;
(vla-Put-Description myLayer LAYERDESC)&lt;BR /&gt;
)&lt;BR /&gt;
Regards&lt;BR /&gt;
Dave</description>
      <pubDate>Fri, 12 May 2006 07:07:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469960#M83491</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-12T07:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create layer programmatically</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469961#M83492</link>
      <description>Filipe can you tell me what refernce need to be checked to use the autodesk.autocad.databseservices ? thanks</description>
      <pubDate>Tue, 12 Dec 2006 23:05:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-layer-programmatically/m-p/1469961#M83492</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-12-12T23:05:58Z</dc:date>
    </item>
  </channel>
</rss>

