This project has moved. For the latest updates, please go here.

How can I to access a block reference?

Jul 22, 2013 at 3:16 PM
I need to access a block reference in a layer. How?
Coordinator
Jul 22, 2013 at 6:28 PM
Edited Jul 22, 2013 at 6:43 PM
You have a couple options.

1 - The easiest one is to iterate through the inserts (block references) list until you find those that are defined in a specified layer.
string layerName = "MyLayer";
foreach (Insert insert in dxf.Inserts)
{
    if (layerName == insert.Layer.Name)
    {
        // found a block reference in a specified layer
    }
}
2 - Or, now, with version 0.5.0, you can get the list of dxf objects, that make use of a specified layer, and iterate through them until you find the inserts you are looking for.
string layerName = "MyLayer";
List<DxfObject> list = dxf.Layers.GetReferences(layerName);
foreach (DxfObject dxfObject in list)
{
    if (dxfObject.CodeName == DxfObjectCode.Insert)
    {
         // found a block reference in a specified layer
    }
}
Daniel