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

How to restore a layer state?

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
470 Views, 10 Replies

How to restore a layer state?

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
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

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
Message 3 of 11
wesbird
in reply to: Anonymous

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
Message 4 of 11
Anonymous
in reply to: Anonymous

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
Message 5 of 11
MarkPendergraft
in reply to: Anonymous

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
Message 6 of 11
Anonymous
in reply to: Anonymous

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
Message 7 of 11
NathTay
in reply to: Anonymous

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

Regards - Nathan
Message 8 of 11
MarkPendergraft
in reply to: Anonymous

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.
Message 9 of 11
Anonymous
in reply to: Anonymous

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.
Message 10 of 11
Anonymous
in reply to: Anonymous

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.
Message 11 of 11
Anonymous
in reply to: Anonymous

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!

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