AutoLISP.9: DXF Codes



Author Orhan Toker
Profession Architect M.Sc.
  Autodesk Authorized Consultant
  Database Specialist
e-mail  

All AutoLISP versions

Hello dailyautocad readers,

In this lesson, I will explain DXF codes that we will frequently come up against in AutoLISP and ObjectARX™ applications. DXF is a short abbreviation for Drawing Exchange Format which is, as it can be understood from its name, a drawing exchange format that was developed by Autodesk, and it is also used by different drawing programs. However, due to the fact that, not all of the drawing objects in every program is same, sometimes there may be some problems during DXF exchange. In the beginning, DXF codes may be necessary for filtering selection sets or creating your own AutoCAD objects; but for more advanced applications, they will be very useful especially for those who are interested in CNC codes. That’s why DXF codes, which are interpreted as DXF group codes in AutoDesk resources, rare important and I strongly recommend for advanced AutoLISP users. DXF group codes that I will explain in this lesson has version number of u19.1.01.

Objects and Entities

In AutoCAD, it is quite easy to distinguish object and entity terms. Objects exist in drawing database but does not have a graphical representation, like LAYER tables or dictionaries. But, entities have graphical representation as well as they are supported by objects. For example: CIRCLE entity, LAYER object of which is “WALL”.

Group Code Values Table

In AutoCAD, a separate group has been allocated in DXF group codes table for each of objects and entities. I will explain these groups below. If you would like to examine the table in more detail, you can find it here: Table.1

Table.1
TABLE.1

Description of Group codes that are frequently used

In the table I will give, you can find descriptions for the most frequently used group codes. Table.2

Table.2
Table.2

DXF Group codes of the most common AutoCAD entities

You can find DXF codes for the 4 most frequently used entities in Table.3. For other AutoCAD entities, you can see DXF referances in VisualLISP help files.

Table.3
Table.3

General structure of a DXF file

Generally a DXF file is as shown below:

  • HEADER
  • CLASSES
  • TABLES
  • BLOCKS
  • ENTITIES
  • OBJECTS

Now, let’s take a look at an DXF file as an example and create ourselves a new one and import it.

An example DXF file

Create a drawing file that has one LINE entity inside it and export it by using DXFOUT command. In this example, line is going from 10,10 point to 100,250 point. I am doing this to be able to follow up the file more easily. Now, open the file that you have created by using DXFOUT by using any TEXT editor and go to ENTITIES header. You will see the code shown below there.

SECTION
2
ENTITIES
0
LINE
5
EF
330
1F
100
AcDbEntity
8
0
100
AcDbLine
10
10.0
20
10.0
30
0.0
11
260.0
21
110.0
31
0.0
0
ENDSEC
0

Add the code shown below inside the same code just in front of ENDSEC line.

CIRCLE
5
FC
330
1F
100
AcDbEntity
8
0
100
AcDbCircle
10
135.0
20
60.0
30
0.0
40
94.04238894157373
0

SAVE the code and close. Then open the file by using DXFIN. You will see that a circle is added to the drawing. Now, I suggest that you should examine header part of the file.

In this lesson, we examined the values of DXF codes only in AutoCAD. You saw their location inside DXF file only in the last title. DXF codes do not exist inside the file as point lists. Instead, they get values like 10 20 30 X, Y, Z. If you examine the codes of line carefully, you will see that the starting point is 10 20 30 and end point is 11 21 31.

In shortest time, I would like to give an application related to this lesson. However, you have to search for the relevant resources for professional applications like transformation into G-codes that is necessary for CNC.

Obtaining DXF group codes for entities inside AutoCAD

In order to obtain DXF codes of entities inside AutoCAD, you have to use enget function. You can use entget function like this: (entget entity name). And this is the code required to get the DXF code of the entity that is selected:

(entget (car (entsel)))

For example, let’s draw a line that starts from point 150,150 and ends at point 300,200 and write the code that is given above into the command line. When you select the line that you have drawn, you will get the following code from the command line:

((-1 . <Entity name: 7ef5efa0>) (0 . "LINE") (330 . <Entity name: 7ef5ecf8>) (5 . "EC") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 150.0 150.0 0.0) (11 450.0 350.0 0.0) (210 0.0 0.0 1.0))

If we examine the code, we can easily see that it is a list that is made up of dotted pairs. In our previous applications, we have learned about these lists.

  • Entity name 0 in the example is “LINE”.
  • Entity handle 5 in the example is “EC”
  • Entity LAYER 8 in the example is “0″
  • 10 starting point
  • 11 end point

(c) Copyright 2006 Taliasoft, by Orhan Toker

Technorati Tags: , ,

Bu yazinin Turkce’sini okumak icin basiniz.

Similar Posts

Rate this article:

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4 out of 5)
Loading ... Loading ...

8 Responses to “AutoLISP.9: DXF Codes

  • 1
    Sumit
    April 4th, 2007 16:19

    Hello Orhan,

    Can you please explain the concept of OCS? Why it is introduced ?

    I am confused because in UCS for some entities like circle and arc we get values for center (DXF value 10) in
    OCS.

    Thanks and Regards,

    Sumit

  • 2
    Bill
    September 6th, 2007 20:03

    Hi Orhan!
    There must be a typographical error.
    In your example using a line drawn from point 150,150 to point 300,200.
    Doing your “entget” on the line, Assoc 11 appears as (11 450.0 350.0)
    Shouldn’t this be (11 300.0 200.0) to reflect the actual end point of the line?
    Proof that someone is paying attention out here, eh!
    Cheers!

  • 3
    Madrice
    October 25th, 2007 22:17

    Can you explain? For instance, say a BLOCK named SEAT20 contains a polyine. Now I hit a insert which refers to that block, what should I do with all the information given?

  • 4
    sidharth
    October 29th, 2007 22:12

    Hi ,

    I am stuck up in one of the problem while converting doing dxfout commond for transfering the file from autocad to CNC.

    It’s about removal of all dots ( CODE :10). Please send me any lisp program after running, it will delete all dots in the drawing. It will be really helpful for me as it reduces lot of time searching for minute dot.

    Awaiting for your response ,
    Siddu

  • 5
    Orhan Toker
    October 30th, 2007 09:27

    Hi Sidharth,

    We will publish an AutoLISP program that clears all the dots in drawings. please wait for a few days.

    Thank you

  • 6
    Phoe San
    March 16th, 2008 13:53

    Hello Sir,
    Thanks for DXF Codes post.
    :)

  • 7
    Adriana
    July 17th, 2008 17:58

    hello:

    I need to know why I importad a DXF 3D model and I am not able to create a section through the 3D model with sectionplane or section commands. CAD says that tehre a re no object to section, whereas when I create a top, lateral, front or isometric view it does let me. I need help with this one. Is a DXF 3d model converted into an autocad drawing.

  • 8
    Orhan Toker
    July 18th, 2008 09:30

    Hello adrianna,

    Unfortunatally, DXF can not export 3d Models as SOLIDs. There fore you are not be able to CUT or make any SOLID MODEL modifications.

    I don’t know if there is a plugin for this.

    Regards

Leave a Reply