Jump to content

Recommended Posts

Posted

Hello Everyone,

I think I have a simple question, so hopefully I will find my answer…

When I use this code, everything works fine

(while (/= dst1 "400")

(setq dst1 (getstring T "\nEnter Width (400,200): ")))

However, when I try to use “or”, I can’t get it to work

(while (or (/= dst1 "400")(/= dst1 "200"))

(setq dst1 (getstring T "\nEnter Width (400,200): ")))

Thanks in advance!

Posted

If dst1 doesn't equal 400 or 200 in the or statement, it will return nil. Thus, terminating while. Try and instead of or.

Posted

If your going to use the getstring function, why not go the route of

 

(initget 7 "200 400")
(setq dst1 (getstring T "\nEnter Width (400,200): "))

But to answer your question try,

(while (not (or [color=black][font=Verdana](= dst1 "200")[/font][/color][color=black][font=Verdana](= dst1 "400")[/font][/color]))....

Other wise i think you would need an "and" instead of an "or" statement.

Aswell if my memory severs me correct "/=" can cause a probblem now and then, and better useing "not"...Mind you im quiet sinile in my younge age.

 

 

Or

(while (not (member dst1 '("200" "400")))....

Posted

FlowerRobot, initget doesn't work with getstring.

Posted

Thanks for the responses.

I didn’t have success using (initget 7 "400 200"), because if I enter a value other than 400 & 200, the program will continue. However, using “and” and using (not (or works for the most part, but the problem I am having now, is that if I enter 400 as the width, and then repeat the command a minute later, it will skip the while loop (which is the part that asks to enter the distance) and move to the next step. It seems like it is remembering the distance input the first time the command is used... Any reasons why?

Thanks again

Posted
Thanks for the responses.

I didn’t have success using (initget 7 "400 200"), because if I enter a value other than 400 & 200, the program will continue. However, using “and” and using (not (or works for the most part, but the problem I am having now, is that if I enter 400 as the width, and then repeat the command a minute later, it will skip the while loop (which is the part that asks to enter the distance) and move to the next step. It seems like it is remembering the distance input the first time the command is used... Any reasons why?

Thanks again

You are not localizing your variables. It's hard to guess w/o seeing the code.

 

Why not use getreal, getdist or getint to eliminate the user entering alpha characters? You can always convert it to a string if/when you need to.

Posted

Once this code is done, i will add it to another code we have in the office, which draws radiator lines. This part will help offset the lines...

 

(defun c:test (/ en1 pt1 and)

(setvar "cmdecho" 0)

(while (not (or (= dst1 "400")(= dst1 "200")))

(setq dst1 (getstring T "\nEnter Width (400,200): "))

)

(setq en1 (entlast))

(setq pt1 (getpoint "\nSpecify Offset Side:"))

(if (= dst1 "400")

(progn

(command "._offset" 400 en1 "_non" pt1 "")

))

(if (= dst1 "200")

(progn

(command "._offset" 200 en1 "_non" pt1 "")

))

(setvar "cmdecho" 1)

(princ)

)

Posted
You are not localizing your variables.

 

I had to add dst1 and i had to remove and in my localized variables :)

 

Thanks everyone

Posted

Try something like this:

 

(defun c:test (/ en1 dst1 pt1)
 (setvar "cmdecho" 0)
 (and (setq en1 (entlast))
      (while (not (member dst1 '(200 400)))
        (setq dst1 (getreal "\nEnter Width [200/400]: "))
      ) ;_ while
      (setq pt1 (getpoint "\nSpecify Offset Side: "))
      (command "_.offset" dst1 en1 "_non" pt1 "")
 ) ;_ and
 (setvar "cmdecho" 1)
 (princ)
) ;_ defun

 

Plus, you can select the 200 or 400 if dynamic mode is on, or a right-click. :)

Posted
FlowerRobot, initget doesn't work with getstring.

 

Whoops was thinking of getkword, but wrote getstring, Was drinking my morning coffeee so you know how it is...

Posted
Whoops was thinking of getkword, but wrote getstring, Was drinking my morning coffeee so you know how it is...

:) For me it would have been a jittery getstrrrriiiiing.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...