Entities handles in dxf file

Discussion in 'AutoCAD' started by Peter S., Oct 20, 2004.

  1. Peter S.

    Peter S. Guest

    Hello group,

    I am writting an application that will create dxf files (2000 format). I
    only use the TEXT, LWPOLYLINE and CIRCLE entities. My question is, is there
    any type of restrictions for the entities handles? If I have e.g. 200
    entities then the handles can be from 100 up too 300 (converted to
    hexadecimal)? Are there any rules on how I must create the handles (e.g.
    first all the polylines, then circles etc)....

    Thank you all
     
    Peter S., Oct 20, 2004
    #1
  2. Peter S.

    O Ransen Guest

    Do you *need* handles for your application? If not simply don't write
    them...

    Unique and easy to use graphics programs
    http://www.ransen.com
     
    O Ransen, Oct 21, 2004
    #2
  3. Peter S.

    Johnnix Guest

    Hello,

    If I ommit the handle for the LWPOLYLINE entity, then when I try to load the
    dxf, autocad produces an error (Handle missing)...I dont know if there is a
    special switch that I must use in order not to create a dxf with the handles
    property of the entities
     
    Johnnix, Oct 21, 2004
    #3
  4. Peter S.

    O Ransen Guest

    Could you use the old style POLYLINE entity instead? Just guessing...


    Unique and easy to use graphics programs
    http://www.ransen.com
     
    O Ransen, Oct 21, 2004
    #4
  5. Peter S.

    Ben Gun Guest

    Mu guess is that for 2000 format DXF you do need handles.

    I have done it and what you do is you assign consecutive numbers to
    them. I'll dig out some details tomorrow if you like. Once you've
    finished you have to set a variable to the next available handle so
    AutoCAD knows where to continue.

    hth,
    Ben
     
    Ben Gun, Oct 21, 2004
    #5
  6. Peter S.

    Peter S. Guest

    Hello Ben,

    In 2000 dxf format the 5 tag (entity handle) cannot be ommited. So what I do
    is begin from 1000 and every time I add an entity I add 1 too the previous
    handle!!! (I first convert the integer value to hex value).

    If you please, I wait for your tips..... BTW, r there any documents on the
    internet about dxf files (except from the hlp files provided by autodesk)?

    Thank you very much
     
    Peter S., Oct 21, 2004
    #6
  7. Peter S.

    O Ransen Guest

    Why does it have to be 2000 format? AutoCAD 2000 can read
    R12 format DXF too. Just curious...!

    Unique and easy to use graphics programs
    http://www.ransen.com
     
    O Ransen, Oct 22, 2004
    #7
  8. Peter S.

    Johnnix Guest

    Well, you r right in this matter but I dont know if later versions of
    autocad can and will read r12 or 114 dxf formats. Maybe I should change back
    to r14 :eek:)
     
    Johnnix, Oct 22, 2004
    #8
  9. Peter S.

    O Ransen Guest

    I am pretty sure that later versions of AutoCAD *can* read older
    DXF files.


    Unique and easy to use graphics programs
    http://www.ransen.com
     
    O Ransen, Oct 22, 2004
    #9
  10. Peter S.

    Ben Gun Guest

    Hi Peter,
    here is what I did:

    Assume my DXF is loaded in Memo1. I want to insert a text at line
    number 'pos', which is just after 'ENTITIES'.
    Everytime I add an entity, I set its handle to 'getHandle':

    <snippet>
    Memo1.Lines.Insert(pos,' 8');
    Memo1.Lines.Insert(pos,'AcDbEntity');
    Memo1.Lines.Insert(pos,'100');
    Memo1.Lines.Insert(pos,getHandle);
    Memo1.Lines.Insert(pos,' 5');
    Memo1.Lines.Insert(pos,'TEXT');
    Memo1.Lines.Insert(pos,' 0');
    </snippet>

    In the above example, I add the lines back to front, as 'pos' (insert
    position) is constant.

    And this is what my 'getHandle' does:

    function TCopyDialog.getHandle: String;
    // find next handle
    var
    i:Integer;
    hand:Integer;
    begin
    hand:=0;
    i:=0;

    repeat
    if (Memo1.Lines=' 9') and
    (Memo1.Lines[i+1]='$HANDSEED') and
    (Memo1.Lines[i+2]=' 5')
    then hand:=StrToInt('$'+Memo1.Lines[i+3]);
    inc(i,2); // we can safely step by 2 in DXFs
    until (i>=Memo1.Lines.Count-2) or (hand>0);

    // increment $HANDSEED
    if hand>0 then Memo1.Lines[i+1]:=IntToHex(hand+1,8);

    // return original $HANDSEED
    Result:=IntToHex(hand,8);
    end;

    So 'getHandle' returns the next handle and increments the variable
    $HANDSEED at the same time. Look up $HANDSEED in your DXF reference.

    hth, Ben
     
    Ben Gun, Oct 23, 2004
    #10
  11. Peter S.

    Ben Gun Guest

    The reason why I had to write this format is that I had to read R2000
    drawings in, modify if necessary, and write out again. The clients
    couldn't be asked to save to R12 DXF.

    Also, R12 doesn't support certain entities, this could be another
    reason to use a later DXF version. E.g., R12 DXF has no concept of
    groups.

    hth,
    Ben
     
    Ben Gun, Oct 23, 2004
    #11
  12. Peter S.

    Johnnix Guest

    Hello Ben,

    Thank you for your replay. Well, first of all I use a template dxf file
    which misses the entities section. I start from handle 1000 (I use
    IntToHex(handle,2)) and every time I insert an entity I increment handle by
    1 (perhaps I should change it by 2 now!). So, according to you, when I am
    done with all my entities and just before I save the dxf to my disk I should
    change the $HANDSEED to the last handle I used plus 1 (or 2)....
     
    Johnnix, Oct 23, 2004
    #12
  13. Peter S.

    Ben Gun Guest

    No, 1.
    No, 1. The skip 1 is for finding a certain entry in a DXF file. You
    know how you have one line with '0', next says 'SECTION'. One line
    says '8', next says '0'. They come in pairs. So if you are looking for
    a particular entry, you can step forward by 2.

    $HANDSEED holds the next handle. Please look it up in the online help.

    hth, Ben
     
    Ben Gun, Oct 23, 2004
    #13
  14. Peter S.

    Johnnix Guest

    Ok, Ben, my mistake...I got it now. Is there any good handbook about dxf
    (besides autotdesk's hlp files)
     
    Johnnix, Oct 23, 2004
    #14
  15. Peter S.

    Ben Gun Guest

    Sorry, you ask the wrong bloke. I don't have any books.
    Ben
     
    Ben Gun, Oct 23, 2004
    #15
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.