Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

xdata read

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Anonymous
5133 Views, 12 Replies

xdata read

Hello, do anybody have lisp code to read xdata information?

12 REPLIES 12
Message 2 of 13
Lee_Mac
in reply to: Anonymous

XDLIST command (Express Tools)

 

Entity List program.

 

Basic method:

(defun c:xdread ( / en xd )
    (if (setq en (car (entsel "\nSelect entity to read xdata:")))
        (if (setq xd (cdr (assoc -3 (entget en '("*")))))
            (foreach a xd
                (foreach x a (print x))
            )
            (princ "\nEntity has no xdata.")
        )
    )
    (princ)
)

 

Lee

Message 3 of 13
Anonymous
in reply to: Lee_Mac

thanks, but if I want see some lines info in one table?

Message 4 of 13
hgasty1001
in reply to: Anonymous

Hi,

 

Xdata organization is up to the programmer, so the code Lee posted it's almost the best you can obtain without a sample.

 

Gaston Nunez

Message 5 of 13
Anonymous
in reply to: Anonymous

but if I need see more than 1 line imformation in one table?

Message 6 of 13
Lee_Mac
in reply to: Anonymous


@Anonymous wrote:

but if I need see more than 1 line imformation in one table?


Sorry, I don't understand your question - what table are you referring to?

Are you perhaps referring to viewing data for only one App ID?

Message 7 of 13
Anonymous
in reply to: Anonymous

for example I have any lines, such as 100 lines, in every line, I write information with xdata, such as line is street name,

then I want have in one list whole 100 lines (streets) names

Message 8 of 13
Lee_Mac
in reply to: Anonymous

One would need to know the structure of the xdata (i.e. App ID / DXF Group Codes) to be able to confidently retrieve the desired item.

 

I assume you are using DXF group 1000 to store your street name data?

What Application ID are you using?

Message 9 of 13
Anonymous
in reply to: Anonymous

I don't know, that I do it well, but I try write "xdata" select line, and write information, and do it in every line,

 

then I need have whole lines information in one list

Message 10 of 13
Lee_Mac
in reply to: Anonymous

What is returned at the command-line if you select one of the lines using my program from this post?

Message 11 of 13
Anonymous
in reply to: Anonymous

maybe another question, what you think,

 

how is the best way to store information of lines/polylines/circles... (text and numbers), and at the end get a one list of whole information about that lines

 

such as, line is street, and information is street's name, length, class...

Message 12 of 13
mid-awe
in reply to: Anonymous

I'm curious to hear this answer too.
For me I've been using a process of setting up specific dictionaries pertaining to everything (almost) that I do in the drawing. I'm then able to collect that data into massively nested assoc-lists and again store those lists into dictionary references. I can then call for a report and print the list to the textscr when I need. Since I've found this is limiting and in some cases requires a lot of code. I'm perusing a route of storing to XML (external data storage).
Message 13 of 13
Lee_Mac
in reply to: Anonymous


@Anonymous wrote:

how is the best way to store information of lines/polylines/circles... (text and numbers), and at the end get a one list of whole information about that lines such as, line is street, and information is street's name, length, class...


For xdata, the DXF groups that are to be used for each item of data will depend on both the data type of the data (e.g. string / integer / double etc.) and also what the data represents (e.g. is the string an arbitrary string, or is it an entity handle? Similar questions should also be asked for points and doubles, since, depending on the DXF group used to store these items, the data will be automatically updated when the parent entity is modified). Here is a complete reference for all available xdata DXF groups - take care to understand the subtle differences between the DXF groups, especially the point groups (1010 - 1033).

 

For your example, since the street name will be an arbitrary string not connected to the entity, I would suggest DXF group 1000 for this item, whereas, for the length (assuming this corresponds to the length of the line itself), I would suggest using DXF group 1041, since the value of this 'distance' group will be scaled with the parent entity, removing the need for Reactors to update the xdata.

 

As for 'class' (and potentially other items of data), you would need to assess each item individually to decide which DXF group is most suitable, depending on the data type of the data and how the data should behave following modification of the parent entity.

 

Where the xdata structure is concerned, whether or not you will have more than one set of items for an object, to allow for future expansion amongst other things, I would recommend enclosing the items for each set of data within control strings (DXF group 1002) - I outline several reasons for this practice in my post here.

 

Here is a quick example for you to consider:

 

(defun c:test ( / app ent enx str )
    (setq app "MyTestApp"     ;; Example App ID
          str "Sesame Street" ;; Example street name
    )
    (regapp app)
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect a line to add xdata <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent) nil)
                (   (/= "LINE" (cdr (assoc 0 (entget ent))))
                    (princ "\nSelected object is not a line.")
                )
                (   (assoc -3 (setq enx (entget ent (list app))))
                    (princ "\nSelected line already has xdata.")
                )
                (   (entmod
                        (append enx
                            (list
                                (list -3
                                    (list app
                                        '(1002 . "{")
                                         (cons 1000 str)
                                         (cons 1041
                                             (distance
                                                 (cdr (assoc 10 enx))
                                                 (cdr (assoc 11 enx))
                                             )
                                         )
                                        '(1002 . "}")
                                    )
                                )
                            )
                        )
                    )
                    (princ "\nxData added.")
                )
                (   (princ "\nxData could not be added - line on locked layer?"))
            )
        )
    )
    (princ)
)

 

I hope this is clear!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost