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

lisp to toggel between two funtions

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
The_Caddie
441 Views, 3 Replies

lisp to toggel between two funtions

Hi all,

 

I’m having a mental collapse\ blank today. I'm trying to write a lisp that toggles between two custom lisp/ functions.

 

just incase, the lisp is to be incorperated into a button...

 

Can somebody help?

3 REPLIES 3
Message 2 of 4
stevor
in reply to: The_Caddie

Not sure what you mean,

but an easy coding method to toggle between

two anything is use one autolisp variable as a key,

containing either T or nil.  Ex:

 (if togvar1

    (progn  (do-one-thing ) (setq TogVar1 nil) )

    (progn  (do-other-thing ) (setq TogVar1 t ) )

 )

And it could be simplified various ways, but memory and speed is cheap..

 

And for toggleing between  two alternate functions, like Func1 and Func2:

 

(if TogVar1 ( Func1 ) ( Func2 ) ) ; alternate functions

(setq TogVar1 ( not TogVar1 ) ) ; the toggle of the key

 

And by using an integer instead of the logic data in the key's state variable,

it can be extended to 3 or more states, and their associated processes, or functions.

 

 

S
Message 3 of 4
The_Caddie
in reply to: stevor

thanks this helped...

 

(defun C:TOGGEL ()
(if togvar1
    (progn  (TOMMY) (setq TogVar1 nil) )
    (progn  (TUCKER) (setq TogVar1 t ) )
 )

)

(defun TOMMY ()
(alert "TOMMY!")

;Sets the next toggel command in place...
(setq TogVar1 t )
)

(defun TUCKER ()
(alert "TUCKER!")

;Sets the next toggel command in place...
(setq TogVar1 nil)
)

  ofcause this is just a test to the entier lisp.

Message 4 of 4
Lee_Mac
in reply to: The_Caddie

Another option to avoid the global variable:

 

(defun c:toggle nil (tommy))

(defun tommy nil
    (alert "Tommy!")
    (defun c:toggle nil (tucker))
    (princ)
)

(defun tucker nil
    (alert "Tucker!")
    (defun c:toggle nil (tommy))
    (princ)
)

 

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

Post to forums  

Autodesk Design & Make Report

”Boost