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

Help with selection and loop

7 REPLIES 7
Reply
Message 1 of 8
mid-awe
299 Views, 7 Replies

Help with selection and loop

Hey all, I am working on a simple piece of code that will place a leader at the insertion point of every block with a specified name. Hears the good part then I want to select each of the added leaders and use the QLATTACH to connect the leaders to a specified string in the drawing. below is the code that I have so far, and what it doesn't do is select all of the newly added leaders only the first one. Please help. Thanks in advance.
[code] (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 blockname)))
n (1- (sslength ss))
)
(while (>= n 0)
(setq blockname (ssname ss n)
n (1- n)
inspt (cdr (assoc 10 (entget blockname)))
)
(command "._LEADER" inspt "@12<0" "" "" "N")
(setq ldrs (entlast))
)
(COMMAND "QLATTACH" ldrs PAUSE)[/code]
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: mid-awe

Look at the help for (ssadd) to see how this works:
[code]
(setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 blockname)))
n (1- (sslength ss))
ldrs (ssadd)
)
(while (>= n 0)
(setq blockname (ssname ss n)
n (1- n)
inspt (cdr (assoc 10 (entget blockname)))
)
(command "._LEADER" inspt "@12<0" "" "" "N")
(ssadd (entlast) ldrs)
)
(COMMAND "QLATTACH" ldrs PAUSE)
[/code]

wrote in message news:4926902@discussion.autodesk.com...
Hey all, I am working on a simple piece of code that will place a leader at
the insertion point of every block with a specified name. Hears the good
part then I want to select each of the added leaders and use the QLATTACH to
connect the leaders to a specified string in the drawing. below is the code
that I have so far, and what it doesn't do is select all of the newly added
leaders only the first one. Please help. Thanks in advance.
Message 3 of 8
Anonymous
in reply to: mid-awe

or - to be geeky tweaky...

code]
(setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 blockname)))
n (sslength ss)
ldrs (ssadd)
)
(repeat n
(setq n (1- n)
blockname (ssname ss n)
inspt (cdr (assoc 10 (entget blockname)))
)
(command "._LEADER" inspt "@12<0" "" "" "N")
(ssadd (entlast) ldrs)
)
(COMMAND "QLATTACH" ldrs PAUSE)
[/code]


--
Princess Jamie,

Life shrinks or expands in proportion to one's courage.
- Anais Nin
Message 4 of 8
mid-awe
in reply to: mid-awe

I'm not sure of the problem. I've just spent the last half hour studying both versions of this code and the developer documentation set on ssadd but I do not see why this will not attach all of the leaders to the text. I did add all of the variables to the (defun addleader (/ blocknamess n ldrs inspt)) It still only connects the first leader to the text.

I tested QLATTACH and noticed that it only allows one leader to be selected and then the text. How can I do this will I have to repeat the QLATTACH command for the unspecified number of times. Can I use foreach or ...?

Thanks for you help
Message 5 of 8
Anonymous
in reply to: mid-awe

Well, I obviously didn't test the code ;-/
I don't think I've ever used the QLATTACH command so I did not realize it
was a 'one at a time' type of command.

So you could either run the QLATTACH immediately after creating each leader,
Or, still using the code that creates the ldrs SS, do a (while) or (repeat)
with that SS to invoke the QLATTACH on each leader,
Or, you could look into using ActiveX to set the Annotation property of the
leader object.

wrote in message news:4927463@discussion.autodesk.com...
I'm not sure of the problem. I've just spent the last half hour studying
both versions of this code and the developer documentation set on ssadd but
I do not see why this will not attach all of the leaders to the text. I did
add all of the variables to the (defun addleader (/ blocknamess n ldrs
inspt)) It still only connects the first leader to the text.

I tested QLATTACH and noticed that it only allows one leader to be selected
and then the text. How can I do this will I have to repeat the QLATTACH
command for the unspecified number of times. Can I use foreach or ...?

Thanks for you help
Message 6 of 8
mid-awe
in reply to: mid-awe

Thanks, I'll give your suggestions a try. I'm still new enough at this that I was proud of my self for my original code. I'll learn a lot if I figure this one out.

Thanks again to everyone who helped.
Message 7 of 8
Anonymous
in reply to: mid-awe

(setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 blockname)))
n (sslength ss)
ldrs (ssadd)
)
(repeat n
(setq n (1- n)
blockname (ssname ss n)
inspt (cdr (assoc 10 (entget blockname)))
)
(command ".LEADER" inspt "@12<0" "" "" "N")
(command ".qlattach" (entlast) blockname)
)
[/code]

like this? I assume attreq has to be set properly...
--
Princess Jamie


wrote in message news:4927677@discussion.autodesk.com...
Thanks, I'll give your suggestions a try. I'm still new enough at this that
I was proud of my self for my original code. I'll learn a lot if I figure
this one out.

Thanks again to everyone who helped.
Message 8 of 8
mid-awe
in reply to: mid-awe

Sweet! That works great. Thank you so much. Princess Jamie 🙂

This is what I finished with.
[code](defun mldr_attch (STRING blockname / TXT ss n ldrs inspt)
(command "_.mtext" PAUSE "J" "MC" "W" "0" STRING "" "")
(SETQ TXT (ENTLAST))
(setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 blockname)))
n (sslength ss)
ldrs (ssadd)
)
(repeat n
(setq n (1- n)
blockname (ssname ss n)
inspt (cdr (assoc 10 (entget blockname)))
)
(command ".LEADER" inspt "@12<0" "" "" "N")
(command ".qlattach" (entlast) TXT)
)
)[/code]

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report