Deactivate Multiple Tiles with Single Toggle

Deactivate Multiple Tiles with Single Toggle

jcpLPAKD
Participant Participant
671 Views
9 Replies
Message 1 of 10

Deactivate Multiple Tiles with Single Toggle

jcpLPAKD
Participant
Participant

I have three edit boxes that I want to be able to disable with the click of a single toggle. All of these lines will work on their own but when run together only the list line is executed.

 

  (action_tile "tg1" "(setq result $key) (mode_tile \"eb1\" (- 1 (atoi $value))))")
  (action_tile "tg1" "(setq result $key) (mode_tile \"eb1a\" (- 1 (atoi $value))))")
  (action_tile "tg1" "(setq result $key) (mode_tile \"eb1b\" (- 1 (atoi $value))))")

 

Is there a way to combine these 3 lines into one?

 

Thanks in advance!

0 Likes
Accepted solutions (2)
672 Views
9 Replies
Replies (9)
Message 2 of 10

paullimapa
Mentor
Mentor
Accepted solution

put all the action call back functions into one line only and not separate lines that's what's causing the problem because AutoCAD doesn't support multiple callbacks

(action_tile "tg1" "(setq result $key) (mode_tile \"eb1\" (- 1 (atoi $value)))(mode_tile \"eb1a\" (- 1 (atoi $value)))(mode_tile \"eb1b\"(- 1 (atoi $value)))")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 10

Moshe-A
Mentor
Mentor

@jcpLPAKD hi,

 

(action_tile key action-expression)

 

Lets take a look at the second argument of (action_tile) function.

it says action-expression (as a string) - yes?

action-expression means any AutoLISP symbol (variable or a function) 

and function in this case means a callback function. as soon as you click on the tile (action-tile) will fire callback.

 

instead of writing an endless code in one line (which of course is legal) you could do:

 

; callback function

(defun enable_disable_editbox (val)

   (foreach key '("eb1" "eb2" "eb3")

     (mode_tile key (itoa (1- (atoi val))))

   )

)

 

(action_tile "tg1" "(enable_disable_editbox $value)")

 

this way the code is very clear, simple and easy to debug - no? 😀

 

enjoy

Moshe

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 4 of 10

jcpLPAKD
Participant
Participant

Worked perfectly.

Thanks

0 Likes
Message 5 of 10

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 10

jcpLPAKD
Participant
Participant

I like the more compact code but I can't get it to work.  It keeps failing at:

 

(mode_tile key (itoa (1- (atoi val))))
 
When checking the toggle I get the error 'Bad argument type: fixnump: "0"  ' 
When unchecking the toggle I get the error 'Bad argument type: fixnump: "-1" 
Is val supposed to be defined?
0 Likes
Message 7 of 10

paullimapa
Mentor
Mentor

the error occurs when your tile is already disable which returns a value of 0 and your code then applies a subtraction of -1 causing it to now return a negative #. To disable just use 0

(mode_tile key 0)

to enable use 1

(mode_tile key 1)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 10

komondormrex
Mentor
Mentor

try this. 1- function replaced with - function

(action_tile "tg1" "(setq result $key) 
					(foreach tile '("eb1" "eb1a" "eb1b") 
						(mode_tile tile (- 1 (atoi $value)))
					)"
)

 

0 Likes
Message 9 of 10

jcpLPAKD
Participant
Participant

Ok, I finally figured out why this callback function was not working.  The minus sine is in the wrong place and iota is not necessary.

 

This is the corrected code.

 

(defun enable_disable_editbox (val)

   (foreach key '("eb1" "eb2" "eb3")

   (mode_tile key (- 1 (atoi val)))

   )

)

 

(action_tile "tg1" "(enable_disable_editbox $value)")

 

Thanks for all the help with this!

0 Likes
Message 10 of 10

Moshe-A
Mentor
Mentor
Accepted solution

@jcpLPAKD ,

 


@jcpLPAKD wrote:

Ok, I finally figured out why this callback function was not working.  The minus sine is in the wrong place and iota is not necessary.

 

The minus sign is in right place, cause (1- n) is accepable expresstion in autolisp. the (itoa) function is not nessacery here and that is the result of repling here when you do not have a working AutoCAD under hand 😀 

so the following is also correct:

 

(defun enable_disable_editbox (val)

   (foreach key '("eb1" "eb2" "eb3")

   (mode_tile key (1- (atoi val)))

   )

)

 

This is the corrected code.

 

(defun enable_disable_editbox (val)

   (foreach key '("eb1" "eb2" "eb3")

   (mode_tile key (- 1 (atoi val)))

   )

)

 

(action_tile "tg1" "(enable_disable_editbox $value)")

 

Thanks for all the help with this!


Althought i'm not rewarded here 😂, i'm glade to see you finally choose to use my solution 😀

 

cheers

Moshe

 

0 Likes