How to restore a layer state?

How to restore a layer state?

Anonymous
Not applicable
1,362 Views
10 Replies
Message 1 of 11

How to restore a layer state?

Anonymous
Not applicable
Hi,

I'm working on restoring a layer state.

I know object LayerStateManager has a method RestoreLayerState could do it.
But I tried to use the mothod, it desn't work.

Does everybody have an example for doing RestoreLayerState?

Thank you very much.

Zhongwei
0 Likes
1,363 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Would you please help with restoreing "layer state"?



"Zhongwei Xia" wrote in message
news:5553231@discussion.autodesk.com...
Hi,

I'm working on restoring a layer state.

I know object LayerStateManager has a method RestoreLayerState could do it.
But I tried to use the mothod, it desn't work.

Does everybody have an example for doing RestoreLayerState?

Thank you very much.

Zhongwei
0 Likes
Message 3 of 11

wesbird
Collaborator
Collaborator
Application.DocumentManager.MdiActiveDocument.Database.LayerStateManager.RestoreLayerState ( LayerStateName,
ObjectId.Null,
0,
LayerStateMasks.Color |
LayerStateMasks.CurrentViewport LayerStateMasks.Frozen |
LayerStateMasks.LineType |
LayerStateMasks.LineWeight |
LayerStateMasks.Locked |
LayerStateMasks.NewViewport |
LayerStateMasks.On |
LayerStateMasks.Plot |
LayerStateMasks.PlotStyle );

check the help file for detail
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
0 Likes
Message 4 of 11

Anonymous
Not applicable
Thank you for your email.

I know the method would do it, and I tried to use it. It doesn't work, and
there is not much document for how to use this method.

My code is like following:

....
LayerStateManager lsMgr = new LayerStateManager(db);
lsMgr.RestoreLayerState("BlueState", db.ViewportTableId, 0,
LayerStateMasks.None);
...

Is there anything wrong with my code?

Thank you very much.
Zhongwei


wrote in message news:5557920@discussion.autodesk.com...
Application.DocumentManager.MdiActiveDocument.Database.LayerStateManager.RestoreLayerState

check the help file for detail
0 Likes
Message 5 of 11

Anonymous
Not applicable
Here is an example. the variable LayStateName is a global string variable which contains the name of the state to restore. A quick note: If you restore a layer state, and the code runs without any errors but nothing happens on screen, then you may just need to regen. This code uses the interop library to call the regen function in order to deal with that problem.

Private Sub RestoreLayerState()

Dim db As Database = HostApplicationServices.WorkingDatabase
Dim lsm As LayerStateManager = db.LayerStateManager

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
If QueryLayerStates() = False Then
ed.WriteMessage("" + vbCrLf + "*No Layer States Exist in Drawing*")
Exit Sub
End If
CreateForm()
LayStateName = Trim(LayStateName)
If lsm.HasLayerState(LayStateName) Then
Try
lsm.RestoreLayerState(LayStateName, ObjectId.Null, 1, LayerStateMasks.Frozen + LayerStateMasks.On)
Dim AcApp As Autodesk.AutoCAD.Interop.AcadApplication = Application.AcadApplication
Dim AcDoc As Autodesk.AutoCAD.Interop.AcadDocument = AcApp.ActiveDocument
AcDoc.Regen(Autodesk.AutoCAD.Interop.Common.AcRegenType.acActiveViewport)
Catch ex As Exception
ed.WriteMessage("*Operation Failed*")
End Try
ElseIf LayStateName = "" Then
ed.WriteMessage("*Cancel*")
Else
ed.WriteMessage("*Invalid Name*")
End If
End Sub


-Mark Pendergraft
0 Likes
Message 6 of 11

Anonymous
Not applicable
Mark,

I used your code and converted to C#. It works!

Thank you very much. I appreciate your help.

Zhongwei

wrote in message news:5557953@discussion.autodesk.com...
Here is an example. the variable LayStateName is a global string variable
which contains the name of the state to restore. A quick note: If you
restore a layer state, and the code runs without any errors but nothing
happens on screen, then you may just need to regen. This code uses the
interop library to call the regen function in order to deal with that
problem.

Private Sub RestoreLayerState()

Dim db As Database = HostApplicationServices.WorkingDatabase
Dim lsm As LayerStateManager = db.LayerStateManager

Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
If QueryLayerStates() = False Then
ed.WriteMessage("" + vbCrLf + "*No Layer States Exist in
Drawing*")
Exit Sub
End If
CreateForm()
LayStateName = Trim(LayStateName)
If lsm.HasLayerState(LayStateName) Then
Try
lsm.RestoreLayerState(LayStateName, ObjectId.Null, 1,
LayerStateMasks.Frozen + LayerStateMasks.On)
Dim AcApp As Autodesk.AutoCAD.Interop.AcadApplication =
Application.AcadApplication
Dim AcDoc As Autodesk.AutoCAD.Interop.AcadDocument =
AcApp.ActiveDocument
AcDoc.Regen(Autodesk.AutoCAD.Interop.Common.AcRegenType.acActiveViewport)
Catch ex As Exception
ed.WriteMessage("*Operation Failed*")
End Try
ElseIf LayStateName = "" Then
ed.WriteMessage("*Cancel*")
Else
ed.WriteMessage("*Invalid Name*")
End If
End Sub


-Mark Pendergraft
0 Likes
Message 7 of 11

Anonymous
Not applicable
What version are you using? 2007 has Autodesk.AutoCAD.EditorInput.Editor.Regen()

Regards - Nathan
0 Likes
Message 8 of 11

Anonymous
Not applicable
Wow. Thats pretty cool. I have LDD 2006 and 2007. However everyone else in my company is using 2006. So i'm stuck with the old methods. 😞

I really feel that the Managed libraries were/are missing some very important methods and properties that would force me to use the Interop reference. But it sounds like AutoDesk is getting their stuff together.... Now if they could only do that for Aecc_Objects in Land Development Desktop.
0 Likes
Message 9 of 11

Anonymous
Not applicable
You can also send "regen" to the command line via
SendStringToExecute(), or by using the wrapper for
acedCommand() that's available on on my website.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5558494@discussion.autodesk.com...
Wow. Thats pretty cool. I have LDD 2006 and 2007. However everyone else in my company is using 2006. So i'm stuck with the old methods. 😞

I really feel that the Managed libraries were/are missing some very important methods and properties that would force me to use the Interop reference. But it sounds like AutoDesk is getting their stuff together.... Now if they could only do that for Aecc_Objects in Land Development Desktop.
0 Likes
Message 10 of 11

Anonymous
Not applicable
I'm using AutoCad 2006.

doc.SendStringToExecute("regen", false, false, false); works pretty good
too.

Thank you for your guys helps.
Zhongwei

wrote in message news:5558494@discussion.autodesk.com...
Wow. Thats pretty cool. I have LDD 2006 and 2007. However everyone else
in my company is using 2006. So i'm stuck with the old methods. 😞

I really feel that the Managed libraries were/are missing some very
important methods and properties that would force me to use the Interop
reference. But it sounds like AutoDesk is getting their stuff together....
Now if they could only do that for Aecc_Objects in Land Development Desktop.
0 Likes
Message 11 of 11

Anonymous
Not applicable
I'm not too savy with code, but this doesn't look like a lisp routine, how do you use this type of code? I could really use this because we are on LDT2007 and the layer state manager is buried in the layer dialogue box and it's rutheless for productivity.

thanks!
0 Likes