Reading DXF: how to assign a line to a layer ?

Use this forum to ask questions about how to do things in dxflib.

Moderator: andrew

Post Reply
rekoru
Registered Member
Posts: 2
Joined: Sun Jun 23, 2013 7:51 pm

Reading DXF: how to assign a line to a layer ?

Post by rekoru » Mon Jun 24, 2013 6:20 pm

I have a DXF file with lines assigned to several layers. I would like to determine a layer for each line object in a DXF file. As there is no layer info in DL_LineData struct, I hoped to get the line->layer affiliation info using order of addLine() and addLayer() calls. I wrote simple test app and discovered that all addLayer() calls during execution of DL_Dxf::in() happen before first addLine call(). How to check to which layer a line belongs to?

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: Reading DXF: how to assign a line to a layer ?

Post by andrew » Mon Jun 24, 2013 7:32 pm

Layers are reported through the DL_CreationInterface using the function DL_CreationInterface::addLayer(...). All layers that are reported through that interface are typically stored in a list or map of layers.

The current layer is part of the current entity attributes. You can get the current attributes by calling
DL_Attributes getAttributes()
of your implementation of the DL_CreationInterface.

When an entity is reported, for example a line entity though DL_CreationInterface::addLine(...), you can get information about the layer it is on (as well as other attributes) through the attributes member variable:
MyImporter::addLine(const DL_LineData& data) {
    std::out << "line is on layer " << getAttributes().getLayer();
}

rekoru
Registered Member
Posts: 2
Joined: Sun Jun 23, 2013 7:51 pm

Re: Reading DXF: how to assign a line to a layer ?

Post by rekoru » Mon Jun 24, 2013 8:04 pm

I missed whole attributes thing. But now my sample works exactly as I need to :) Thank you very much!

Post Reply

Return to “dxflib 'How Do I' Questions”