Jump to content

Recommended Posts

Posted

Hi,

 

I want to run this condition (nextstep) continuously if "Y" is true until "N" is true.

 

	(initget 1 "Y y N n")
	(setq nextstep (strcase (getkword "\nDo you want to continue with next step? [Y/N]?: ")))
	(cond
		((= nextstep "Y")
			(initget 1 "P p N n")
			(setq nextpos (strcase (getkword "\nContinue after Previous position or start at New postition? [P/N]?: ")))
			(cond
				((= nextpos "P")
					;piece of code
				)
				((= nextpos "N")
					;piece of code
				)
			)
		)
		((= nextstep "N")
			(princ "Drawing is finished!")
		)
	)

 

How do I do that?

 

Posted (edited)

As Steven correctly indicates, a while loop is the way to go, however, since both prompts offer a binary choice, you can encode a default option with no additional code, e.g.:

(while
    (progn
        (initget "Yes No")
        (/= "No" (getkword "\nDo you want to continue with the next step? [Yes/No] <Yes>: "))
    )
    (initget 1 "Previous New")
    (if (= "Previous" (getkword "\nContinue after the Previous position or start at a New postition? [Previous/New] <New>: "))
        (princ "\nUser selected Previous.")
        (princ "\nUser selected New.")
    )
)

 

Edited by Lee Mac
  • Like 1
Posted (edited)

That is a nice one Lee!

Where do I put the different lisp codes for New and Previous location then?

I also figured out a way, but not so efficient.

 

(while
	(or
		(initget 1 "Y y N n")
		(= (setq nextstep (strcase (getkword "\nDo you want to continue with next step? [Y/N]?: "))) "Y")
	)
	(cond
		((= nextstep "Y")
			(initget 1 "P p N n")
			(setq nextpos (strcase (getkword "\nContinue after Previous position or start at New postition? [P/N]?: ")))
			(cond
				((= nextpos "P")
					(progn
						(princ "Previous Position is selected!")
					)
				)
				((= nextpos "N")
					(progn
						(princ "New Position is selected!")
					)
				)
			)
		)
		((= nextstep "N")
			(princ "Drawing is finished!")
		)
	)
)

 

Edited by gsc
Posted (edited)
14 hours ago, gsc said:

That is a nice one Lee!

Where do I put the different lisp codes for New and Previous location then?

 

Thank you - you would perform the relevant operations here:

(while
    (progn
        (initget "Yes No")
        (/= "No" (getkword "\nDo you want to continue with the next step? [Yes/No] <Yes>: "))
    )
    (initget 1 "Previous New")
    (if (= "Previous" (getkword "\nContinue after the Previous position or start at a New postition? [Previous/New] <New>: "))
        (progn
            ;; Do something if the user selects Previous
        )
        (progn
            ;; Do something if the user selects New
        )
    )
)

 

Edited by Lee Mac
Posted

I don't know if I am right or wrong, but I suppose that if you stated in (initget 1 "Previous New") the following (getkword) will honor "Previous" and not just "P"...

So I believe that it should actually be :

(while
    (progn
        (initget "Yes No")
        (/= "No" (getkword "\nDo you want to continue with the next step? [Yes/No] <Yes>: "))
    )
    (initget 1 "Previous New")
    (if (= "Previous" (getkword "\nContinue after the Previous position or start at a New postition? [Previous/New] <New>: "))
        (progn
            ;; Do something if the user selects Previous
        )
        (progn
            ;; Do something if the user selects New
        )
    )
)

 

Posted (edited)
2 hours ago, marko_ribar said:

I don't know if I am right or wrong, but I suppose that if you stated in (initget 1 "Previous New") the following (getkword) will honor "Previous" and not just "P"...

 

It was my mistake - it should have been (= "Previous" ...) in my earlier posts (I have since corrected the code in my earlier posts) - thank you for bringing this to my attention. (initget 1 ...) will force the user to specify an option rather than being able to press Enter to accept the default option.

Edited by Lee Mac
Posted

Thanx, this is working.

I have only one other question.

If I want to print a message after the user has selected "No", where (and how) do I write that?

(progn
	(princ "The drawing is finished!")
) 

I have tried several positions, but the message always appears, even if Yes is selected

Posted (edited)

For me it may be easier to call a defun as next, rather than having a very deep multi cond running and trying to have lots of code inside the cond to balance.

 

(defun yesyes ()
(initget 1 "P p N n")
			(setq nextpos (strcase (getkword "\nContinue after Previous position or start at New postition? [P/N]?: ")))
			(cond
				((= nextpos "P")(princ "Previous Position is selected!")) ; call defun "previous"
				((= nextpos "N") (princ "New Position is selected!")) ; call defun "newpos"
				)
)
; starts here
(initget "Yes No")
(setq nextstep (getkword "\nDo you want to continue with the next step? [Yes/No] <Yes>: "))
(cond
		((= nextstep "Yes")(yesyes))
		((= nextstep "No")(Alert "Drawing is finished"))
)

or using ifs

(initget "Yes No")
(setq nextstep (getkword "\nDo you want to continue with the next step? [Yes/No] <Yes>: "))
(if (= nextstep "Yes")
    (progn
            (initget 1 "P p N n")
			(setq nextpos (strcase (getkword "\nContinue after Previous position or start at New postition? [P/N]?: ")))
			(if (= nextpos "P")
			  (progn (princ "Previous Position is selected!")
			  do your thing here
			  )
			  (progn
			  (princ "New Position is selected!")
			  do your other thing here
			  )
			)
    )
    (Alert "Drawing is finished")
)

 

Edited by BIGAL
Posted
15 hours ago, gsc said:

I have only one other question.

If I want to print a message after the user has selected "No", where (and how) do I write that?


(progn
	(princ "The drawing is finished!")
) 

I have tried several positions, but the message always appears, even if Yes is selected

 

You would place this outside of the while loop entirely.

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