jbreard Posted November 25, 2019 Posted November 25, 2019 Hello everyone, I've used quite a lot of xdatas in my programms but 'im faced today with an issue I cannot find the answer to. I would like to attached to an object created by a first LISP programm a list. This list is not simple (it is nested) and varies in length function to the number of vertex of a lwpolyline. So it's not practical to play with the 1002 group code (I don't know if it's even possible). My list only contains integers and real numbers. Does anybody here knows of a simple way to attach a list to xdata ? If that is not feasable, I was wondering if there is a way to transform the list into string, to attach it to a 1000 group code, and then transform it back after retrieval by an other program. The list I want to attach looks like this ((0.52623 (1 2) (0 4)) (0.89652 (2 3) (2 1))...) Thank you, Jacques Quote
dlanorh Posted November 25, 2019 Posted November 25, 2019 Look at the (vl-princ-to-string) function. Quote
Lee Mac Posted November 25, 2019 Posted November 25, 2019 (edited) Perhaps consider a function such as the following: (defun LM:lst->xdata ( lst ) (if lst (append '((1002 . "{")) (apply 'append (mapcar (function (lambda ( x / k ) (cond ( (setq k (cdr (assoc (type x) '((str . 1000) (real . 1040))))) (list (cons k x)) ) ( (= 'int (type x)) (list (cons (if (< -32769 x 32768) 1070 1071) x)) ) ( (= 'list (type x)) (LM:lst->xdata x) ) ( (list (cons 1000 (vl-prin1-to-string x)))) ) ) ) lst ) ) '((1002 . "}")) ) ) ) Example: _$ (LM:lst->xdata '(1 2 3 4)) ((1002 . "{") (1070 . 1) (1070 . 2) (1070 . 3) (1070 . 4) (1002 . "}")) _$ (LM:lst->xdata '(1 (2 3) 4)) ((1002 . "{") (1070 . 1) (1002 . "{") (1070 . 2) (1070 . 3) (1002 . "}") (1070 . 4) (1002 . "}")) _$ (setq lst '((0.52623 (1 2) (0 4)) (0.89652 (2 3) (2 1)))) ( (0.52623 (1 2) (0 4)) (0.89652 (2 3) (2 1)) ) _$ (LM:lst->xdata lst) ( (1002 . "{") (1002 . "{") (1040 . 0.52623) (1002 . "{") (1070 . 1) (1070 . 2) (1002 . "}") (1002 . "{") (1070 . 0) (1070 . 4) (1002 . "}") (1002 . "}") (1002 . "{") (1040 . 0.89652) (1002 . "{") (1070 . 2) (1070 . 3) (1002 . "}") (1002 . "{") (1070 . 2) (1070 . 1) (1002 . "}") (1002 . "}") (1002 . "}") ) Edited November 25, 2019 by Lee Mac 1 Quote
Lee Mac Posted November 25, 2019 Posted November 25, 2019 (edited) The above could alternatively be written: (defun LM:data->xdata ( x ) (cond ( (= 'str (type x)) (list (cons (if (handent x) 1005 1000) x))) ( (= 'real (type x)) (list (cons 1040 x))) ( (= 'int (type x)) (list (cons (if (< -32769 x 32768) 1070 1071) x))) ( (= 'list (type x)) (append '((1002 . "{")) (apply 'append (mapcar 'LM:data->xdata x)) '((1002 . "}")))) ( (list (cons 1000 (vl-prin1-to-string x)))) ) ) Edited November 27, 2019 by Lee Mac 4 Quote
jbreard Posted November 26, 2019 Author Posted November 26, 2019 Thank you so much, I have tried the ( vl-princ-to-string ) function that works but I don't seem to find the reverse transformation. I wil find a bit more. Lee Mac, as usual, impressive coding. I will need a few more days to work around it though but I'l sure I will succeed ! Thanks again, Jacques Quote
ronjonp Posted November 27, 2019 Posted November 27, 2019 On 11/25/2019 at 3:14 PM, Lee Mac said: The above could alternatively be written: (defun LM:data->xdata ( x ) (cond ( (= 'str (type x)) (list (cons 1000 x))) ( (= 'real (type x)) (list (cons 1040 x))) ( (= 'int (type x)) (list (cons (if (< x 32768) 1070 1071) x))) ( (= 'list (type x)) (append '((1002 . "{")) (apply 'append (mapcar 'LM:data->xdata x)) '((1002 . "}")))) ( (list (cons 1000 (vl-prin1-to-string x)))) ) ) Nice as always Lee .. you could also look for handles and assign the 1005 group code too. ( (= 'str (type x)) (list (cons (if (handent x) 1005 1000) x))) Quote
Lee Mac Posted November 27, 2019 Posted November 27, 2019 (edited) 3 hours ago, ronjonp said: Nice as always Lee .. you could also look for handles and assign the 1005 group code too. ( (= 'str (type x)) (list (cons (if (handent x) 1005 1000) x))) Great suggestion @ronjonp - I have updated my earlier post. Edited November 27, 2019 by Lee Mac Quote
thanhduan2407 Posted June 28, 2021 Posted June 28, 2021 Somebody let me ask a question! Is there a way to read Xdata to get a List? Thank you very much P/s: Thanks Lee_Max for LM:data->xdata Quote
BIGAL Posted June 29, 2021 Posted June 29, 2021 Please explain more if you can read the XDATA then what is problem making a list ? Quote
ronjonp Posted June 29, 2021 Posted June 29, 2021 On 6/27/2021 at 6:44 PM, thanhduan2407 said: Somebody let me ask a question! Is there a way to read Xdata to get a List? Thank you very much P/s: Thanks Lee_Max for LM:data->xdata Try: (if (setq e (car (entsel))) (cdr (assoc -3 (entget e '("*")))) ) Quote
thanhduan2407 Posted June 29, 2021 Posted June 29, 2021 3 hours ago, ronjonp said: Try: (if (setq e (car (entsel))) (cdr (assoc -3 (entget e '("*")))) ) Thanks @ronjonpreply! I have a list: (setq lst (list "ThanhDuan" '(2 3 3.2) '((2 5 6.5) (4 5 8.14)) '("every" "Ok"))) => (LM:data->xdata lst) => ((1002 . "{") (1000 . "ThanhDuan") (1002 . "{") (1070 . 2) (1070 . 3) (1040 . 3.2) (1002 . "}") (1002 . "{") (1002 . "{") (1070 . 2) (1070 . 5) (1040 . 6.5) (1002 . "}") (1002 . "{") (1070 . 4) (1070 . 5) (1040 . 8.14) (1002 . "}") (1002 . "}") (1002 . "{") (1000 . "every") (1000 . "Ok") (1002 . "}") (1002 . "}") ) I want to lisp: Xdata (x) => lst Thanks for support! Quote
marko_ribar Posted June 29, 2021 Posted June 29, 2021 (edited) I understood it this way : (setq lst (list "ThanhDuan" '(2 3 3.2) '((2 5 6.5) (4 5 8.14)) '("every" "Ok"))) (defun LM:data->xdata ( x ) (cond ( (= 'str (type x)) (list (cons (if (handent x) 1005 1000) x)) ) ( (= 'real (type x)) (list (cons 1040 x)) ) ( (= 'int (type x)) (list (cons (if (< -32769 x 32768) 1070 1071) x)) ) ( (= 'list (type x)) (append '((1002 . "{")) (apply 'append (mapcar 'LM:data->xdata x)) '((1002 . "}"))) ) ( (list (cons 1000 (vl-prin1-to-string x))) ) ) ) (setq lstn (LM:data->xdata lst)) (setq lst (read (apply 'strcat (mapcar '(lambda ( x ) (cond ( (= x "{") "(" ) ( (= x "}") ")" ) ( t (cond ( (= 'str (type x)) (strcat "\"" x "\"") ) ( (= 'real (type x)) (strcat " " (rtos x) " ") ) ( (= 'int (type x)) (strcat " " (itoa x) " ") ) ( t (vl-prin1-to-string x) ) ) ))) (mapcar 'cdr lstn))))) Not sure, but I think OP is searching to convert list of Xdata syntax to normal original list... Edited July 4, 2021 by marko_ribar 1 Quote
thanhduan2407 Posted June 30, 2021 Posted June 30, 2021 3 hours ago, marko_ribar said: I understood it this way : (setq lst (list "ThanhDuan" '(2 3 3.2) '((2 5 6.5) (4 5 8.14)) '("every" "Ok"))) (defun LM:data->xdata ( x ) (cond ( (= 'str (type x)) (list (cons (if (handent x) 1005 1000) x)) ) ( (= 'real (type x)) (list (cons 1040 x)) ) ( (= 'int (type x)) (list (cons (if (< -32769 x 32768) 1070 1071) x)) ) ( (= 'list (type x)) (append '((1002 . "{")) (apply 'append (mapcar 'LM:data->xdata x)) '((1002 . "}"))) ) ( (list (cons 1000 (vl-prin1-to-string x))) ) ) ) (setq lstn (LM:data->xdata lst)) (setq lst (read (apply 'strcat (mapcar '(lambda ( x ) (cond ( (= x "{") "(" ) ( (= x "}") ")" ) ( t (cond ( (= 'str (type x)) (strcat "\"" x "\"") ) ( (= 'real (type x)) (strcat " " (rtos x) " ") ) ( (= 'int (type x)) (strcat " " (itoa x) " ") ) ) ))) (mapcar 'cdr lstn))))) Not sure, but I think OP is searching to convert list of Xdata syntax to normal original list... Wonderful! Exactly what I needed. Thank you so much Quote
marko_ribar Posted July 3, 2021 Posted July 3, 2021 (edited) Not sure, but hopefully someone may correct me if I am wrong... According to my research, I found that (LM:data->xdata) function should look something like this : (defun LM:data->xdata ( x ) (cond ( (= 'str (type x)) (list (cons (cond ( (handent x) 1005 ) ( (tblsearch "LAYER" x) 1003 ) ( t 1000 )) x)) ) ( (and (= 'list (type x)) (vl-every 'numberp x) (= (length x) 3)) (list (cons 1010 x)) ) ( (= 'real (type x)) (list (cons 1040 x)) ) ( (= 'int (type x)) (list (cons (if (< -32769 x 32768) 1070 1071) x)) ) ( (= 'list (type x)) (append '((1002 . "{")) (apply 'append (mapcar 'LM:data->xdata x)) '((1002 . "}"))) ) ) ) According to DXF manual, DXF codes 1010, 1011, 1012, 1013 should express X value of 3d point, 1020, 1021, 1022, 1023 Y value and 1030, 1031, 1032, 1033 Z value, but I tried to implement this on some entity and ACAD reported - bad DXF group -3... So I had to remove this and put complete 3d point into 1010... Now with this Lee's code, only DXF 1010 and 1040 are processed, but as you may find out like I said there are 1011, 1012, ... , 1040, 1041 and 1042, but I don't know how to use them - they express same type of data, but are related to different things (3d point, displacement, direction, position) (double-precision floating point, distance, scale factor)... Still I think that list that OP provided actually tells about point lists and not just simple numbers - they are lists of 3 consecutive numbers - that must be a point lists IMHO... My expression for (setq lst ... ) after (setq lstn (LM:data->xdata lst)) I hopefully changed to reflect different Lee's sub, but Lee's function was somewhat different - it was correct (you can assign xdata to entity), but can be treated differently... EDIT : You may find this topic interested also : https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/programs-for-xdata/m-p/10441156/highlight/true#M417070 Edited July 4, 2021 by marko_ribar 1 Quote
thanhduan2407 Posted August 13, 2021 Posted August 13, 2021 I tried with this list but it doesn't work (setq lst '("J6" (1002 . "{") (1000 . "J6") (1002 . "{") (1002 . "{") (1040 . 1.01) (1040 . 1.36) (1040 . 0.35) (1002 . "}") (1002 . "{") (1040 . 0.98 ) (1040 . 1.39) (1040 . 0.41) (1002 . "}") (1002 . "{") (1040 . 0.98) (1040 . 1.36 ) (1040 . 0.38) (1002 . "}") (1002 . "{") (1040 . 1.01) (1040 . 1.31) (1040 . 0.3) (1002 . "}") (1002 . "{") (1040 . 1.01) (1040 . 1.36) (1040 . 0.35 ) (1002 . "}") (1002 . "}") (1040 . 0.4475) (1040 . 100.0) (1040 . 44.75) (1002 . "}") ) ) Can anyone help me? Quote
thanhduan2407 Posted August 13, 2021 Posted August 13, 2021 Sorry, I solved it. However, I noticed, when assigning xdata to the object, it limits the amount of Xdata it must. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.