using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace Test
{
public class Test
{
[CommandMethod("LSPAV", CommandFlags.NoBlockEditor)]
public void Run()
{
Document adoc = Application.DocumentManager.MdiActiveDocument;
Database db = adoc.Database;
Editor ed = adoc.Editor;
LayoutManager lm = LayoutManager.Current;
LayerStateManager lsm = db.LayerStateManager;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Layout cl = tr.GetObject(lm.GetLayoutId(lm.CurrentLayout), OpenMode.ForRead) as Layout;
ObjectIdCollection colvp = cl.GetViewports();
colvp.RemoveAt(0);
foreach (ObjectId id in colvp)
{
Viewport vp = tr.GetObject(id, OpenMode.ForRead) as Viewport;
// Номер текущего видового экрана
short vpNumber = (short)vp.Number;
// Обновляем вид
ed.UpdateScreen();
// Переходим внутрь активного ВЭ
ed.SwitchToModelSpace();
// Переключаемся в обрабатываемый ВЭ
Application.SetSystemVariable("CVPORT", vpNumber);
if (lsm.HasLayerState("1") == true)
{
lsm.RestoreLayerState("1", id, 1,
LayerStateMasks.Color |
LayerStateMasks.Frozen |
LayerStateMasks.LineType |
LayerStateMasks.LineWeight | LayerStateMasks.Locked |
LayerStateMasks.On |
LayerStateMasks.Plot | LayerStateMasks.PlotStyle |
//LayerStateMasks.LastRestored|
//LayerStateMasks.None|
LayerStateMasks.NewViewport |
LayerStateMasks.CurrentViewport |
LayerStateMasks.Transparency
);
}
ed.SwitchToPaperSpace();
}
tr.Commit();
}
}
}
}