• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Mentor
    Posts: 289
    Registered: ‎03-15-2007

    Retrieving xdat from an entity

    143 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

    Please use plain text.
    *Expert Elite*
    Posts: 833
    Registered: ‎08-16-2007

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

     

     

    Please use plain text.
    Mentor
    Posts: 289
    Registered: ‎03-15-2007

    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.

    Please use plain text.
    *Expert Elite*
    Posts: 833
    Registered: ‎08-16-2007

    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"

     

     

    Please use plain text.
    Mentor
    Posts: 289
    Registered: ‎03-15-2007

    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.

    Please use plain text.
    Mentor
    Posts: 289
    Registered: ‎03-15-2007

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

    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

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

     

     

    Please use plain text.
    Mentor
    Posts: 289
    Registered: ‎03-15-2007

    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

    Please use plain text.
    *Expert Elite*
    Posts: 833
    Registered: ‎08-16-2007

    Re: Retrieving xdat from an entity

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

    You're welcome. Glad to help.

    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    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

    Please use plain text.