Looks like they forgot to wrap some methods of the LayerStateManager
AcDbLayerStateManager::addLayerStateLayers to add layers to a layerstate and
AcDbLayerStateManager::removeLayerStateLayers for removing layers
So far this has been working with minimal testing, but not sure the best way to do this or if this gonna blow up on me later
I have the following xrefs
Host
-XrefA
--XrefB
I am copying XreB layers settings from XreA into the Host.
Seems like the easiest so for is using
LayerStateManager.ImportLayerStateFromDb will handle cloning linetypes etc...
So open XrefA in a side databse use its LayerStateManager to create a LayerState with only XrefB layers then use Host LayerStateManger to import it.
The problem is I cannot choose which layers with the LayerStateManger and having to do it directly in the extension directory.
So I use the XrecordEnumerator to enumerate through the result buffer until I find a 330 for Layer ObjectId then I remove it and continue removing lines until I remove 440 for its transparency which I am assuming is the last code for a layer.
Shit! I just realized I need to set transparency on layer to see if adds more codes following it.
If you look at pic below I am assuming the format starts with its pointer and ends with the alpha value.
This example creates a layerstate called xref then removes all the layers from it that not xref layers.
private LayerStateMasks lsMasks = LayerStateMasks.Color | LayerStateMasks.Frozen | LayerStateMasks.LineWeight | LayerStateMasks.LineType | LayerStateMasks.On | LayerStateMasks.Plot | LayerStateMasks.Locked;
[CommandMethod("XrefLayersOnlyLayerState")]
public void XrefLayersOnlyLayerState()
{
var lman = Db.LayerStateManager;
string name = "xref";
lman.SaveLayerState(name, lsMasks, ObjectId.Null);
using (Transaction trx = Db.TransactionManager.StartTransaction())
{
var dic = lman.LayerStatesDictionaryId(false).GetDBObject<DBDictionary>();
if (!dic.Contains(name))
{
Ed.WriteLine("The pooch is now screwed");
return;
}
Xrecord xrec = dic.GetAt(name).GetDBObject<Xrecord>(OpenMode.ForWrite);
XrecordEnumerator enumer = xrec.GetEnumerator();
while (enumer.MoveNext())
{
if (enumer.Current.TypeCode == (int)DxfCode.SoftPointerId && enumer.Current.Value != null)
{
try
{
ObjectId id = (ObjectId)enumer.Current.Value;
if (!id.IsNull && id.IsValid)
{
LayerTableRecord ltr = id.GetDBObject<LayerTableRecord>();
if (!ltr.IsDependent)
{
enumer.RemoveCurrent();
while (enumer.Current.TypeCode != (int)DxfCode.Alpha)
{
enumer.RemoveCurrent();
}
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Ed.WriteLine(ex.Message);
}
}
}
trx.Commit();
}
}