Visual LISP, AutoLISP and General Customization

Reply
Mentor
Posts: 291
Registered: ‎03-15-2007
Message 1 of 10 (167 Views)

Retrieving xdat from an entity

167 Views, 9 Replies
03-29-2012 10:15 AM

Hey Gang

 

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

 

Southie

*Expert Elite*
Posts: 1,377
Registered: ‎08-16-2007
Message 2 of 10 (161 Views)

Re: Retrieving xdat from an entity

03-29-2012 11:24 AM in reply to: southie

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".

 

 

Mentor
Posts: 291
Registered: ‎03-15-2007
Message 3 of 10 (158 Views)

Re: Retrieving xdat from an entity

03-29-2012 12:10 PM 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.

*Expert Elite*
Posts: 1,377
Registered: ‎08-16-2007
Message 4 of 10 (146 Views)

Re: Retrieving xdat from an entity

03-29-2012 12:41 PM in reply to: southie

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"

 

 

Mentor
Posts: 291
Registered: ‎03-15-2007
Message 5 of 10 (144 Views)

Re: Retrieving xdat from an entity

03-29-2012 12:56 PM in reply to: southie

Excellent! Thank you dbroad for your time and help.

Mentor
Posts: 291
Registered: ‎03-15-2007
Message 6 of 10 (131 Views)

Re: Retrieving xdat from an entity

03-29-2012 08:03 PM in reply to: southie

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)))

*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 7 of 10 (119 Views)

Re: Retrieving xdat from an entity

03-29-2012 10:48 PM in reply to: southie

southie 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)))))

 

 

Mentor
Posts: 291
Registered: ‎03-15-2007
Message 8 of 10 (106 Views)

Re: Retrieving xdat from an entity

03-30-2012 06:09 AM in reply to: southie

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

 

Southie

*Expert Elite*
Posts: 1,377
Registered: ‎08-16-2007
Message 9 of 10 (99 Views)

Re: Retrieving xdat from an entity

03-30-2012 06:40 AM in reply to: southie

You're welcome. Glad to help.

*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 10 of 10 (91 Views)

Re: Retrieving xdat from an entity

03-30-2012 07:48 AM in reply to: southie

southie wrote:

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

 

Southie


Good for you.

 

Cheers

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community