Re: Get values from xdata
Hi,
Try this:
Code:
(foreach x (cdr thexdata) (if (= (car x) 1000) (setq lst (cons x lst))))
Re: Get values from xdata
Using (foreach x (cdr thexdata) (if (= (car x) 1000) (setq lst (cons x lst))))
I got this:
((1000 . "#TP=7") (1000 . "N=325") (1000 . "#HG=211.000") (1000 . "#TE=20181209.1429") . "")
or for other point
((1000 . "#TP=5") (1000 . "#TE=20181210.0029") (1000 . "N=124") (1000 . "SGN=tree") . "")
How to get variables TP, TE, N, SGN, HG and their values?
Re: Get values from xdata
Hi,
I don't have any example drawing of your Xdata so please try the following and upload a sample drawing to check the objects' data before posting codes and to save time.
Code:
(foreach x (cdr thexdata)
(if (and (= (car x) 1000)
(setq p (vl-string-search "=" (setq v (cdr x))))
(setq s (vl-string-left-trim "#" (substr v 1 p)))
)
(setq l (cons s l))
)
)
If that works as expected then just use the reverse function to reverse the order of the return strings.
Re: Get values from xdata
Not sure about this was trying to find another example may be usefull.
Code:
(defun c:test ( / ent vals x codes datas)
(setq ent (entget (car (entsel "select an object"))))
(vla-GetXData (vlax-ename->vla-object (cdr (assoc -1 ent))) "" 'codes 'datas)
(if (/= datas nil)
(progn
(setq vals (vlax-safearray->list datas))
(repeat (setq x (length vals))
(princ (strcat "\n" (setq val (vlax-variant-value (nth (setq x (- x 1)) vals)))))
)
)
(alert "Please pick again object has no xdata")
)
)
Re: Get values from xdata
A start with this?
Code:
((lambda ( / js n obj elist xd_list)
(setq js (ssget '((-3 ("*")))))
(cond
(js
(repeat (setq n (sslength js))
(setq
obj (ssname js (setq n (1- n)))
elist (entget obj (list "*"))
xd_list (cdr (assoc -3 elist))
)
(foreach el xd_list
(print (car el))
(mapcar 'print (mapcar 'cdr (cdr el)))
(print)
)
)
)
)
(prin1)
))
Re: Get values from xdata
All three codes are great, I got what I want, so thanks to Bruno.Valsecchi, Tharwat and BIG-AL.
In Tharwat's code I have added:
Code:
(setq val (substr v (+ 2 p) 15))
(cond
((= s "N")
(setq N val))
((= s "TP")
(setq TP val))
((= s "HG")
(setq HG val))
((= s "SGN")
(setq SGN val))
((= s "TE")
(setq TE val))
(t nill)
); cond
to get values. Probably this is dirty coding but it works for me.
Next I would like to ask you friends is how to pass variable to xdata?
For example:
(setq PtNo (getstring "\nPoint indicator: "))
(setq PtType (getint "\nPoint type: "))
(setq PtHgh (getreal "\nPoint height: "))
If I use:
(command "POINT" (setq NPt (getpoint "\nPoint coordinates: ")))
(setq lastent (entget (entlast)))
(regapp "MY_APP")
(setq N (cons 1000 PtNo)
TP (cons 1000 PtType)
HG (cons 1000 PtHgh))
how to add N, TP and HG to entity lastent as extended data to be like
(-3 ("MY_APP" (1002 . "{") (1000 . "#HG=311.7700") (1000 . "N=147") (1000 . "#TP=4") (1002 . "}")))
Thanks again, best wishes
Re: Get values from xdata
Hi,
You can append the xdata to a certain object as follows based on your posted example;
Code:
(and (/= "" (setq PtNo (getstring "\nPoint indicator: ")))
(setq PtType (getint "\nPoint type: "))
(setq PtHgh (getreal "\nPoint height: "))
(setq NPt (getpoint "\nPoint coordinates: "))
(or (tblsearch "APPID" "MY_APP")
(regapp "MY_APP")
)
(setq obj (entmakex (list '(0 . "POINT") (cons 10 NPt))))
(setq zin (getvar 'DIMZIN))
(setvar 'DIMZIN 0)
(setq PtHgh (rtos PtHgh 2 4))
(setvar 'DIMZIN zin)
(entmod
(append
(entget obj)
(list
(list -3
(list "MY_APP"
'(1002 . "{")
(cons 1000 (strcat "#HG=" PtHgh))
(cons 1000 (strcat "N=" PtNo))
(cons 1000 (strcat "#TP=" (itoa PtType)))
'(1002 . "}")
)
)
)
)
)
)
Re: Get values from xdata
That is all I need for now, I can continue now on. Thank you very much Tharwat you have made my life easier. Thanks to Bruno and BIG-AL too.
Re: Get values from xdata
Quote:
Originally Posted by
BaneBax
That is all I need for now, I can continue now on. Thank you very much Tharwat you have made my life easier. Thanks to Bruno and BIG-AL too.
You're welcome anytime. ;)