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

Retrieving xdat from an entity

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
632 Views, 9 Replies

Retrieving xdat from an entity

Hey Gang

 

How can i build a selection set of all circles  and then retrieve the xdata attached to them?  Thanks.

 

Southie

9 REPLIES 9
Message 2 of 10
dbroad
in reply to: Anonymous

These sequences should give you some hints:

(regapp "myapp")

;Draw a test circle

(setq e (entlast));;Select circle

(entmod (list (cons -1 e) '(-3 ("myapp" (1000 . "this is xdata"))))) ;;add xdata to circle

(cdr (assoc -3 (entget e '("myapp")))) ;;get xdata from circle

(ssget '(0 . "circle"));;filtered selection set for circles.



(setq ss (ssget '((0 . "circle") (-3 ("myapp")))));;To filter for circles managed by "myapp".

 

 

Architect, Registered NC, VA, SC, & GA.
Message 3 of 10
Anonymous
in reply to: dbroad

Thanks for the quick response.  There use to be a Doug Broad who was a guru around here a while back.

 

Here is my attempt

 

(setq ss (ssget "x" '((0 . "circle") (-3 ("circ")))));;

(setq index 0)
(repeat (sslength ss)
(setq ent1 (entget (ssname ss index))
      e (cdr (assoc -1 ent1))
      xent (cdr (assoc -3 (entget e '("circ")))))
(setq index (+ index 1))

);repeat

 

xent = (("CIRC" (1002 . "{") (1000 . "qty 4") (1002 . "}"))) how do i assign   "qty 4"  to a variable. thanks.

Message 4 of 10
dbroad
in reply to: Anonymous

That's me.  

 

There are ways to get the data but the most productive process is to play with the list functions: car, cdr, their composites: caar cadr cdar cddr, etc.  and assoc.  The person who wrot the app that stores the xdata is responsible for the ordering of the information in the xdata and should know how to extract an individual object.  Some examples for your particular case using X as the variable name are:

_$(setq x '(("CIRC" (1002 . "{") (1000 . "qty 4") (1002 . "}"))))

_$ (car x)
("CIRC" (1002 . "{") (1000 . "qty 4") (1002 . "}"))

_$ (caar x)
"CIRC"

_$ (cdr(car x))
((1002 . "{") (1000 . "qty 4") (1002 . "}"))

_$ (cdr(cdr(car x)))
((1000 . "qty 4") (1002 . "}"))

_$ (cdr(assoc 1000 (cdar x)))
"qty 4"

_$ (nth 1 (cdr(car x)) )
(1000 . "qty 4")

_$ (cdr(nth 1 (cdr(car x))))
"qty 4"

 

 

Architect, Registered NC, VA, SC, & GA.
Message 5 of 10
Anonymous
in reply to: Anonymous

Excellent! Thank you dbroad for your time and help.

Message 6 of 10
Anonymous
in reply to: Anonymous

Mr. dbroad if you get a chance

 

stumped on this.  With e being a valid  entityname the following works

 

(entmod (list (cons -1 e) '(-3 ("idnumqty" (1000 . "3")))))

 

however,

 

(setq xqty "3")

(entmod (list (cons -1 e) '(-3 ("idnumqty" (1000 . xqty)))))

does not work & get this error ; error: bad DXF group: (-3 ("idnumqty" (1000 . XQTY)))

Message 7 of 10
pbejse
in reply to: Anonymous


@Anonymous wrote:

Mr. dbroad if you get a chance

 

stumped on this.  With e being a valid  entityname the following works

 

(entmod (list (cons -1 e) '(-3 ("idnumqty" (1000 . "3")))))

 

however,

 

(setq xqty "3")

(entmod (list (cons -1 e) '(-3 ("idnumqty" (1000 . xqty)))))

does not work & get this error ; error: bad DXF group: (-3 ("idnumqty" (1000 . XQTY)))


with ' (quote) the line will be treated on its face value

 

(entmod (list (cons -1 e)  (list -3 (list "idnumqty" (cons 1000 xqty)))))

 

 

Message 8 of 10
Anonymous
in reply to: Anonymous

Thanks dbroad & pb for all the help and sharing of your knowledge.

 

Southie

Message 9 of 10
dbroad
in reply to: Anonymous

You're welcome. Glad to help.

Architect, Registered NC, VA, SC, & GA.
Message 10 of 10
pbejse
in reply to: Anonymous


@Anonymous wrote:

Thanks dbroad & pb for all the help and sharing of your knowledge.

 

Southie


Good for you.

 

Cheers

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report