DXF processing: how to calculate absolute coordinates in blocks

Discussion in 'AutoCAD' started by jmespinosabaviera, Apr 5, 2006.

  1. 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
     
    jmespinosabaviera, Apr 5, 2006
    #1
  2. jmespinosabaviera

    gegematic Guest

    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/
     
    gegematic, Apr 5, 2006
    #2
  3. 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
     
    jmespinosabaviera, Apr 5, 2006
    #3
  4. jmespinosabaviera

    dbu Guest

    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
     
    dbu, Apr 5, 2006
    #4
  5. 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 ?
     
    jmespinosabaviera, Apr 5, 2006
    #5
  6. jmespinosabaviera

    dbu Guest

    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
     
    dbu, Apr 5, 2006
    #6
  7. And yes INSERT's can be within block's, too and not only in the
    So this means nested blocks ? So this makes absolute coordinates more
    difficult to calculate.
     
    jmespinosabaviera, Apr 5, 2006
    #7
  8. jmespinosabaviera

    dbu Guest

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

    regards
    Dirk
     
    dbu, Apr 5, 2006
    #8
  9. Thank you for all your help. I will try to do my best.
     
    jmespinosabaviera, Apr 5, 2006
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.