- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
All,
I have an application which saves a Layer State ("XXX_SaveState") and re-sets it after processing. The problem is that on some occasions, layers are turned off when resetting. You will see from my comment below:
RestoreLayerState(pstrLayerStateName, ObjectId.Null, 1, ...
// changed from 0 to 1
// think this is problem, xref layers think they are new
// so are restored off
This is why I implemented the Layer State as previously Xref layer settings were not obeying VISRETAIN after processing. Now, except for some isolated Layers turning off, it is ok for Xrefs. I wonder if my set/saveLayerStateAllProps() has something incorrect? Has anyone used Layer States before/after differently? Thanks for reading, Dale
<code>
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// save Layer State
string LayerStateName = "XXX_SaveState";
LayerStateTools.saveLayerStateAllProps(db, tr, LayerStateName);
// myProcess - so secret even NSA doesn't have a copy
myProcess(db, tr, true, true, true);
// restore Layer State
LayerStateTools.setLayerStateAllProps(db, tr, LayerStateName);
tr.Commit();
}
// restore layer state - overloaded
public static void setLayerStateAllProps(string pstrLayerStateName)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
LayerStateManager acLyrStMan = db.LayerStateManager;
try
{
if (acLyrStMan.HasLayerState(pstrLayerStateName) != false)
{
acLyrStMan.RestoreLayerState(pstrLayerStateName,
ObjectId.Null,
1,
// changed from 0 to 1
// think this is problem, xref layers think they are new
// so are restored off
LayerStateMasks.Color |
LayerStateMasks.CurrentViewport |
LayerStateMasks.Frozen |
LayerStateMasks.LineType |
LayerStateMasks.LineWeight |
LayerStateMasks.Locked |
LayerStateMasks.NewViewport |
LayerStateMasks.On |
LayerStateMasks.Plot |
LayerStateMasks.PlotStyle);
}
else
{
ed.WriteMessage(pstrLayerStateName + " Layer State does not exist");
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// restore layer state - overloaded
public static void setLayerStateAllProps(Database pdb, Transaction ptr, string pstrLayerStateName)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
LayerStateManager acLyrStMan = pdb.LayerStateManager;
try
{
if (acLyrStMan.HasLayerState(pstrLayerStateName) != false)
{
acLyrStMan.RestoreLayerState(pstrLayerStateName,
ObjectId.Null,
1,
// changed from 0 to 1
// think this is problem, xref layers think they are new
// so are restored off
LayerStateMasks.Color |
LayerStateMasks.CurrentViewport |
LayerStateMasks.Frozen |
LayerStateMasks.LineType |
LayerStateMasks.LineWeight |
LayerStateMasks.Locked |
LayerStateMasks.NewViewport |
LayerStateMasks.On |
LayerStateMasks.Plot |
LayerStateMasks.PlotStyle);
}
else
{
ed.WriteMessage(pstrLayerStateName + " Layer State does not exist");
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
<code>
______________
Yes, I'm Satoshi.
Solved! Go to Solution.