.NET

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

change properties of layer in runtime programmatically

80 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
Posts: 61
Registered: ‎10-25-2005
Message 2 of 2 (80 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community