Results 1 to 10 of 10

Thread: Get values from xdata

  1. #1
    Member
    Join Date
    2018-12
    Posts
    4
    Login to Give a bone
    0

    Default Get values from xdata

    Hello everybody

    Using
    (setq elist (entget (car (entsel)) '("MY_APP")))
    (setq exlist (assoc -3 elist))
    (setq thexdata (car (cdr exlist)))

    I get (depending on which xdata my point has added)
    ("MY_APP" (1002 . "{") (1000 . "#TE=20180602.1516") (1000 . "#HG=14.000") (1000 . "N=123") (1000 . "#TP=5") (1002 . "}"))
    or
    ("MY_APP" (1002 . "{") (1000 . "N=124") (1002 . "}"))
    or
    ("MY_APP" (1002 . "{") (1000 . "#HG=323.2100") (1002 . "}"))
    or
    ("MY_APP" (1002 . "{") (1000 . "SGN=tree") (1000 . "#TE=20180602.1517") (1000 . "#HG=14.000") (1000 . "N=123")

    I need to get value of each xdata in given list and add it to new variable so I can use it in further programming. As you can see the order of xdata is not always the same, so I can't use for example (setq TE (cdr (nth 1 thexdata))) and so on.
    How to get those values "tree", 14.000, 123... depending on existing specific xdata?

  2. #2
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    865
    Login to Give a bone
    0

    Default Re: Get values from xdata

    Hi,
    Try this:
    Code:
    (foreach x (cdr thexdata) (if (= (car x) 1000) (setq lst (cons x lst))))

  3. #3
    Member
    Join Date
    2018-12
    Posts
    4
    Login to Give a bone
    0

    Default 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?

  4. #4
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    865
    Login to Give a bone
    0

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

  5. #5
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    310
    Login to Give a bone
    0

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

  6. #6
    100 Club
    Join Date
    2002-08
    Posts
    178
    Login to Give a bone
    0

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

  7. #7
    Member
    Join Date
    2018-12
    Posts
    4
    Login to Give a bone
    0

    Default 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

  8. #8
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    865
    Login to Give a bone
    0

    Default 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 . "}")
                     )
               )
             )
           )
         )
    )

  9. #9
    Member
    Join Date
    2018-12
    Posts
    4
    Login to Give a bone
    0

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

  10. #10
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    865
    Login to Give a bone
    0

    Default Re: Get values from xdata

    Quote Originally Posted by BaneBax View Post
    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.

Similar Threads

  1. Replies: 6
    Last Post: 2015-08-31, 04:05 PM
  2. Replies: 4
    Last Post: 2008-11-13, 05:36 AM
  3. xdata
    By san_k4 in forum VBA/COM Interop
    Replies: 3
    Last Post: 2005-09-19, 10:29 PM
  4. xdata
    By fletch97 in forum AutoLISP
    Replies: 1
    Last Post: 2005-08-31, 05:52 PM
  5. Level Differences (Execution project Z values minus observed Z values)
    By ped.rib in forum AutoCAD Civil 3D - General
    Replies: 2
    Last Post: 2005-06-16, 10:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •