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

Multiple User Inputs to Delete Hatch/Text

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
jhoageN5XUG
212 Views, 3 Replies

Multiple User Inputs to Delete Hatch/Text

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)
))

 

3 REPLIES 3
Message 2 of 4
ВeekeeCZ
in reply to: jhoageN5XUG

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)
))

 

Message 3 of 4
jhoageN5XUG
in reply to: jhoageN5XUG

Thanks, I realized last night that there was no need for the "and" statement.  Thank you for the explanations though.

Message 4 of 4
Sea-Haven
in reply to: jhoageN5XUG

I tackle this in a different way using a dcl with toggles. Tick on for delete. Then have 2 defuns that do the work.

SeaHaven_0-1668655608279.png

 

 

(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.

Post to forums  

Forma Design Contest


AutoCAD Beta