Reply to Message

View discussion in a popup

Replying to:
nam_h_tran
337 Views, 10 Replies

Trying to mimic LAYUNISO command

The code below im trying to mimic the ability of layuniso command. But it not make the layer faded restored back to normal. Although it restore everything normally like layuniso. Im trying to regen model too but seem like it not working.

 

here below the code:

 

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using TrainingAutoCAD.Helpers;



var doc = Application.DocumentManager.MdiActiveDocument;
var ed = Application.DocumentManager.CurrentDocument.Editor;
var db = Application.DocumentManager.CurrentDocument.Database;
using (var tr = db.TransactionManager.StartTransaction())
{
LayerStateManager acLyrStMan;
acLyrStMan = doc.Database.LayerStateManager;

DBDictionary? acDbDict;
acDbDict = tr.GetObject(acLyrStMan.LayerStatesDictionaryId(true),
OpenMode.ForWrite) as DBDictionary;

string sLyrStName = "_LAYISO_STATE";


if (acLyrStMan.HasLayerState(sLyrStName) == true)
{
var rb = acDbDict.XData;
if (rb != null)
{
int index = 0;
foreach (TypedValue typeVal in rb)
{
if (index == 1)
{
string layoutValue = $"*{typeVal.Value.ToString()}";
Application.SetSystemVariable("CLAYOUT", layoutValue);
break;
}
index++;
}
}
acLyrStMan.RestoreLayerState(sLyrStName,
ObjectId.Null,
0,
LayerStateMasks.On |
LayerStateMasks.Locked |
LayerStateMasks.Frozen |
LayerStateMasks.CurrentViewport |
LayerStateMasks.NewViewport);
acLyrStMan.DeleteLayerState(sLyrStName);
acDbDict.Erase();
ed.Regen();
}
tr.Commit();
}

ed.Regen();