Help with selection and loop

mid-awe
Collaborator
Collaborator

Help with selection and loop

mid-awe
Collaborator
Collaborator
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]
0 Likes
Reply
301 Views
7 Replies
Replies (7)

Anonymous
Not applicable
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.
0 Likes

Anonymous
Not applicable
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
0 Likes

mid-awe
Collaborator
Collaborator
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
0 Likes

Anonymous
Not applicable
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
0 Likes

mid-awe
Collaborator
Collaborator
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.
0 Likes

Anonymous
Not applicable
(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.
0 Likes

mid-awe
Collaborator
Collaborator
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]
0 Likes