Jump to content

Call function outside of command [LISP]


OMEGA-ThundeR

Recommended Posts

Hi,

 

i'm trying to create a piece of code with a messagebox that ask a question (yes/no) which in turn should set an value that i can use in the 'main' command.

 

(Defun FUNCTION (reply)
(SETQ reply (ACET-UI-MESSAGE	"Content of questionbox" "Title of questionbox"
				(+ Acet:YESNO Acet:ICONQuestion)
		)
)
)

 

As far as my 'function' knowledge goes this usually is defined within a command. i.e.:

 

(Defun c:command ()
(defun FUNCTION ( / a)
  (do something)
)
(FUNCTION (and do something with that function))
)

 

But i kind of want to use the function in multiple commands that work in a similar way, but don't want to add the lines of code to every command.

 

So, how do i make the following work?

 

(Defun FUNCTION (reply)
(SETQ reply (ACET-UI-MESSAGE	"Content of questionbox" "Title of questionbox"
				(+ Acet:YESNO Acet:ICONQuestion)
		)
)
)

(Defun c:CallFunction1 ()
FUNCTION
)

(Defun c:CallFunction2 ()
FUNCTION
)

(Defun c:CallFunction3 ()
FUNCTION
)

Link to comment
Share on other sites

Should look something like this.

All three command's now open the dialog with the YES/NO question...

So there is no variable for the three commands in this case.

 

(defun FUNCTION ( / )
(setq reply (ACET-UI-MESSAGE "Choose dude " "Russells Dialog" (+ Acet:YESNO Acet:ICONQuestion)))
;; Yes = 6, No = 7
(if (= reply 6)
	(progn
		(ALERT "Yep")
	)
	(progn
		(ALERT "Nope")
	)
)
)

(defun C:CallFunction1 ( / )
(FUNCTION)
(princ)
)

(defun C:CallFunction2 ( / )
(FUNCTION)
(princ)
)

(defun C:CallFunction3 ( / )
(FUNCTION)
(princ)
)

(princ)

 

To do something different for each command, it could look like this:

(defun TESTCOMMAND ( number / )
(setq reply (ACET-UI-MESSAGE "Choose dude " "Russells Dialog" (+ Acet:YESNO Acet:ICONQuestion)))
;; Yes = 6, No = 7
(if (= reply 6)
	(progn
		(cond
			((= number 1)
				(princ "Voorwaarden voor CallFunction1")
			)
			((= number 2)
				(princ "Voorwaarden voor CallFunction2")
			)
			((= number 3)
				(princ "Voorwaarden voor CallFunction3")
			)
		)
	)
	(progn
		(princ "NO, annuleren.")
	)
)
)

(defun C:CallFunction1 ( / )
(TESTCOMMAND 1)
(princ)
)

(defun C:CallFunction2 ( / )
(TESTCOMMAND 2)
(princ)
)

(defun C:CallFunction3 ( / )
(TESTCOMMAND 3)
(princ)
)

(princ)

 

(TESTED AND WORKING)

Edited by Aftertouch
Link to comment
Share on other sites

Gives errors in both cases and i can't find a way to fix them :(. Seems to be going wrong in the command parts

Link to comment
Share on other sites

This is the code i tested and works perfect. :)

 

(defun TESTCOMMAND ( number / )
(setq reply (ACET-UI-MESSAGE "Choose dude " "Russells Dialog" (+ Acet:YESNO Acet:ICONQuestion)))
;; Yes = 6, No = 7
(if (= reply 6)
	(progn
		(cond
			((= number 1)
				(princ "Voorwaarden voor CallFunction1")
			)
			((= number 2)
				(princ "Voorwaarden voor CallFunction2")
			)
			((= number 3)
				(princ "Voorwaarden voor CallFunction3")
			)
		)
	)
	(progn
		(princ "NO, annuleren.")
	)
)
)

(defun C:CallFunction1 ( / )
(TESTCOMMAND 1)
(princ)
)

(defun C:CallFunction2 ( / )
(TESTCOMMAND 2)
(princ)
)

(defun C:CallFunction3 ( / )
(TESTCOMMAND 3)
(princ)
)

(princ)

Link to comment
Share on other sites

IMO you should strive for a 'YesNo' function with this signature:

(YesNoDialog "Title" "message") => T/nil (return value T or nil)

Link to comment
Share on other sites

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