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

Show Message prompt Yes/No before continue

32 REPLIES 32
SOLVED
Reply
Message 1 of 33
JCprog
4852 Views, 32 Replies

Show Message prompt Yes/No before continue

Hello Everyone!Smiley Happy

 

I need help on the code below to ask the user if yes or no. If yes continue with the script, if no cancel routine. 

(initget "Yes No")
(if (eq (getkword "\nThis wil load & run someroutine, Do you wish to continue? [Yes/No] <No>: ") "Yes")
  (setvar '?????)
)
(load "C:/folder1/someroutine.lsp")
(command "someroutine")

 Thanks in advance!Smiley Happy

32 REPLIES 32
Message 2 of 33
hmsilva
in reply to: JCprog

(initget "Yes No")
(if (eq (getkword "\nThis wil load & run someroutine, Do you wish to continue? [Yes/No] <No>: ") "Yes")
   (setvar '?????)
   (progn
     (load "C:/folder1/someroutine.lsp")
     (command "someroutine")
   )
)

HTH

Henrique

EESignature

Message 3 of 33
alanjt_
in reply to: JCprog

(initget "Yes No")
(if (and (eq (getkword "\nThis wil load & run someroutine, Do you wish to continue? [Yes/No] <No>: ") "Yes")
         (load "C:/folder1/someroutine.lsp" nil) ; check if lisp actually loads
    )
  (command "someroutine") ; not sure why using command. command won't work on lisp routines
)

 

Message 4 of 33
JCprog
in reply to: alanjt_

Hello alanjt_
Thanks for the reply! Im not trying to do this through lisp, I need this using script (.scr)
Message 5 of 33
alanjt_
in reply to: JCprog

It should work under the same principal. You can run lisp in a scr (as long as it's not autocad LT).
Message 6 of 33
paullimapa
in reply to: JCprog

Unfortunately, Script files will not pause for user input.  Script files just contain a sequence of commands that execute from beginning to end.

You'll need to use Lisp to request for a pause and user input.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 33
JCprog
in reply to: hmsilva

Hello Henrique, this didnt work.
Message 8 of 33
JCprog
in reply to: paullimapa

I see....if thats the case then lets go with the lisp that will load another lisp routine then run it.....before asking the user first if wants to continue.
Message 9 of 33
paullimapa
in reply to: JCprog

Also as others have stated, don't use (command "someroutine") to execute Lisp function.

Assuming lisp function is coded with (defun c:someroutine ()..

then the code to call the lisp function is: (c:someroutine)

If lisp function is coded with just (defun someroutine ()..

then the code to call the lisp function is (someroutine)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 33
JCprog
in reply to: paullimapa

Thanks Paul!!!! simple tutorial goes a long way for me.....very much appreciated sir!!!!!!!!!!
Message 11 of 33
paullimapa
in reply to: JCprog

Sure..no problem...glad to have helped.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 33
Kent1Cooper
in reply to: JCprog


@JCprog wrote:

.... 

I need help on the code below to ask the user if yes or no. If yes continue with the script, if no cancel routine. 

(initget "Yes No")
(if (eq (getkword "\nThis wil load & run someroutine, Do you wish to continue? [Yes/No] <No>: ") "Yes")
  (setvar '?????)
)
(load "C:/folder1/someroutine.lsp")
(command "someroutine")

....


[EDIT: Someone beat me to the punch on some of this, but I'll leave it anyway....]

 

That's not a script [AutoCAD means something specific and different by that word, though Scripts can include AutoLISP code within limits as noted in another Reply].  But assuming you're only using the term in the way that a lot of people often do mistakenly --

 

I don't think you need to set any variable.  I would try this:

 

(initget "Yes No")
(if

  (and

    (= (getkword "\nThis wil load & run someroutine, Do you wish to continue? [Yes/No] <No>: ") "Yes")
    (load "C:/folder1/someroutine.lsp"); it loaded successfully

  ); and
  (someroutine); then expression

); if

 

That assumes that the someroutine.lsp file defines a function of the same name, i.e. it contains a line starting like this:

 

(defun someroutine (.....

 

But a file name doesn't necessarily need to be the same as the name of the function it defines, and a single file can define more than one function and/or command.  If the function that you want to run from that file has some other name, use that instead in the 'then' expression parentheses above.  If it defines a command with a C: in front:

 

(defun C:someroutine (/ .....

 

then include that C: in the 'then' expression parentheses, i.e. use:

  (C:someroutine); then

since you can't use the (command) function to call a Lisp-defined command, only a native AutoCAD command.

Kent Cooper, AIA
Message 13 of 33
alanjt_
in reply to: Kent1Cooper

Kent's load call is flawed. While the second variable in load is optional, it will error if the routine cannot be found.

 

Command: (load "someroutine.lsp" nil)
nil

Command: (load "someroutine.lsp" "did not load")
"did not load"

Command: (load "someroutine.lsp")
Error: LOAD failed: "someroutine.lsp"

 

See the differences of how load functions when the second variable is/isn't filled in. If you use the code snippet I posted before, it will yield the results you want, just replace (command) with an acutal call to the lisp routine (which is exactly what I questioned you about). eg. (c:CommandName)

Message 14 of 33
JCprog
in reply to: alanjt_

Can you post the whole working code please.
Message 15 of 33
alanjt_
in reply to: JCprog

(initget "Yes No")
(if (and (eq (getkword "\nThis wil load & run someroutine, Do you wish to continue? [Yes/No] <No>: ") "Yes")
         (load "C:/folder1/someroutine.lsp" nil) ; check if lisp actually loads
    )
  (c:CommandName)
)

 Sure. 🙂

Message 16 of 33
Lee_Mac
in reply to: alanjt_

For completeness, perhaps also a check to ensure the program defines the function in question:

 

(initget "Yes No")
(if (= "Yes" (getkword "\nLoad & run someroutine? [Yes/No] <No>: "))
    (if (or c:commandname (and (load "C:/folder1/someroutine.lsp" nil) c:commandname))
        (c:commandname)
        (princ "\nc:commandname could not be defined.")
    )
)
Message 17 of 33
JCprog
in reply to: Lee_Mac

Lee_Mac to the rescue!!!!!!!!! Good to see you Lee!
Message 18 of 33
alanjt_
in reply to: Lee_Mac

While I do agree with you, that's quite a bit of overkill error checking for a bit of code to load a lisp routine someone compiled. lol

Message 19 of 33
JCprog
in reply to: alanjt_

Both codes work just perfect!!!! Thank you much!!!!!
Message 20 of 33
alanjt_
in reply to: JCprog

Use Lee's. 

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

Post to forums  

Autodesk Design & Make Report

”Boost