Get Block coordinates to adjust relative Entities

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

Moderator: andrew

Post Reply
Semon
Registered Member
Posts: 2
Joined: Wed Oct 29, 2014 8:28 am

Get Block coordinates to adjust relative Entities

Post by Semon » Wed Oct 29, 2014 9:14 am

I am currently working on a Project where i need to convert dxf (AC1009) files. The problem i have currently is that it works fine as long as Entities hold absolute Coordinates. As soon as Entities have relative coordinates to the Block they are within, it doesn't work and i can only get the relative coordinates as i am unable to connect the parsed Block Elements with the parsed Entities.

This is because dxflib seems to group together parsed Elements and only then call appropriate methods. So when i convert a dxf file and check which methods are called i get something like this:

Code: Select all

addBlock
endBlock
addBlock
endBlock
addBlock
endBlock
addBlock
endBlock
addBlock
endBlock
addBlock
endBlock
addText
addText
addText
addText
addText
addText
addText
addText
addText
addText
addText
addText
addText
addText
addText
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
addPolyline
endEntity
So the problem is that there is no Connection between Blocks, Polylines and Text, because the methods aren't called sequentiel while parsing, if it were like this:

Code: Select all

addBlock
addText
endBlock
addBlock
addPolyine
endEntity
endBlock
I would have the relation of Blocks and everything thats within them.

So if anyone got a suggestion how to solve this problem, it would be much appreciated.

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

Re: Get Block coordinates to adjust relative Entities

Post by andrew » Wed Oct 29, 2014 9:27 am

The call sequence is indeed:
addBlock
addLine, addArc, ...
endBlock

Where the line and arc are part of the block definition.
If addBlock is directly followed by endBlock, this would indicate an empty block, or perhaps a block that contains only entities you have not handled yet in any way (?)

Note that block definitions are not visible in the drawing. Once a block is actually used as block reference ('insert'), addInsert is called with the appropriate parameters such as angle, scale, etc.

Block definitions can be inserted into a drawing multiple times with different parameters.

Semon
Registered Member
Posts: 2
Joined: Wed Oct 29, 2014 8:28 am

Re: Get Block coordinates to adjust relative Entities

Post by Semon » Wed Oct 29, 2014 10:26 am

I implemented all methods to check which ones were called and found out that "addInsert" is called before all "addText" calls. And those inserts hold the coordinates i need.

Thank you very much, this helped me alot.

ugurmdogan
Registered Member
Posts: 2
Joined: Wed Jan 21, 2015 1:46 pm

Re: Get Block coordinates to adjust relative Entities

Post by ugurmdogan » Wed Jan 21, 2015 2:46 pm

Hi everyone.

Firstly, I want to thank to author of this great library. I didn't know anything about dxf and it really helped me to get started but I'm stuck now.

My question is related but it's more about "interpreting" the data. I get the coordinates of the lines of a block and put them inside a vector. Then I get coordinates of the insert. It's fine till now but I can't make use of them properly.

How can I know which insert coordinate is which? It reads a block then it's entities then again a block and it's entities and so on... When the blocks are over then it reads the insert coordinates. If every block had a reference(insert) then it would be ok but it's not. I need to be able to tie the insert coordinates to the right blocks. I hope you get my problem.

Thanks.

Code: Select all

vector< vector< vector<double> > > bloklar; // this is global
virtual void addBlock(const DL_BlockData& d){
        vector< vector<double> > blok;
        if(d.name!="*Model_Space"){
            bloklar.push_back(blok); //for relative coordinates of entities
            bloklar.push_back(blok); //for coordinates of references(insert)
        }
}
virtual void addLine(const DL_LineData& d){
        vector<double> line;
        unsigned int s=bloklar.size();
        line.push_back(d.x1);
        line.push_back(d.y1);
        ...
        bloklar[s-2].push_back(line);
}
virtual void addInsert(const DL_InsertData& d){
        vector<double> row;
        unsigned int s=bloklar.size();
        row.push_back(d.ipx);
        ...
        for(unsigned int i=1; i<s; i+=2){
                bloklar[i].push_back(row);
        }
}
virtual void endBlock(const DL_BlockData& d){
}

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

Re: Get Block coordinates to adjust relative Entities

Post by andrew » Thu Jan 22, 2015 9:23 am

ugurmdogan wrote:I need to be able to tie the insert coordinates to the right blocks.
Inserts reference blocks through their name:

DL_InsertData::name
DL_BlockData::name

An insert might refer to a block called 'MyBlock'. This means that an instance of the block 'MyBlock' is inserted at DL_InsertData::ipx, DL_InsertData::ipy.

ugurmdogan
Registered Member
Posts: 2
Joined: Wed Jan 21, 2015 1:46 pm

Re: Get Block coordinates to adjust relative Entities

Post by ugurmdogan » Fri Jan 23, 2015 8:03 pm

I don't know how I missed that name variable. It works now. Thank you for your response.

Post Reply

Return to “dxflib 'How Do I' Questions”