.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating layer is not being created

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
TTIII
481 Views, 2 Replies

Creating layer is not being created

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

 

2 REPLIES 2
Message 2 of 3
kdub_nz
in reply to: TTIII

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

Message 3 of 3
TTIII
in reply to: kdub_nz

Thanks,

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost