Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Xdata from ssget

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
2382 Views, 10 Replies

Xdata from ssget

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 🙂
Tags (2)
10 REPLIES 10
Message 2 of 11
john.uhden
in reply to: Anonymous

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

Message 3 of 11
Anonymous
in reply to: john.uhden

 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 🙂

Message 4 of 11
doaiena
in reply to: Anonymous

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.

Message 5 of 11
_gile
in reply to: Anonymous

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

Message 6 of 11
john.uhden
in reply to: _gile

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

Message 7 of 11
cadffm
in reply to: john.uhden

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

EESignature

Message 8 of 11
_gile
in reply to: cadffm

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



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 11
Anonymous
in reply to: _gile

The code provided by _gile works perfectly.
Thanks for all the help, I've learned a lot from this.
Message 10 of 11
edgar.torres
in reply to: _gile

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

 

Message 11 of 11
john.uhden
in reply to: edgar.torres

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta