DXF processing: how to calculate absolute coordinates in blocks

I have a software that needs to process dxf files and I am having a nightmare trying to find the absolute corrdinates of LINEs inside blocks.

This is what I know about BLOCKS:

Each BLOCK (in the BLOCKS section) has a block name that is related to an INSERT entity (In the ENTITIES section). The INSERT entity defines the transformation parameters such as origin, scale and rotation, to transform the BLOCK coordinates from relative to absolute coordinates. All coordinates in the BLOCK may be transformed using the parameters defined in INSERT. Each BLOCK ends with ENDBLK.

This is what I need to do:

I need to transform the relative coordinates of LINEs inside blocks (in the BLOCKS section) to absolute coordinates. What I do is search (using the block name) the corresponding INSERT entity (in the ENTITIES section) which gives me the coordinates of the block, so by adding the relative + block corrdinates I can obtain the absolute coordinates for LINEs.

SO FAR THE EXPLANATION, NOW THE PROBLEM TO SOLVE:

What can I do if I find more than one INSERT entity with the same block name ? How do I know which one applies to each LINE, since for a given block name there is only one BLOCK structure in the blocks SECTION but in some cases there is more than one INSERT entity in the ENTITIES section.

Thanks for your help Jose Maria

Reply to
jmespinosabaviera
Loading thread data ...

snipped-for-privacy@yahoo.com a écrit :

In the BLOCKS section, you've got the BLOCK definition. A dxf can contain a BLOCK definition, but none INSERT occurrence The entities that are defining the block are described only in BLOCK section. All their coordinates are relative to the specified insertion point of the bloc.

The Block and insert system is designed to compress files and make the drawing reactive : One BLOCK definition, and for each occurence, only a insertion point, and optional, x,y,z scale factor and rotation angle. The way you've got to think is that for each occurence of the Block (Insert) you will have to perform a geodesic projection change, to calculate the real position of all entities of your insert.

You must take care of the fact that DXF code are optional : By default, only 10,20,30 code for insertion point. If the scale is not 1 : 41,42,43 appear If rotation : 50 code If 3d_rotation : 210 220 230

If you wish to have a syntaxic coloration of DXF files see this page :

formatting link
If your program is is in C, you will find open source library for projection change, that may be easely adapted to that case ?
formatting link

Reply to
gegematic

Thanks for your help, but the I do not understand. Once I know which INSERT corresponds to each line, there is no problem, I know how to calculate.

The problem I have is that I need to know which of the INSERTs in the entities secion WITH THE SAME BLOCK NAME I must take to calculate the absolute coordinates form each LINE in the BLOCKS section.

The problem is that for ONE block name there is only ONE block in the blocks sections with many LINEs and there may be one or MORE THAN ONE INSERT in the entities section. If there is only one INSERT with the corresponding block name, there is no problem. But if there are several inserts, I need to know for each LINE which of the INSERTS I need to use to calculate the absolute coordinates.

Thanks

Reply to
jmespinosabaviera

snipped-for-privacy@yahoo.com schrieb:

Every block defined in the block section can be inserted more than one time! So you have to transform the complete block for ANY insert you find.

regards Dirk

Reply to
dbu

Thank you very much, that makes sense.

Another question: there are cases where the BLOCK in the blocks section does not correspond to any INSERT in the entities section, so this block is "garbage". As I read the dxf file from beginning to end, I read the block first, later the insert. Do I have anyway to know when I read the BLOCK in the blocks section that this block is useless before reaching the entities section and realizing that there is no INSERT with the same name ?

Reply to
jmespinosabaviera

snipped-for-privacy@yahoo.com schrieb:

No you, have to check the INSERT's to see if a block is used or not. And yes INSERT's can be within block's, too and not only in the entities section.

regards Dirk

Reply to
dbu

So this means nested blocks ? So this makes absolute coordinates more difficult to calculate.

Reply to
jmespinosabaviera

snipped-for-privacy@yahoo.com schrieb:

yes

yes, and don't forget that block's can be scaled and rotated...

regards Dirk

Reply to
dbu

Thank you for all your help. I will try to do my best.

Reply to
jmespinosabaviera

how do you adjust the relative coordinate to absoulte coordinate? //////////////////////////

BLOC KBLOCKBLOCKBLOCKBLOCK

5 62 330 4A 100 AcDbEntity 8 0 100 AcDbBlockBegin 2 CK_HATCH_0319 70 0 71 0 10
Reply to
wwinthan

Hi, I'm winthan. I saw the question u post on forum. I have the same problem with converting the relative coordinates of the lines insides the block(dxf) to

absolute coordinates. the question u asked is in the following Quote: " I have a software that needs to process dxf files and I am having a nightmare trying to find the absolute corrdinates of LINEs inside blocks.

This is what I know about BLOCKS:

Each BLOCK (in the BLOCKS section) has a block name that is related to an INSERT entity (In the ENTITIES section). The INSERT entity defines the transformation parameters such as origin, scale and rotation, to transform the BLOCK coordinates from relative to absolute coordinates. All coordinates in the BLOCK may be transformed using the parameters defined in INSERT. Each BLOCK ends with ENDBLK.

This is what I need to do:

I need to transform the relative coordinates of LINEs inside blocks (in the BLOCKS section) to absolute coordinates. What I do is search (using the block name) the corresponding INSERT entity (in the ENTITIES section) which gives me the coordinates of the block, so by adding the relative + block corrdinates I can obtain the absolute coordinates for LINEs.

SO FAR THE EXPLANATION, NOW THE PROBLEM TO SOLVE:

What can I do if I find more than one INSERT entity with the same block name ? How do I know which one applies to each LINE, since for a given block name there is only one BLOCK structure in the blocks SECTION but in some cases there is more than one INSERT entity in the ENTITIES section. " DXF Data I'm trying to read /////////////////////////////// ////////////////////////////// BLOC KBLOCKBLOCKBLOCKBLOCK

5 62 330 4A 100 AcDbEntity 8 0 100 AcDbBlockBegin 2 CK_HATCH_0319 70 0 71 0 10
Reply to
wwinthan

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.