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

Troubles with nothing selected (while loop

2 REPLIES 2
Reply
Message 1 of 3
smaher12
398 Views, 2 Replies

Troubles with nothing selected (while loop

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

2 REPLIES 2
Message 2 of 3
Kent1Cooper
in reply to: smaher12


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

Kent Cooper, AIA
Message 3 of 3
smaher12
in reply to: Kent1Cooper

Kent1Cooper - I like it. That works great. Thank you so much!!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost