PDA

View Full Version : Copy Blocks



ImaJayhawk
21st Jan 2004, 07:59 pm
I'm trying to write a simple routine that copies all blocks of a entered name or selected. I'm getting an Invalid Selection error when I enter in the name, and when I select I'm getting a never ending loop. Thanks.

(defun C:bs ( / blocker continue selecty selecter selecterset)
(setvar "cmdecho" 0)
(setq continue T)
(if (= (strcase (getstring "\nDo you want to enter block name? y/<n>")) "Y")
(progn
(setq blocker (getstring "\nEnter Block Name: "))

(While continue
(progn
(setq selecty (ssget "X" (list (cons 0 "Insert") (cons 2 blocker))))
(command "_copybase" pause selecty)
)
)
)
(While continue
(if (setq enty (car (entsel "\nSelect Block: ")))
(progn
(setq e (entget enty))
(setq selecter (cdr (assoc 2 e)))
(setq selecterset (ssget "X" (list (cons 0 "Insert") (cons 2 selecter))))
(command "_copybase" pause selecterset)
(setq continue F)
) (progn (princ "Please select a block") (setq continue T))

)))
(Setvar "cmdecho" 1)
(princ)
)

fuccaro
22nd Jan 2004, 10:15 am
ImaJayhawk
Your error:
....
(setq continue T)
...
(while continue
...
(setq continue F)
)
This is an endless loop. The opposite of TRUE (T) is NIL. F is not NIL, so the test (while continue...) will return T even if continue is set to F.
Here is my attempt to solve your problem. But (again) I think that is not safe to accept the block name to be typed by the user. Not without a verification!


; Blocks to Clippboard
; copy all occurences of a block to the clipboard
; mfuccaro@hotmail.com
; January 2004
&#40;defun c&#58;b2c&#40; / answer name blocks&#41;
&#40;setvar "cmdecho" 0&#41;
&#40;initget "N"&#41;
&#40;setq answer &#40;entsel "\nselect block\\enter &#91;N&#93;ame "&#41;&#41;
&#40;setq name &#40;if &#40;listp answer&#41;
&#40;cdr &#40;assoc 2 &#40;entget &#40;car answer&#41;&#41;&#41;&#41;
&#40;getstring "\nenter block name "&#41;
&#41;
blocks &#40;ssget "X" &#40;list &#40;cons 0 "insert"&#41; &#40;cons 2 name&#41;&#41;&#41;&#41;
&#40;princ "\nbase point "&#41;
&#40;command "_copybase" pause blocks ""&#41;
&#40;princ "\nOK"&#41;
&#40;princ&#41;
&#41;

David Bethel
22nd Jan 2004, 03:47 pm
(ssget) accepts wildcards as well

So maybe:

(while (or (not bn)
(not (or (snvalid bn)
(wcmatch bn "*[#@`,.*?~]*"))))
(setq bn (getstring "\nBlock Name <Pattern>: ")))

;And then

(and
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 bn))))
(command ........)
)


or:

(setq i (sslength ss))
(while (not (minusp (setq i (1- i))))
(setq en (ssname ss i)
ed (entget en))))

For picks:

(while (not ss)
(setq ss (ssget (list (cons 0 "INSERT"))))
(command .....)
)

ImaJayhawk
26th Jan 2004, 08:15 pm
Thanks for the help!