Message 1 of 12
Create layer programmatically
Not applicable
10-26-2005
09:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
i'm trying to create a layer programmatically with the following code:
< CommandMethod("addlayer") > _
Public Function AddLayer()
Dim curdb As Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim myT As Transaction
curdb = Application.DocumentManager.MdiActiveDocument.Database
tm = curdb.TransactionManager
myT = tm.StartTransaction()
Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable)
Dim x As New LayerTableRecord
x.Name = "Test1"
x.IsOff = chkON.Checked 'Checkbox
x.IsFrozen = chkFrozen.Checked 'Checkbox
x.IsLocked = chkLocked.Checked 'Checkbox
'Color RED
x.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0)
'Lineweight
x.LineWeight = LineWeight.LineWeight120
x.IsPlottable = chkPlottable.Checked 'Checkbox
x.Description = "Layer test1"
lt.Add(x)
myT.Commit()
End Function
This code actually inserts the layer, but first, the property 'DESCRIPTION' appears empty. Second, after I run this code the layer is inserted but, if I access the layer manager just to check if the layer were actually inserted and then click cancel, the insert layer gets removed!! I don't understand why. Maybe because the document database isn't updated automatically...I don't know.
Thanks in advance for your attention, I hope you can help me.
Regards,
Filipe Marcelino
i'm trying to create a layer programmatically with the following code:
< CommandMethod("addlayer") > _
Public Function AddLayer()
Dim curdb As Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim myT As Transaction
curdb = Application.DocumentManager.MdiActiveDocument.Database
tm = curdb.TransactionManager
myT = tm.StartTransaction()
Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable)
Dim x As New LayerTableRecord
x.Name = "Test1"
x.IsOff = chkON.Checked 'Checkbox
x.IsFrozen = chkFrozen.Checked 'Checkbox
x.IsLocked = chkLocked.Checked 'Checkbox
'Color RED
x.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0)
'Lineweight
x.LineWeight = LineWeight.LineWeight120
x.IsPlottable = chkPlottable.Checked 'Checkbox
x.Description = "Layer test1"
lt.Add(x)
myT.Commit()
End Function
This code actually inserts the layer, but first, the property 'DESCRIPTION' appears empty. Second, after I run this code the layer is inserted but, if I access the layer manager just to check if the layer were actually inserted and then click cancel, the insert layer gets removed!! I don't understand why. Maybe because the document database isn't updated automatically...I don't know.
Thanks in advance for your attention, I hope you can help me.
Regards,
Filipe Marcelino