Jump to content

Recommended Posts

Posted

Dear All,

Need your help on how should I be able to set a string depending on the toggle key value:

Here's the code...

DCL

 :boxed_row {
    key = "InOut";
    label = "Plot In/Out the viewport:";
 :toggle  {label="Inside";
    key = "in";}
 :toggle  {label="Outside";
    key = "out";}}

 

LISP

 (action_tile "in"
 "(progn
      (setq in $value)
      (in_action $value))")
 (action_tile "out"
 "(progn
      (setq out $value)
      (out_action $value))")
  (defun in_action (value)
      (if (/= value "0")
      (progn (set_tile "out" "0"))))
  (defun out_action (value)
      (if (/= value "0")
      (progn (set_tile "in" "0"))))

 (action_tile "accept"
   "(setq gPlot (get_tile \"InOut\"))
      (done_dialog 1) (setq userclick T)
    )"
 )

 (if userclick
   (cond                                                
     ((= gPlot "in")(setq gInOut "Inside"))
     ((= gPlot "out")(setq gInOut "Outside))
   )
   nil
 )

…..so it can be read by this argument

          (if (setq temp gInOut)
              (setq gSet  (= temp "Outside"))
              (setq gSet  'T)
          )

 

Thanks in advance!!!

 

Posted

Hi,

Your explanation is not quite enough so try the following to know what is the return value of each toggle [in/out]

(action_tile "in"  "(alert (strcat \"Current status for 'in' is: \" (get_tile \"in\")))")
(action_tile "out" "(alert (strcat \"Current status 'out' is: \"    (get_tile \"out\")))")

Besides that, you need to read about progn function to know how and when to use it.

Posted

Toggles are check boxes. Are you planning on both "In" and "Out" being checked, or is this an "either or"? If the latter then i would switch to using radio buttons. Much easier to control and a single variable to up date if either is selected.

Posted

1435657345_togglekey.png.f64f15e2f49c6003fd39d6ab58f60eaf.png

 

Here's what it looks like, what I want to achieve is when I select "inside" grid coordinates will be drawn inside the viewport and otherwise it will be plotted outside.

@ dlanorh the reason why I prefer to try to use toggle key just to make my dialogue box more presentable because I already have radio buttons.

@ Tharwat , I will try Sir.

 

Posted (edited)
; https://www.cadtutor.net/forum/topic/66854-need-help-for-toggle-key/

; main routine
(defun c:t1 ( / fn gInOut )
  (_start_dialog)
  (if (and fn (findfile fn))(vl-file-delete fn))
  (princ)
)

; you may guess 1 time what this function does
(defun _create_dialog ( / fp)
  (if (and (setq fn (vl-filename-mktemp ".dcl")) (setq fp (open fn "w")))
    (mapcar '(lambda (x)(princ x fp))
        '("Glory_1 : dialog {label=\"Plot Viewport\";"
          ":boxed_row {label=\"Plot In/Out the viewport:\";"
            ":toggle {label=\"Inside\";key=\"tg_in\";}"
            ":toggle {label=\"Outside\";key=\"tg_out\";}}"
           ":boxed_radio_row {label=\"Plot In/Out the viewport:\";"
            ":radio_button {label=\"Inside\";key=\"rb_in\";}"
            ":radio_button {label=\"Outside\";key=\"rb_out\";}}"
          "ok_cancel;}"
         )
    )
  )
  (if fp (close fp))(gc)
)

; assign all actions to the toggles & (radio) buttons
(defun _dialog_actions ()
  (mapcar
    '(lambda (x)(action_tile (car x) (cadr x)))
    '(("cancel" "(done_dialog 0)")
      ("accept" "(done_dialog 1)")

      ("tg_in"  "(toggle_me \"in\")")
      ("tg_out" "(toggle_me \"out\")")

      ("rb_in"  "(setq gInOut \"Inside\")")
      ("rb_out" "(setq gInOut \"Outside\")")
     )
  )
)

; you can use toggles but they are normaly used when multiple conditions can be true (which are called 'options')
; In your case, there should only be one option true, you're either inside or you're outside
; unless of course you are a cat writing this program on your quantum computer. If not? : meet the radio button
(defun toggle_me (in_or_out)
  (if (eq in_or_out "in")
    (progn (setq gInOut "Inside")(set_tile "tg_out" "0")(set_tile "rb_out" "0"))
    (progn (setq gInOut "Outside")(set_tile "tg_in" "0")(set_tile "rb_in" "0"))
  )
)

(defun _start_dialog ( / id dcl drv)
  (_create_dialog)
  (if (and fn (setq fn (findfile fn)) (setq id (load_dialog fn)) (new_dialog "Glory_1" id))
    (progn
      (_dialog_actions)
      (setq drv (start_dialog))
      (cond
    ((= 0 drv)(alert "Dialog was cancelled"))
    ((= 1 drv)(alert (strcat "gInout = " gInOut)))
      )
    )
    (alert "dialog not started")
  )
)

 

Edited by rlx
Posted (edited)

Heres some simple example, to simulate a radio_row with toggles :

 

(defun C:test ( / toggleSet *error* kL dcl des dch dcf r )
  
  (defun toggleSet ( k kL )
    (foreach x kL (set_tile x "0")) (set_tile k "1") k
  )
  
  (defun *error* ( m )
    (and (< 0 dch) (unload_dialog dch))
    (and (eq 'FILE (type des)) (close des))
    (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
    (and m (princ m)) (princ)
  ); defun *error*
  
  (and 
    (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "W"))
    (princ
      (strcat
        "test : dialog"
        "{"
        ": boxed_row "
        "{ label = \"Plot In/Out the viewport:\";"
        "  : toggle { label = \"Inside\"; key = \"in\"; }"
        "  : toggle { label = \"Outside\"; key = \"out\"; }"
        "  : toggle { label = \"Left\"; key = \"left\"; }"
        "  : toggle { label = \"Right\"; key = \"right\"; }"
        "  : toggle { label = \"Up\"; key = \"up\"; }"
        "  : toggle { label = \"Down\"; key = \"down\"; }"
        "}"
        "spacer_1;"
        "ok_cancel;"
        "}"
      ); strcat 
      des
    ); princ
    (not (setq des (close des))) (setq dch (load_dialog dcl)) (new_dialog "test" dch)
    (progn
      (setq kL '("in" "out" "left" "right" "up" "down"))
      (set_tile (setq r (car kL)) "1")
      (foreach k kL 
        (action_tile k "(setq r (toggleSet $key kL))")
      )
      (action_tile "accept" "(done_dialog 1)")
    ); progn
    (= 1 (setq dcf (start_dialog)))
    (alert (strcat "User's choice:\n" (nth (vl-position r kL) '("Inside" "Outside" "Left" "Right" "Up" "Down"))))
  ); and
  (*error* nil) (princ)
); defun

 

EDIT: dang Rlx replied few seconds faster, because in Germany the internet speed is fast like their autobahn. :D

BTW aside from the "presentable look", @dlanorh has a good point that with this idea the user may be confused

(hence that might not be a good idea from user's perspective).

Edited by Grrr
Posted

Thank you so much guys for time. @ Grrr I will try to analyze the code you suggest to fit in my existing codes.

Posted

Problem solved!!!

Thank you so much guys... 'til next time.

 

Special THANKS to Grrr, that is what I am looking for by forcing the toggle to select either in or out.

Posted
2 hours ago, GLORY said:

Special THANKS to Grrr, that is what I am looking for by forcing the toggle to select either in or out.

 

You're wellcome, @GLORY !

Again don't forget dlanorh's remark - I might use this technique in a program for a personal use (because I'll know what I did in there) but for anyone else it would be a risky GUI.

Posted

Now and again I (mis?) use toggles as a sort of radio buttons when certain combinations of settings have an impact on the rest of the program or dialog. In that case I pass the toggle action to my 'toggle-police' where I do the rest like if toggle a and toggle b are 1 and toggle c is 0 then disable button d.

Posted (edited)
40 minutes ago, rlx said:

Now and again I (mis?) use toggles as a sort of radio buttons when certain combinations of settings have an impact on the rest of the program or dialog. In that case I pass the toggle action to my 'toggle-police' where I do the rest like if toggle a and toggle b are 1 and toggle c is 0 then disable button d.

 

I've also "misused" checkboxes in the past (namely within the XML options for this old program); in this case I thought it necessary as having both checkboxes unchecked was also a valid option, which is not possible when using radio buttons unless you introduce a third radio button option of "neither".

 

Lee

Edited by Lee Mac
Posted
11 minutes ago, Lee Mac said:

 

I've also "misused" toggles in the past (namely within the XML options for this old program); in this case I thought it necessary as having both toggles unchecked was also a valid option, which is not possible when using radio buttons unless you introduce a third radio button option of "neither".

 

Lee

That was the next problem to deal with after looking for a solution for the issue that I posted, but applying the code from Grrr everything was solved. Anyways THANKS to everyone. Now I am currently dealing with error handling cause after running the program some user environment was not back to its current settings. And I am looking at your (Lee Mac) site to fix this one.

http://www.lee-mac.com/errorhandling.html

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