I seem to be having troubles my (while looping. My issue is if I select nothing and I select anthing other than a hatch pattern and go back and select nothing again the loop stops. I kind of know why but I'm not having any luck getting it work. Any ideas?
(defun c:hhh ()
(setq ent (car (entsel "\nSelect a hatch whose properties will become current: ")))
(while
(= ent nil)
(princ "\nNothing was selected")
(setq ent (car (entsel "\nSelect a hatch whose properties will become current: ")))
)
(setq ent2 (entget ent))
(setq type (cdr (assoc 0 ent2)))
(while
(/= "HATCH" type)
(progn
(princ "\nHatch pattern was not selected")
(setq ent nil)
(setq ent (car (entsel "\nSelect a hatch whose properties will become current: ")))
(setq ent2 (entget ent))
(setq type (cdr (assoc 0 ent2)))
)
)
(setq hpn (cdr (assoc '2 ent2)))
(if (= hpn "SOLID")
(progn
(setvar "hpname" (cdr (assoc '2 ent2)))
(princ (strcat "\n" "Pattern = " (getvar "hpname") " is set to current."))
(princ)
)
)
(if (/= hpn "SOLID")
(progn
(setvar "hpang" (cdr (assoc '52 ent2)))
(setvar "hpname" (cdr (assoc '2 ent2)))
(setvar "hpscale" (cdr (assoc '41 ent2)))
(princ (strcat "\n" "Pattern = " (getvar "hpname") " Scale = " (rtos (getvar "hpscale") 2 2) " Angle = " (rtos (getvar "hpang") 2 2) " is set to current."))
(princ)
)
)
(princ)
)
@smaher12 wrote:I seem to be having troubles my (while looping. My issue is if I select nothing and I select anthing other than a hatch pattern and go back and select nothing again the loop stops. I kind of know why but I'm not having any luck getting it work. Any ideas?
....
Without digging too deeply into the possible reason(s) for that, I would suggest a somewhat different approach, which can, among other benefits, spare you both the need to spell out the same prompt twice and the double (while) loops:
(defun c:hhh (/ esel edata)
(while
(not
(and
(setq esel (entsel "\nSelect a hatch whose properties will become current: "))
(setq edata (entget (car esel)))
(= (cdr (assoc 0 edata)) "HATCH")
); and
); not
(prompt "\nNothing selected, or not a Hatch pattern.")
); while
(setq hpn (cdr (assoc 2 edata)))
... etc. ...
You don't need the apostrophes before the numbers in (assoc) [it may work with them, but they're expendable].
And you're setting the HPNAME System Variable to what's in your hpn variable in any case, so you could just omit that setting in the two subsequent cases, and instead follow the last line above with:
(setvar 'hpname hpn)