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
Solved! Go to Solution.
Solved by kdub_nz. Go to Solution.
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
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper