Read xref layer color overrides in model space

Read xref layer color overrides in model space

ottosson_mathias
Advocate Advocate
306 Views
2 Replies
Message 1 of 3

Read xref layer color overrides in model space

ottosson_mathias
Advocate
Advocate

I'm trying to get the model space layer colors for external references.

 

I have a model.dwg with an xref.dwg linked, where xref.dwg has a layer called "layer123" which is set to color 9.

If I open the model.dwg in AutoCAD I can see that xref|layer123 has a color override set to 255, 128, 128, but when I look at the layer from the API LayerTableRecord.Color returns the original xref color (ByAci / ACI 9 / RGB 192,192,192).

 

I've checked these system variables if that matters and the values are:

VISRETAIN = 1
VISRETAINMODE = 0
XREFOVERRIDE = 0

 

Here's a shortened version of my code:

I'm reading model.dwg as a side db

using (var sideDb = new Database(false, true))
{
    sideDb.ReadDwgFile(sideDbPath, FileOpenMode.OpenForReadAndAllShare, false, null);
    sideDb.ResolveXrefs(true, false);
    message.FileContents.Layers = LayerHandler.GetLayers(sideDb);
}

 

internal static void GetLayers(Database db)
{
    using (Transaction transaction = db.TransactionManager.StartTransaction())
    {
        var layerTable = transaction.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

        foreach (var layObj in layerTable)
        {
            var lay = layObj.GetObject(OpenMode.ForRead) as LayerTableRecord;
            var color = lay.Color;
            // do stuff...
        }

        transaction.Dispose();
    }
}

 

Am I missing something?

 

0 Likes
307 Views
2 Replies
Replies (2)
Message 2 of 3

daniel_cadext
Advisor
Advisor

You might try from the host drawing, AI says you can get the LayerTableRecord override from LayerTable by using “xrefName|layer123”. If not, the overrides are probably stored in an extension dictionary in the LTR in the host drawing

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 3

Gepaha
Collaborator
Collaborator

https://forums.autodesk.com/t5/net-forum/layertablerecord-linetypeobjectid-of-xref-dependent-layers/... 

Take a look at the link above in message 8 of 15 from @Balaji_Ram. I tested the code and it worked correctly for me. In the code snippet:

// Reset the layer color
layerTableRec.Color = ltr2.Color;

 

0 Likes