Xdata from ssget

This widget could not be displayed.

Xdata from ssget

Anonymous
Not applicable
Hi,
I would be very grateful if someone could take the time to try to help me.
I'm still a beginner in LISP...

I need to extract lots of Xdata from selectionsets and add them to leaders.
Example:
Selectionset ss1 ( for instance 3 polylines)
I need to extract the Xdata assigned to AAA1/AAA2/AAA3 and want to add these to a string.
The string of each polyline should be added to a new line of a leader, like such:
image001.png
This is what I have so far:
(setq ss1 (ssget '((0 . "LWPOLYLINE")
                                             (8 . "LAY1,LAY2,LAY3")
                                             (-3 ("AAA"))))) ;;selection set

(if (= "AAA1" (cdr (car e2)));;retrieve first Xdata
(progn
(if (or (wcmatch (cdr (cadr e2)) "8..")(wcmatch (cdr (cadr e2)) "8#."))
(setq T1 "_NO_AAA1")
(setq T1 (cdr (cadr e2)))
)
)
)

(if (= "AAA2" (cdr (car e2)));;retrieve second Xdata
(progn
(if (= (cdr (cadr e2)) "???")
(setq T2 "_NO_AAA2")
(setq T2 (cdr (cadr e2)))
);new
)
)
(if (= "AAA3" (cdr (car e2)));;retrieve third Xdata
(progn
(if (= (cdr (cadr e2)) "?")
(setq T3 "_NO_AAA3")
(setq T3 (cdr (cadr e2)))
)
)
)
(setq R1 (strcat T1 T2 T3));;make the string for the first polyline

(command "leader" pause pause "" "" "" R1 "");;make the leader
I probably need something to go from the SSget to the e2, but i'm drawing blanks...
Also I think I need to repeat this command for each polyline, but I haven't been able to figure out what is the correct way of handling this.
Any help is much appreciated!
Thanks in advance to those who reply ๐Ÿ™‚
0 Likes
Reply
Accepted solutions (1)
2,595 Views
10 Replies
Replies (10)

john.uhden
Mentor
Mentor

This comes to mind...

(setq ss1 (ssget '((0 . "LWPOLYLINE")
                                             (8 . "LAY1,LAY2,LAY3")
                                             (-3 ("AAA"))))) ;;selection set
(repeat (setq I (sslength ss1))
  (setq e (ssname ss1 (setq I (1- I)))
           e2 (entget e '("AAA"))
  )
  (setq X (cdr (car e2)))  ;; this doesn't look right
  (cond
    ((= X "AAA1") ;;retrieve first Xdata
        ;; do something
    )
    ((= X "AAA2")
        ;; do something else
    )
    ;; etc.
  )
)

John F. Uhden

Anonymous
Not applicable

 Hi John (and others),

Thanks for your reply.  The repeat mechanism is indeed what I needed.
Your post has already given me a better understanding, thanks.
For the rest, I'm still struggling to make it work.
I feel like I'm missing some key insights to 'glue' everything together in the code.
I will provide more info below.
This is the result of an XDLIST of a polyline. I've put all important refererences in red.

Registered Application Name: AAA
* Code 1000, ASCII string: VERSION
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string:
* Code 1002, Starting or ending brace: }
* Code 1000, ASCII string: A1
* Code 1002, Starting or ending brace: {
* Code 1002, Starting or ending brace: {
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: dwgname
* Code 1000, ASCII string: 120
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: A2
* Code 1000, ASCII string: 01AAA0
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: from
* Code 1002, Starting or ending brace: {
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: 120
-More-
* Code 1000, ASCII string: 01AAA0
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: to
* Code 1002, Starting or ending brace: {
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: 120
* Code 1000, ASCII string: 01AAA0
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: A3
* Code 1000, ASCII string: 027
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: A3
* Code 1002, Starting or ending brace: {
-More-
* Code 1000, ASCII string: 027
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: A4
* Code 1000, ASCII string:
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: A5
* Code 1000, ASCII string: 1999
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: AAA1
* Code 1000, ASCII string: 888
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: A6
* Code 1000, ASCII string:
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
-More-
* Code 1000, ASCII string: AAA2
* Code 1000, ASCII string: 444
* Code 1002, Starting or ending brace: }
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: AAA3
* Code 1000, ASCII string: 2
* Code 1002, Starting or ending brace: }

I would need to extract these 3 Xdata values from each polyline and put them together in a string. (example from XDLIST: "8884442")
Then I would need to combine these in a single leader, which holds the data from the entire selection set like this:

 

Capture.PNG

(this example has 4 polylines, each polyline's data should be on a new line)
But i'm unsure how I can build this string in an easy way.
How do I go from the 'cond' to such a string?
How do I tell (auto)lisp to add a โ€œ\nโ€ (new line) for each additional object in the selectionset that I will use in the leader?

If someone could please take the time to help me, it would be much appreciated ๐Ÿ™‚

0 Likes

doaiena
Collaborator
Collaborator

Are you adding the xdata yourself, or you are working with drawings that have that data already there and you just want to extract it? Also could you privide a drawing that contains those entities and the exact end result you are aiming for.

0 Likes

_gile
Mentor
Mentor
Accepted solution

Hi,

 

Here's a quick and dirty:

 

(defun c:xdatafromssget (/ str ss i data p1 p2)
  (and
    (setq str "")
    (setq ss (ssget '((0 . "LWPOLYLINE") (8 . "LAY1,LAY2,LAY3") (-3 ("AAA")))))
    (repeat (setq i (sslength ss))
      (if (setq data (cdadr (assoc -3 (entget (ssname ss (setq i (1- i))) '("AAA")))))
        (setq str (strcat
                    str
                    (cdadr (member '(1000 . "AAA1") data))
                    (cdadr (member '(1000 . "AAA2") data))
                    (cdadr (member '(1000 . "AAA3") data))
                    "\\P"
                  )
        )
      )
    )
    (setq p1 (getpoint "\nSpecify leader arrowhead location "))
    (setq p2 (getpoint p1 "\nSpecify leader landing location: "))
    (command "_mleader" p1 p2 str)
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

john.uhden
Mentor
Mentor

You always make things so simple and clear.

Just one thing... the (and ...) will return nil because of the (command) at the end.  Not that it really matters here.  I'm just being picky.  (vl-cmdf) solves the miniscule problem.

John F. Uhden

0 Likes

cadffm
Consultant
Consultant

T or nil, both are not pretty feedback for an AutoCAD command.. NOTHING or a senseful Text information is normal for an AutoCAD command  feedback.

So my choice in this case is (princ) at last.

Sebastian

0 Likes

_gile
Mentor
Mentor

@john.uhden & @cadffm, I said "quick and dirty"...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Anonymous
Not applicable
The code provided by _gile works perfectly.
Thanks for all the help, I've learned a lot from this.
0 Likes

edgar_torres
Participant
Participant

I'm looking for something similar to this but can't seem to figure it out. I'm trying to extract xdata "line number" from a cadworx drawing but not sure where to start. Seems like it would be as easy as modifying the lisp routine you provided but doubt it's that easy. Below is a screenshot of the XDLIST properties I'm needing. Thanks in advance.


 

 

Code 1002, Starting or ending brace.png

 

0 Likes

john.uhden
Mentor
Mentor

Your XDLIST shows ten (10) 1000 codes, which are easy to extract from the whole list, but you'll have to figure out some method of choosing the right one, maybe by using wcmatch with wildcards.

John F. Uhden

0 Likes