Kerry, I would have thought Dictionary<> myself, but I could be wrong.
Personally, I'd be saving and restoring a LayerState
I was about to ask for help in figuring out what the deal was with LayerStates, but after a bit of searching the Autodesk forums I came up with the following: -
(At the moment the two commands are called by the "savelayers" and "restorelayers" commands respectively.)
public class LayerCommands
{
[CommandMethod ("SaveLayers")]
public static void SaveLayerstate()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
DocumentLock doclock = doc.LockDocument();
Database db = doc.Database;
LayerStateManager lsm = db.LayerStateManager;
string dwgname = "test";
lsm.SaveLayerState(dwgname, LayerStateMasks.Frozen |
LayerStateMasks.Locked | LayerStateMasks.On, ObjectId.Null);
}
[CommandMethod("RestoreLayers")]
public static void RestoreLayerstate()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
DocumentLock doclock = doc.LockDocument();
Database db = doc.Database;
LayerStateManager lsm = db.LayerStateManager;
string dwgname = "test";
lsm.RestoreLayerState(dwgname, ObjectId.Null, 0,
LayerStateMasks.Frozen | LayerStateMasks.Locked | LayerStateMasks.On);
}
}
For once that was quite easy.
You can test that this works by running first the
savelayers command in a drawing with a few layers. Then change some of the properties of those layers, and run the
restorelayers command. You should then see that the properties you changed have been restored.
For my purposes (I think) I'm only storing the
Frozen,
Locked and
On settings, but you can add more as you see fit.