.NET

.NET

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

change properties of layer in runtime programmatically

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

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()
Try
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
Next
myT.Commit()
Catch ex As Exception
myT.Abort()
MessageBox.Show("An error has ocurred", "Application Test", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
myT.Dispose()
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
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 2 of 2 (83 Views)

Re: change properties of layer in runtime programmatically

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

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.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.