Jump to content

Recommended Posts

Posted

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

Posted (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 by Lee Mac
  • Like 1
Posted (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 by Lee Mac
  • Like 4
Posted

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

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

 

Posted (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 :thumbsup: - I have updated my earlier post.

Edited by Lee Mac
  • 1 year later...
Posted

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

Posted

Please explain  more if you can read the XDATA then what is problem making a list ?

Posted
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 '("*"))))
)

 

Posted
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!

 

Posted

I'm not sure I understand what you're after?

Posted (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 by marko_ribar
  • Like 1
Posted
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

Posted (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 by marko_ribar
  • Like 1
  • 1 month later...
Posted

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?

Posted

Sorry, I solved it. However, I noticed, when assigning xdata to the object, it limits the amount of Xdata it must.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...