When I run this code, it only allows the user to input one "Yes" command. How do I go about stringing them together? (Very new to lisps)
(initget "Yes No")
(if
(and
(= (getkword "\nDelete hatches? [Yes/No] <No>: ") "Yes")
)
((if (setq s (ssget "_X" '((0 . "HATCH"))))
(repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))
)
(princ)
))
(initget "Yes No")
(if
(and
(= (getkword "\nDelete text? [Yes/No] <No>: ") "Yes")
)
((if (setq s (ssget "_X" '((0 . "TEXT"))))
(repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))
)
(princ)
))
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
The first version fixes your serial arrangement, the latter combines them into one prompt.
(defun c:DeleteHatchAndText ( / s i ) (if (and (not (initget "Yes No")) (= (getkword "\nDelete hatches? [Yes/No] <no>: ") "Yes") (setq s (ssget "_X" '((0 . "HATCH")))) ) (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))) (if (and (not (initget "Yes No")) (= (getkword "\nDelete text? [Yes/No] <no>: ") "Yes") (setq s (ssget "_X" '((0 . "TEXT")))) ) (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))) (princ) ) (defun c:DeleteHatchAndText2 ( / r s i) (if (and (not (initget "Hatch Text Both")) (setq r (getkword "\nDelete hatches or text? [Hatch/Text/Both] <none>: ")) (setq r (vl-string-subst "TEXT,HATCH" "BOTH" (strcase r))) (setq s (ssget "_X" (list (cons 0 r)))) ) (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))) (princ) )
Comments on your code.
(if (and ; no reason for AND if follows just one condition. (= (getkword "\nDelete hatches? [Yes/No] <no>: ") "Yes") ) ((if (setq s (ssget "_X" '((0 . "HATCH")))) ; (( double initial parent is usually wrong. ;; it has its place in COND function, but never with simple IF. (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i))))) ) (princ) ))
Thanks, I realized last night that there was no need for the "and" statement. Thank you for the explanations though.
I tackle this in a different way using a dcl with toggles. Tick on for delete. Then have 2 defuns that do the work.
(if (not AH:Toggs)(load "Multiple toggles.lsp"))
(setq ans (reverse (ah:toggs '("Delete " "Hatches " "Text "))))
(if (= (nth 0 ans)"1")(deletehatches))
(if (= (nth 1 ans)"1")(deletetext))
Can't find what you're looking for? Ask the community or share your knowledge.