' Define command 'addlayer' _ Public Shared Sub AddLayer() Dim curdb As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager Dim myT As Transaction = tm.StartTransaction() Try Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable) Dim x As New LayerTableRecord With x .Name = "Test Layer" .IsOff = True .IsFrozen = True .IsLocked = True .Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0) 'Color RED .LineWeight = LineWeight.LineWeight120 .IsPlottable = False .Description = "Layer insert sucessfully" End With lt.Add(x) myT.AddNewlyCreatedDBObject(x, True) myT.Commit() Catch ex As Exception myT.Abort() 'If there is an error, abort it. Finally myT.Dispose() End Try End Sub