Hello, do anybody have lisp code to read xdata information?
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Solved by hgasty1001. Go to Solution.
Solved by Lee_Mac. Go to Solution.
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
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
@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?
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
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?
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
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...
@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!