ixmilia / dxf

MIT License
221 stars 67 forks source link

How to get an edge/block's connected units (up & downstream) #198

Closed ChristopherVR closed 1 year ago

ChristopherVR commented 1 year ago

There's not a lot of documentation available for this library so I figured I'd ask here.

Say you have an DXF file like this (I'm using SysCAD to create DXF files): image

How can I determine the relationship between CONC_ACID -> TNK_002

Similar to all the other ex. TINK_001 -> TNK__02 -> XPG_005

So far I've got this:

var dxFile = DxfFile.Load(@"C:\SysCAD Projects\SysCAD Training\Tut_Test1.spf\DocsGraphics\05_Flowsheet.DXF");

var result = dxFile.Entities
            .Where(y => y.EntityType is DxfEntityType.Insert)
            .Cast<DxfInsert>()
            .Where(y => y.HasAttributes)
            .Select(y =>
            {
                var tag = y.Attributes.Select(z => z.Value).First();

                var relationships = y.Entities
                   .Where(y => y.EntityType is DxfEntityType.Polyline)
                   .Cast<DxfPolyline>()
                   .Select(z =>
                   {
                       // return z;

                       return new Line(null!, null!);
                   })
                   .ToArray();

                return new Node(tag, relationships);
            })
            .ToArray();

I do see an issue with this approach and that the Entities properties also contain all the Links/Lines between the nodes.

Any help would be appreciated.

brettfo commented 1 year ago

The DXF spec is really pretty simple and only allows for entities without any real kind of connection between them. Different CAD applications are free to use the entity attributes (or XDATA) to put additional metadata that can be used to link the entities, but there's no official way to specify something like that in a plain DXF file; the association you're finding appears to be purely a byproduct of the SysCAD software you're using, so the solution to your problem will be to try and divine exactly how they're encoding these relationships in the DXF and pulling that information out yourself.