get stuck with combined dialog box

get stuck with combined dialog box

Anonymous
Not applicable
1,325 Views
5 Replies
Message 1 of 6

get stuck with combined dialog box

Anonymous
Not applicable

I'm trying to create a dialog box to draw a circle which have 2 choice. First one is 2 point (2p) to draw a circle and the other is 1 point and radius. I create a radio list for that. What I want is when I click on 1 choice and another dialog box open and you can enter data on that dialog box and then when you click Ok. Autocad execute the command of drawing a circle. But my lsp and dcl codes don't work. Can sb explain to me? Here is my lsp and dcl code:

 

LSP code: 

(defun C:selena(/ dcl_id userclick)

(if (not (setq dcl_id (load_dialog "selena.dcl")))

(progn

(princ"\n dcl file can not be loaded")

(exit)

)

(progn

(if (not (new_dialog "selena" dcl_id))

(progn

(princ"\n the definition can not be loaded")

(exit)

)

(progn

(action_tile "2point" "(setq choice1 (atoi(get_tile \"2point\")))")

(action_tile "center_radius" "(setq choice2 (atoi(get_tile \"center_radius\")))")

(action_tile "accept" "(done_dialog 1)")

(action_tile "cancel" "(done_dialog 0)")

(set userclick (start_dialog))

(unload_dialog dcl_id)

(if userclick

(progn

(if (= choice1 1)

(defun gomez (/ dcl_id1 userclick)

(if (not (setq dcl_id1 (load_dialog "gomez.dcl")))

(progn

(princ"\n dcl file cann't be loaded")

(exit)

)

(progn

(if (not (new_dialog "gomez" dcl_id1))

(progn

(princ"\n the definition can not be loaded")

(exit)

)

(progn

(action_tile "X1" "(setq X1 (atof(get_tile \"X1\")))")

(action_tile "Y1" "(setq Y1 (atof(get_tile \"Y1\")))")

(action_tile "X2" "(setq X2 (atof(get_tile \"X2\")))")

(action_tile "Y2" "(setq Y2 (atof(get_tile \"Y2\")))")

(action_tile "accept" "(done_dialog 1)")

(action_tile "cancel" "(done_dialog 0)")

(setq userclick (start_dialog))

(unload_dialog dcl_id1)

(if userclick

(progn

(command "circle" "2p" (list X1 Y1) (list X2 Y2))

)

(progn

(alert"\n exit the program")
)

)
)

)
)
)

)

)

(if (= choice2 1)

(progn

(defun superman(/ dcl_id2 userclick)

(if (not (setq dcl_id2 (load_dialog "superman.dcl")))

(progn

(princ"\n dcl file can not be loaded")

(exit)

)

(progn

(if (not (new_dialog "superman" dcl_id2))

(progn

(princ"\n the definition can not be loaded")

(exit)

)

(progn

(action_tile "X" "(setq X (atof(get_tile \"X\")))")

(action_tile "Y" "(setq Y (atof(get_tile \"Y\")))")

(action_tile "radius" "(setq radius (atof(get_tile \"radius\")))")

(action_tile "accept" "(done_dialog 1)")

(action_tile "cancel" "(done_dialog 0)")

(setq userclick (start_dialog))

(unload_dialog dcl_id2)

(if userclick

(progn

(command "circle" (list X Y) radius )
)

(progn

(alert"\n exit the program")
)

)
)
)

)
)

)
)
)

)

(progn

(alert"\n exit the program")

)

)
)

)
)
)
)

 

DCL code 1 : 

 

selena

:dialog{

:boxed_column{

:boxed_radio_column{

:radio_button{

key="2point";

label="select 2 point on plane";

}

:radio_button{

key="center_radius";

label="select center and radius";

}
}

:row{

:button{

key="accept";

label="ok";

is_default=true;

is_cancel=true;

}

:button{

key="cancel";

label="cancel";

is_default=true;

is_cancel=true;
}
}
}
}

 

DCL code 2: 

gomez

:dialog{

:boxed_column{

:row{

:edit_box{

key="X1";

label="X1";

}

:edit_box{

key="Y1";

label="Y1";
}

}

:row{

:edit_box{

key="X2";

label="X2";
}

:edit_box{

key="Y2";

label="Y2";
}

}

:row{

:button{

key="accept";

label="ok";

is_default=true;

is_cancel=true;

}

:button{

key="cancel";

label="cancel";

is_default=true;

is_cancel=true;
}
}
}
}

 

DCL code 3 : 

superman

:dialog{

:boxed_column{

:row{

:edit_box{

key="X";

label="X";

}

:edit_box{

key="Y";

label="Y";

}
}

:edit_box{

key="radius";

label="radius";

}

:row{

:button{

key="accept";

label="ok";

is_default=true;

is_cancel=true;

}

:button{

key="cancel";

label="cancel";

is_default=true;

is_cancel=true;
}
}
}
}

0 Likes
Accepted solutions (1)
1,326 Views
5 Replies
Replies (5)
Message 2 of 6

scot-65
Advisor
Advisor
One method:
You will need to create a WHILE/COND loop
to be able to switch to the second dialog
(and be able to return back to the first dialog).

Another method:
Use (done_dialog 2) to move to the second dialog.
Consecutive IF statements will get you there.

Where:
(setq sd (start_dialog))

<-- the first dialog is closed at this point -->

And
(if (= sd 0) --> Cancel

(if (= sd 2) --> Open second dialog for input
while in here determine if user input is valid.
If not, done_dialog 0, otherwise done_dialog 1.

(if (= sd 1) --> enter main code block and execute.

Oh, and in your DCL code, is_default=true; appears
more than one time. The last one wins.

???

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

0 Likes
Message 3 of 6

Anonymous
Not applicable

Can you edit my lisp code. I don't have enough experience so can you show me? 

0 Likes
Message 4 of 6

joselggalan
Advocate
Advocate
Accepted solution

Inspect the code step by step to learn how to handle the dialog box.

Attach lsp and dcl files.

in processin process

  code:

;;============================= C:selena ====================================;;
;; Jose L. García G. -  3/22/18                                              ;;
;;===========================================================================;;

(defun ctrls_OnOff (key / )
 (cond
  ((= key "2point")
   (mode_tile "2point_values" 0)
   (mode_tile "center_radius_values" 1)
  )
  ((= key "center_radius")
   (mode_tile "center_radius_values" 0)
   (mode_tile "2point_values" 1)
  )
 )
)

(defun C:selena ( /  idxDlg action)
 (or $option (setq $option "2point"))
 (or $x1 (setq $x1 0.0))
 (or $y1 (setq $y1 0.0))
 (or $x2 (setq $x2 1.0))
 (or $y2 (setq $y2 1.0))
 ;;-------------------
 (or $xr (setq $xr 0.0))
 (or $yr (setq $yr 0.0))
 (or $radius (setq $radius 1.0))
 
 ;;Load dialog box
 
 (if (null pos_Dlg_selena)(setq pos_Dlg_selena '(-1 -1)))
 (if (not (setq idxDlg (load_dialog "selena.dcl")))
  (progn (prompt "\nDCL file can not be loaded.!") (exit))
 )	  
 (setq action T)
 (while action
  (if (not (new_dialog "selena" idxDlg "" pos_Dlg_selena))
   (progn (prompt "\nThe definition can not be loaded.!") (exit))
  )
  ;;_____________________________________________
  ;;dialog box assignments:
  (set_tile "option" $option)
  (ctrls_OnOff $option)
  (set_tile "X1" (rtos $x1))
  (set_tile "Y1" (rtos $y1))
  (set_tile "X2" (rtos $x2))
  (set_tile "Y2" (rtos $y2))
  ;;__
  (set_tile "Xr" (rtos $xr))
  (set_tile "Yr" (rtos $yr))
  (set_tile "radius" (rtos $radius))

  ;;_____________________________________________
  ;;Dialog box actions:
  (action_tile "2point" "(setq $option $key)(ctrls_OnOff $key)")
  (action_tile "center_radius" "(setq $option $key)(ctrls_OnOff $key)")
  ;;2point_values:
  (action_tile "X1" "(setq $x1 (atof $value))")
  (action_tile "Y1" "(setq $y1 (atof $value))")
  (action_tile "X2" "(setq $x2 (atof $value))")
  (action_tile "Y2" "(setq $y2 (atof $value))")
  ;;center_radius_values:
  (action_tile "Xr" "(setq $xr (atof $value))")
  (action_tile "Yr" "(setq $yr (atof $value))")
  (action_tile "radius" "(setq $radius (atof $value))")
  ;;Buttons:
  (action_tile "cancel"  "(setq pos_Dlg_selena (done_dialog 0))")
  (action_tile "DoApply" "(setq pos_Dlg_selena (done_dialog 1))")

  ;;activate dialogue box:
  (setq action (start_dialog))

  ;;_____________________________________________
  (cond
   ((= action 0) ;;click on cancel button
    (setq action nil)
    (unload_dialog idxDlg)
   )
   ((= action 1) ;;click on Make Circle button
    (cond
     ((= $option "2point")
      (command "_.circle" "_2P" (list $x1 $y1) (list $x2 $y2))
     )
     ((= $option "center_radius")
      (command "_.circle" (list $xr $yr) $radius)
     )
    );c.cond
    (princ)
   )
  );c.cond
 );c.while

 (princ)
);c.defun
(princ)
Message 5 of 6

Anonymous
Not applicable

I almost understand your coding but just 1 more thing. Can you explain what is " $action" and "$key" where do you get that from? Esp "$" , is that a symbol for sth?

0 Likes
Message 6 of 6

joselggalan
Advocate
Advocate

 

The action assigned by action_tile supersedes the dialog box's default action (assigned by new_dialog) or the tile's action attribute, if these are specified. The expression can refer to the tile's current value as $value, its name as $key, its application-specific data (as set by client_data_tile) as $data, its callback reason as $reason, and its image coordinates (if the tile is an image button) as $x and $y.

 

2018-03-23_13-00-16.png

 

 

 

 

 

 

 

 

 

 

 

link:

action_tile (AutoLISP/DCL)

 

 I usually use "$" for the variables that remains open in the document to be reused.
$option, $x1, $y1, $x2, $y2, $xr, $yr and $radius are program variables.
Maybe I used another symbol for these and their better understanding.

 

regards.