Author Topic: Attributes and DXF information  (Read 4786 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Attributes and DXF information
« on: October 27, 2005, 07:17:11 AM »
I'm having a hard time getting my head round this.

I have this dxf info from a block with attributes
Code: [Select]
((-1 . <Entity name: 7dd0a590>) (0 . INSERT) (330 . <Entity
name: 7da62cf8>) (5 . 182) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0)
(100 . AcDbBlockReference) (66 . 1) (2 . A1_SHEET) (10 0.0 0.0 0.0) (41 . 1.0)
(42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210
0.0 0.0 1.0))

This has a number of attributes, so how can I get, and then manipulate the attribute values?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

whdjr

  • Guest
Re: Attributes and DXF information
« Reply #1 on: October 27, 2005, 07:49:13 AM »
Entnext

or

Vlax-ename->vla-object and then vla-get-attributes

 :-)
I'll let you research before I give you the full solution.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Attributes and DXF information
« Reply #2 on: October 27, 2005, 07:49:49 AM »
In dxf coding group 66 is used to flag whether a block has entites (attributes) that follow, a 0 indicating none, a 1 indicating at least 1.

For example, in your data --

Code: [Select]
(   (-1 . <Entity name: 7dd0a590>)
    (0 . INSERT)
    (330 . <Entity name: 7da62cf8>)
    (5 . 182)
    (100 . AcDbEntity)
    (67 . 1)
    (410 . Layout1)
    (8 . 0)
    (100 . AcDbBlockReference)
    (66 . 1) <== has attributes.
    (2 . A1_SHEET)
    (10 0.0 0.0 0.0)
    (41 . 1.0)
    (42 . 1.0)
    (43 . 1.0)
    (50 . 0.0)
    (70 . 0)
    (71 . 0)
    (44 . 0.0)
    (45 . 0.0)
    (210 0.0 0.0 1.0)
)

But how do you get them?

Block instances and attributes (or head polyline entity and vertices) utilize a scheme that is loosely based on linked lists: Have a head item, and if there are associated items, each item points to the next item unitil you reach the last item, which either points to the first item or nothing. And so it is with block inserts and attributes.

Example insert with 3 attributes --

Code: [Select]
(
    (-1 . <Entity name: 7ef60ee8>)
    (0 . "INSERT")
    (330 . <Entity name: 7ef60cf8>)
    (5 . "95")
    (100 . "AcDbEntity")
    (67 . 0)
    (410 . "Model")
    (8 . "0")
    (100 . "AcDbBlockReference")
    (66 . 1) ;; <== has entities that follow
    (2 . "IMPLODE-00000")
    (10 18.1549 14.9443 0.0)
    (41 . 1.0)
    (42 . 1.0)
    (43 . 1.0)
    (50 . 0.0)
    (70 . 0)
    (71 . 0)
    (44 . 0.0)
    (45 . 0.0)
    (210 0.0 0.0 1.0)
)

(
    (-1 . <Entity name: 7ef60ef0>)
    (0 . "ATTRIB")
    (330 . <Entity name: 7ef60ee8>)
    (5 . "96")
    (100 . "AcDbEntity")
    (67 . 0)
    (410 . "Model")
    (8 . "0")
    (100 . "AcDbText")
    (10 17.3741 14.852 0.0)
    (40 . 0.2)
    (1 . "Default Value")
    (50 . 0.0)
    (41 . 1.0)
    (51 . 0.0)
    (7 . "Standard")
    (71 . 0)
    (72 . 0)
    (11 17.3741 14.952 0.0)
    (210 0.0 0.0 1.0)
    (100 . "AcDbAttribute")
    (2 . "ATTRIB_01")
    (70 . 0)
    (73 . 0)
    (74 . 2)
)

(
    (-1 . <Entity name: 7ef60ef8>)
    (0 . "ATTRIB")
    (330 . <Entity name: 7ef60ee8>)
    (5 . "97")
    (100 . "AcDbEntity")
    (67 . 0)
    (410 . "Model")
    (8 . "0")
    (100 . "AcDbText")
    (10 17.3741 13.7294 0.0)
    (40 . 0.2)
    (1 . "Default Value")
    (50 . 0.0)
    (41 . 1.0)
    (51 . 0.0)
    (7 . "Standard")
    (71 . 0)
    (72 . 0)
    (11 17.3741 13.8294 0.0)
    (210 0.0 0.0 1.0)
    (100 . "AcDbAttribute")
    (2 . "ATTRIB_02")
    (70 . 0)
    (73 . 0)
    (74 . 2)
)

(
    (-1 . <Entity name: 7ef60f00>)
    (0 . "ATTRIB")
    (330 . <Entity name: 7ef60ee8>)
    (5 . "98")
    (100 . "AcDbEntity")
    (67 . 0)
    (410 . "Model")
    (8 . "0")
    (100 . "AcDbText")
    (10 17.3741 12.5506 0.0)
    (40 . 0.2)
    (1 . "Default Value")
    (50 . 0.0)
    (41 . 1.0)
    (51 . 0.0)
    (7 . "Standard")
    (71 . 0)
    (72 . 0)
    (11 17.3741 12.6506 0.0)
    (210 0.0 0.0 1.0)
    (100 . "AcDbAttribute")
    (2 . "ATTRIB_03")
    (70 . 0)
    (73 . 0)
    (74 . 2)
)

(
    (-1 . <Entity name: 7ef60f08>)
    (0 . "SEQEND") ;; <== flags "end of the list"
    (330 . <Entity name: 7ef60ee8>)
    (5 . "99")
    (100 . "AcDbEntity")
    (67 . 0)
    (410 . "Model")
    (8 . "0")
    (-2 . <Entity name: 7ef60ee8>) ;; <== points to the block insert
)

Bla, bla, I just want the attributes!

Ok, ok. The following function, if passed the ename of a block with attributes (or heavyweight 2d/3d poly w/vertices) will return an ordered list of all the child entity names. From that point you can the perfrom entgets, entmods etc. to suit.

Code: [Select]
(defun Children ( ename / result )
    (if (assoc 66 (entget ename))
        (reverse
            (while
                (/= "SEQEND"
                    (cdr
                        (assoc 0
                            (entget
                                (setq ename
                                    (entnext ename)
                                )
                            )
                        )
                    )
                )
                (setq result (cons ename result))
            )
        )
    )
)

Example:

Code: [Select]
(children (car (entsel))

might return

(   <Entity name: 7ef60ef0>
    <Entity name: 7ef60ef8>
    <Entity name: 7ef60f00>
)

Let me know if you want more info.

Ackkk, it's way to early for a post like this.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Attributes and DXF information
« Reply #3 on: October 27, 2005, 07:58:25 AM »
Following on from Michaels Post ;

Once you have the Enames of the attributes look for the
dxf 1 and dxf 2 keys to go with the -1 key Ename

Something like ;

Code: [Select]
(mapcar '(lambda (ename / elist)
           (setq elist (entget ename))
           (mapcar '(lambda (key) (cdr (assoc key elist))) '(-1 2 1))
         )
        (Children (car (entsel)))
)
will return a list similar to ;
Code: [Select]
( (<Entity name: 7ef97af0> "LABEL" "SECTION")
  (<Entity name: 7ef97af8> "DET" "A")
  (<Entity name: 7ef97b00> "DWG" "232")
  (<Entity name: 7ef97b08> "N1" "1:10")
  (<Entity name: 7ef97b10> "N2" "WALL JOINT")
  (<Entity name: 7ef97b18> "N3" "TYPICAL 17 PLACES")
)
« Last Edit: October 27, 2005, 08:20:16 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Attributes and DXF information
« Reply #4 on: October 27, 2005, 08:00:46 AM »
Are you interested in a relatively transparent ActiveX solution .. for both extraction and modification ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Attributes and DXF information
« Reply #5 on: October 27, 2005, 08:11:00 AM »
There are many ways to skin the retrieval and modification of attributes Hudster, maybe you could indicate in more detail what you want to do.
« Last Edit: October 27, 2005, 08:14:40 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Attributes and DXF information
« Reply #6 on: October 27, 2005, 08:15:55 AM »
Good stuff guys! Thanks for sharing.

Scary thought, how many lines of code are contained within theswamps DB?

... now back to the topic at hand
TheSwamp.org  (serving the CAD community since 2003)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Attributes and DXF information
« Reply #7 on: October 27, 2005, 08:19:01 AM »
I imagine a search on 'attribute' would generate a few days reading :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hudster

  • Gator
  • Posts: 2848
Re: Attributes and DXF information
« Reply #8 on: October 27, 2005, 11:43:25 AM »
There are many ways to skin the retrieval and modification of attributes Hudster, maybe you could indicate in more detail what you want to do.

What i'm looking to do is find a way to extract the contents of the drawing title blocks in a folder to a file, then manipulate the file and have the attributes change to suit.
As you can no doubt work out, i'm having great difficulty.  I'm trying to learn about each stage before I even consider trying to write a program to do this.

I have set up all my title blocks so the attribute tags are the same throughout, but didn't know how to access via lisp.

Has anyone set up or is in the process of setting up a program to manipulate attribute data for multiple drawings from an external file?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

deegeecees

  • Guest
Re: Attributes and DXF information
« Reply #9 on: October 27, 2005, 12:01:48 PM »
Here is an example of what I do for TB info to a database and back (bi-directional functionality, but thats a whol nuther cat to skin).

Code: [Select]
(defun tb-att ()
(SETQ isatt1 (SSGET "X" '((2 . "tb-att"))))
(IF isatt1
(PROGN
(setq qtyisatt (sslength isatt1))
(if (= 1 qtyisatt)

(progn
(SETQ isatt2 (SSNAME isatt1 0))               ;
(SETQ dwg_no1 (ENTNEXT isatt2))          ; I like to keep track of each variant
(SETQ dwg_no2 (ENTGET dwg_no1))       ;
(SETQ dwg_no3
(WHILE (/= "ATTRIB"(CDR (ASSOC 0 dwg_no2)))
                                                        (WHILE (/= "DWG-NO." (CDR (ASSOC 2 dwg_no2)))
                                                                        (SETQ dwg_no1 (ENTNEXT dwg_no1))
(SETQ dwg_no2 (ENTGET dwg_no1))

)
)
)
(SETQ isatt2-3 (CDR (ASSOC 1 dwg_no2))) ;<-----------------Attribute value to input to database
)
)
)
)
)

So, isatt2-3 contains the value I want. Clear as mud?
« Last Edit: October 27, 2005, 12:06:16 PM by deegeecees »