Valued Contributor
Posts: 61
Registered: ‎10-25-2005
Message 1 of 2 (86 Views)

change properties of layer in runtime programmatically

86 Views, 1 Replies
11-28-2005 09:27 AM

I'm trying to change the layer properties during runtime of the AutoCAD programmatically. I want to assign the property 'IsFrozen' of a layer to true/false. To do so i'm using the following code:

Application.DocumentManager.MdiActiveDocument.LockDocument(DocumentLockMode.Write, Nothing, Nothing, True)
Dim curdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForWrite), LayerTable)
For Each objId As ObjectId In lt
Dim _name As String = CType(tm.GetObject(objId, OpenMode.ForRead), LayerTableRecord).Name
If _name = "teste" Then
Dim _layer As LayerTableRecord = CType(tm.GetObject(objId, OpenMode.ForWrite), LayerTableRecord)
_layer.Name = "teste_1"
_layer.IsOff = checkbox1.Checked
_layer.IsFrozen = checkbox2.Checked
_layer.IsLocked = checkbox3.Checked
_layer.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(btnColor.BackColor.R, btnColor.BackColor.G, btnColor.BackColor.B)
_layer.LineWeight = LineWeight.ByLineWeightDefault
_layer.IsPlottable = chkPlottable.Checked
Exit For
End If
Catch ex As Exception
MessageBox.Show("An error has ocurred", "Application Test", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

But when I do this an exception is thrown:

at Autodesk.AutoCAD.Runtime.Interop.ThrowExceptionForErrorStatus(Int32 errorStatus)
at Autodesk.AutoCAD.Runtime.Interop.Check(Int32 returnValue)
at Autodesk.AutoCAD.DatabaseServices.LayerTableRecord.set_IsFrozen(Boolean value)
at WindowsApplication1.Form1.RefreshLayer(LayerTableRecord& _layer) in C:\PROJECTS\Form1.vb:line 552

I noticed that this erro only ocurrs when I try it in a layer that already has something in it, like a line. If I do thid in a layer thats empty it runs fine.

Can someone help me please?

Thanks in advance for your attention.
Filipe Marcelino
Valued Contributor
Posts: 61
Registered: ‎10-25-2005
Message 2 of 2 (86 Views)

Re: change properties of layer in runtime programmatically

11-30-2005 06:51 AM in reply to: fmarcelino

I already solved this problem. Before applly the new properties to the layer, you must change the current layer to another one. Then it will work fine.

Thanks anyway.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
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.