activate or deactivate a tile in dialog window with a toggle

activate or deactivate a tile in dialog window with a toggle

andkal
Collaborator Collaborator
2,114 Views
13 Replies
Message 1 of 14

activate or deactivate a tile in dialog window with a toggle

andkal
Collaborator
Collaborator

Hi all
I need to acitivate or deactivate a tile in dialog window with a Toggle-tile. The efect you can see in the short video (see gif file):

gif.gif

Im writing a Lisp routine with DCL section in the LSP file. The problem is I get the desired effect when there is a separate DCL file. How can I correct the following code to make it work without separate DCL file?

 

 

 

(defun c:test (/ dcl_id tmpfpath1)
    (setq tmpfpath1 "D:\\DOWNLOADS\\test\\test.dcl") ;<-path of DCL file with double backslashes
    (setq dcl_id (load_dialog tmpfpath1))
    (new_dialog "testDCL" dcl_id)
    (action_tile   "tile2"   "(mode_tile \"tile1\"  (abs (-(atoi $value)1)))"   )
    (start_dialog)
);defun


(defun c:test1 (/ dcl_id tmpfpath1 infile1)
    (setq         tmpfpath1 (strcat (getvar "MYDOCUMENTSPREFIX") "\\TEMP1DCL.DCL") )
    (setq infile1 (open tmpfpath1 "w"))
    (write-line
    "testDCL : dialog
    {:edit_box {label = \"value1:\"; key = \"tile1\"; edit_width = 20;  }
      :toggle {key = \"tile2\"; label = \"test_toggle1\"; }
      ok_cancel; }"
    infile1
    );write lin
    (close infile1)
    (setq dcl_id (load_dialog tmpfpath1))
    (new_dialog "testDCL" dcl_id)
    (action_tile   "tile2"   " (mode_tile \"tile1\"  (abs (-(atoi $value)1))) "   )
    (start_dialog)
    (unload_dialog dcl_id)
    (vl-file-delete tmpfpath1 )
);defun

 

 

 

 

DCL file:

 

 

    testDCL : dialog {
      :edit_box {key = "tile1"; label = "value:"; edit_width = 10; }
      :toggle {  key = "tile2";  label = "Toggle 1";  }
      ok_cancel;  }

 


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Accepted solutions (1)
2,115 Views
13 Replies
Replies (13)
Message 2 of 14

Moshe-A
Mentor
Mentor

@andkal ,

 

>> check this thread <<  just a week ago, an example on how to create a dcl on the fly.

and if you google or search this forum you will find more 😀

 

Moshe

 

0 Likes
Message 3 of 14

andkal
Collaborator
Collaborator

Thank you for a quick reply.
The code I posted already contains a function (TEST1) with DCL on fly. The problem is that the toggle in this function does not activate/deactivate the edit_box tile like function (TEST) with with separate DCL file. If the GIF doesnt load, it is also attached at the end of my first post.


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 4 of 14

Moshe-A
Mentor
Mentor
Accepted solution

@andkal ,

 

first of all not that a toggle tile can have only 1/0 so (abs) is redundant.

 

to make the edit_box on/off use this:-

(action_tile "tile2" "(mode_tile \"tile1\" (- 1 (atoi $value)))")

 

Moshe

 

0 Likes
Message 5 of 14

andkal
Collaborator
Collaborator

Thank you, it works, it solves the problem.

Although Im curious how does it work.
When I check the toggle   $value returns 1, so to activate edit_box I need to feed set_tile function with 0. Hence (- 1 (atoi $value).
When I uncheck the toggle   $value returns 0, so to deactivate edit_box I need to feed set_tile function with 1.

(- 1 (atoi $value) returns then -1  thats why I added ABS

I modified this line to the following (to print later the values with PRINC) :

(action_tile "tile2" "(setq val1 (atoi $value) val2 (abs (- val1 1))) (mode_tile \"tile1\" val2)")


and it works. But with no ABS this line, as we can expect, doesnt work becouse we get   -1.


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@andkal wrote:

....
When I check the toggle   $value returns 1, so to activate edit_box I need to feed set_tile function with 0. Hence (- 1 (atoi $value).
When I uncheck the toggle   $value returns 0, so to deactivate edit_box I need to feed set_tile function with 1.

(- 1 (atoi $value) returns then -1  thats why I added ABS
.....


[Does $value return 1 [a number] or "1" [a text string] as would be needed for your (atoi) functions?  Assuming the latter....]

 

Are you sure that's how you have it structured?  If it was the reverse:

  (- (atoi $value) 1)

or the maybe-less-obviously-reversed dquivalent:

  (1- (atoi $value))

then when $value is "0", the result would be -1.  But if, as described, it's really:

  (- 1 (atoi $value))

then if $value is "0", the result will be [positive] 1, and if it's "1", the result will be 0.  I don't see how it can come up with a result of -1.

Kent Cooper, AIA
0 Likes
Message 7 of 14

andkal
Collaborator
Collaborator

Oh I mistook 1- with - 1, (was reading too fast). I ment to write (- (atoi $value) 1) returns -1, sorry.
Answearing your question I observed that $value returns:
nil - when no action is made on toggle
"0" - (STR) when clicked to uncheck

"1" - (STR) when clicked to check

In the way Moshe-A wrote it ABS really is not necessary.
But still, I can't find a difference in result between (abs (-(atoi $value)1)) and (- 1 (atoi $value)). They give the same number when I store it in a variable.

And somehow this code doesn't work:

 

(mode_tile \"tile1\" (abs (- (atoi $value) 1)))

 

but this one works:

 

(mode_tile \"tile1\" (- 1 (atoi $value)))

 


I noticed too that when I store my"abs-version" in a variable it starts to work.

 

(action_tile "tile2" "(setq val2 (abs (- (atoi $value) 1))) (mode_tile \"tile1\" val2)")

 


Maybe $value behaves differently depending on its position in relation to functions...What also remains unknown for me is that it initially worked in lisp routine wirh separate DCL but didnt work in routine with DCL on fly.


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 8 of 14

Moshe-A
Mentor
Mentor

@andkal ,

 

it seems you still does not understand it so here is one more 'shot' 😀

toggle tile can return only "0" or "1" (not nil) so $value just holds the return value on (action_tile) call.

 

take a look at this:

(- 1 1)  is 0 - agree?

(- 1 0) is 1 - agree?

 

now replace the second argument with (atoi $value) which (as said) returns the toggle tile value

when it's on, it return 1 when it's off, it return 0.  

 

hope now this is more clear? 😀

 

Moshe

 

 

0 Likes
Message 9 of 14

andkal
Collaborator
Collaborator

Hello Moshe-A
First of all, thank you for solving the main problem.
You must have misunderstood my last post. I understand how your expresion works and I also agree that without ABS it is even simplier.
Maybe Im wrong, but what im saying is that that "reveserd" expression when wrapped with ABS gives the same results as you presented. I just dont know why then it doesnt work. See the following.

(abs (- 1 1)) = 0
(abs (- 0 1)) = 1

(Of course if the numbers returned by $value were other than 0 and 1 than those expressions would not be equivalent, but in this particular case they seem to be equivalent).


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 10 of 14

andkal
Collaborator
Collaborator

Also to correct myself:
Not $value returned nil but princ function when printing a not existing variable that was supposed to store $value. When action_tile was not activated varialbe was not created. So $value returns only "0" or "1".


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 11 of 14

Kent1Cooper
Consultant
Consultant

And now for something completely different....

I don't suppose René Magritte was anticipating a pandemic in the painting you pulled your avatar from, but I wonder -- would there be a market for Magritte apple masks?

Kent Cooper, AIA
0 Likes
Message 12 of 14

andkal
Collaborator
Collaborator

Haha, good point.
yes it's from Magritte paiting.
In some countries in EU (including where i live) people say FFP2 masks look like like a pigs nose. (those are here obligatory). Maybe if those masks had an apple painted on them it would make more sens.
pig_apple.jpg


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 13 of 14

andkal
Collaborator
Collaborator

I tried it on another computer with other LISP compatibile software and it worked normally. I guess I'll have to reinstall Autocad.


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 14 of 14

scot-65
Advisor
Advisor

A tile will always return nil unless you initialize it.

 

(set_tile "tile2" "0") is preferred or set it in the DCL

 

** load_dialog

** new_dialog

** initialize

** set_tile

** mode_tile

** action_tile

** start_dialog

** unload_dialog

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes