- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
yes the layer faded can't back is a is a typical problem ,try to use LayerUtilities.RegenLayers Method, In advanced version it's CoreLayerUtilities.RegenLayers, the RegenPending is a property of LayerUtilities
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks, base on you i found this topic:
Topic about layer unlock, faded,hide ( chinese language)
And here is my code for that:
Regen Layers :
var lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
ObjectId[] layerIds = lt.Cast<ObjectId>().ToArray();
RegenLayers(layerIds);
public static void RegenLayers(ObjectId[] layerIds)
{
dynamic acad = Application.AcadApplication;
int majorVersion = int.Parse(acad.Version.Split('.')[0]);
var type = majorVersion >= 21
? Assembly.Load("accoremgd")?.GetType("Autodesk.AutoCAD.Internal.CoreLayerUtilities")
: Assembly.Load("acmgd")?.GetType("Autodesk.AutoCAD.Internal.LayerUtilities");
var majorInfo = type?.GetMethod("RegenLayers", new[] { typeof(ObjectId[]), typeof(int) });
var propertyInfo = type?.GetProperties().FirstOrDefault(e => e.Name == "RegenPending");
var regenPending = (int)(propertyInfo?.GetValue(null) ?? 0);
majorInfo?.Invoke(null, new object[] { layerIds, regenPending });
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
oh I know this man, he is a member of our organization, and he quoted my post in this article.
The link that the arrow points to is mine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi. Sorry to open this topic again. But you know how to handle it in object arx? (c++). Or how to call the internal library of autocad in object arx?. Here the full verion of code in c++: Im using ads_regen() but it same problem in C#
RestoreLayer()
{
AcString M1 = multilingual_.GetValue(L"M1");
AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
AcDbLayerStateManager* layerStateManager = db->getLayerStateManager();
try
{
if (layerStateManager->hasLayerState(LAYER_NAME) == true)
{
AcDbDictionary* dic_layerstate;
Acad::ErrorStatus es = acdbOpenObject(dic_layerstate, layerStateManager->layerStatesDictionaryId(true), kForRead);
if (es == Acad::eOk && dic_layerstate != nullptr)
{
GetLayoutAndViewPort(dic_layerstate);
}
RestoreData(layerStateManager, db);
layerStateManager->deleteLayerState(LAYER_NAME);
ads_regen();
}
else
{
throw acutPrintf(multilingual_.GetValue(L"M2"));
}
}
catch (...)
{
throw;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I found out the answer for the RegenLayer in ObjectArx (c++) too:
void __stdcall acedRegenLayers(
class AcArray<class AcDbObjectId, class AcArrayMemCopyReallocator<class AcDbObjectId>> const&,
int);
static Acad::ErrorStatus GetLayerObjectIdArray(AcDbObjectIdArray& objIds, bool External = true)
{
Acad::ErrorStatus es = Acad::eOk;
AcDbLayerTablePointer pTable(acdbCurDwg()->layerTableId());
if (pTable.openStatus() != Acad::eOk)
return es;
AcDbLayerTableIterator* pIter(nullptr);
es = pTable->newIterator(pIter);
if (es != Acad::eOk)
return es;
AcDbLayerTableRecord* pRecord(nullptr);
for (pIter->start(); !pIter->done(); pIter->step())
{
es = pIter->getRecord(pRecord, AcDb::kForRead);
if (es == Acad::eOk)
{
if (pRecord->isDependent() && External)
{
objIds.append(pRecord->objectId());
}
else
objIds.append(pRecord->objectId());
}
pRecord->close();
}
delete pIter;
return es;
}
static void RegenLayer()
{
AcDbObjectIdArray layerIds{};
GetLayerObjectIdArray(layerIds);
acedRegenLayers(layerIds, 0);
}