.NET

Reply
Active Contributor
tony.tomison.iii
Posts: 26
Registered: ‎05-12-2014
Message 1 of 3 (128 Views)
Accepted Solution

Creating layer is not being created

128 Views, 2 Replies
07-28-2014 01:37 PM

Hello,

 

This code will sometimes create the layer and other times not do it, why?

 

Sub CreateLayer() 
'' Get the current document and database
                Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
                Dim acCurDb As Database = acDoc.Database

                '' Start a transaction
                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                    '' Open the Layer table for read
                    Dim acLyrTbl As LayerTable
                    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite)

                    Dim sLayerName As String = "MyLayer"

                    If acLyrTbl.Has(sLayerName) = False Then
                        Dim acLyrTblRec As LayerTableRecord = New LayerTableRecord()

                        '' Assign the layer the ACI color 1 and a name
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 4)
                        acLyrTblRec.Name = sLayerName

                        '' Upgrade the Layer table for write
                        'acLyrTbl.UpgradeOpen()

                        '' Append the new layer to the Layer table and the transaction
                        acLyrTbl.Add(acLyrTblRec)
                        'acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
                        acTrans.Commit()
                    Else
                        acTrans.Dispose()
                    End If
End Sub

 

Ditch the dispose.

'End Using' block of code for the transaction

 

Have a look here:

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-7BF88244-D866-40D1-8C21-7DD1A2C633DF

Valued Mentor
KerryBrown
Posts: 269
Registered: ‎11-29-2008
Message 2 of 3 (121 Views)

Re: Creating layer is not being created

07-28-2014 02:20 PM in reply to: tony.tomison.iii

Ditch the dispose.

'End Using' block of code for the transaction

 

Have a look here:

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-7BF88244-D866-40D1-8C21-7DD1A2C633DF

//-------------------------------------------------------

class keyThumper<T> : Lazy<T>;      another  Swamper

Active Contributor
tony.tomison.iii
Posts: 26
Registered: ‎05-12-2014
Message 3 of 3 (89 Views)

Re: Creating layer is not being created

07-29-2014 08:38 AM in reply to: KerryBrown

Thanks,

 

That was the code I used, but I just deleted it and started over and it worked.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.