.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

change properties of layer in runtime programmatically

1 REPLY 1
Reply
Message 1 of 2
fmarcelino
192 Views, 1 Reply

change properties of layer in runtime programmatically

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
1 REPLY 1
Message 2 of 2
fmarcelino
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost