.NET

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

Creating layer is not being created

135 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: 278
Registered: ‎11-29-2008
Message 2 of 3 (128 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

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

Everything will work just as you expect it to, unless your expectations are incorrect.

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

Active Contributor
tony.tomison.iii
Posts: 32
Registered: ‎05-12-2014
Message 3 of 3 (96 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.