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
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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 : http://www.g-eaux.com/powerclic/explorer/bonusedit_eng.html
If your program is is in C, you will find open source library for projection change, that may be easely adapted to that case ? http://proj.maptools.org /
--
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
PowerClic: http://www.g-eaux.com/powerclic/explorer/english.html
  Click to see the full signature.
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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 ?
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

So this means nested blocks ? So this makes absolute coordinates more difficult to calculate.
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
snipped-for-privacy@yahoo.com schrieb:

yes
yes, and don't forget that block's can be scaled and rotated...
regards Dirk
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Thank you for all your help. I will try to do my best.
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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 <<<base point of block(y) 0.0 30 0.0 3 CK_HATCH_0319 1
0 LINE 5 4B 330 4A 100 AcDbEntity 8 Unnamed [40] 6 Continuous 62 4 48 2.0 370 0 100 AcDbLine 10 -0.5967346429824829 <<<line (relative coordinate in block: y1) 30 0.0 11 -0.4835976660251617 <<<line (relative coordinate in block: y2) 31 0.0 ///////////////////////////////////////// INSERT INSERT INSERT INSERT ///////////////////////////////////////// INSERT INSERT INSERT INSERT
5 476 330 471 100 AcDbEntity 8 Unnamed [20] 62 2 370 -2 100 AcDbBlockReference 2 _CLOSED 10 -4.805948448181153 << Insert x value 20 -0.1038970574736592 <<<Insert x scale factor 42 0.125 <
////////////// I tried the following code " Those co-ordinates are block base point. Block entites will be first translated using the base point first. Thus line would be drawn at: line (relative coordinate in block: x1) = Insert x+ (line {relative coordinate in block: x1}-basepoint) * Insert x scale factor line (relative coordinate in block: x2) = Insert y+ (line {relative coordinate in block: y1}-basepoint) * Insert y scale factor " but it does work for text and doesn't work for line. plz help thanks winthan
-- Message posted using http://www.talkaboutcad.com/group/alt.cad.autocad / More information at http://www.talkaboutcad.com/faq.html
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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 <<<base point of block(y) 0.0 30 0.0 3 CK_HATCH_0319 1
0 LINE 5 4B 330 4A 100 AcDbEntity 8 Unnamed [40] 6 Continuous 62 4 48 2.0 370 0 100 AcDbLine 10 -0.5967346429824829 <<<line (relative coordinate in block: y1) 30 0.0 11 -0.4835976660251617 <<<line (relative coordinate in block: y2) 31 0.0 ///////////////////////////////////////// INSERT INSERT INSERT INSERT ///////////////////////////////////////// INSERT INSERT INSERT INSERT
5 476 330 471 100 AcDbEntity 8 Unnamed [20] 62 2 370 -2 100 AcDbBlockReference 2 _CLOSED 10 -4.805948448181153 << Insert x value 20 -0.1038970574736592 <<<Insert x scale factor 42 //////////
Those co-ordinates are block base point. Block entites will be first translated using the base point first. Thus line would be drawn at: line (relative coordinate in block: x1) = Insert x+ (line {relative coordinate in block: x1}-basepoint) * Insert x scale factor line (relative coordinate in block: x2) = Insert y+ (line {relative coordinate in block: y1}-basepoint) * Insert y scale factor
I tried above, it works for text but it doesn't work for lines,arc,etc. plz help
-- Message posted using http://www.talkaboutcad.com/group/alt.cad.autocad / More information at http://www.talkaboutcad.com/faq.html
Add pictures here
βœ–
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.