TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andy_lee on March 17, 2017, 08:13:25 AM

Title: A question about an DCL example.
Post by: andy_lee on March 17, 2017, 08:13:25 AM
Hi
Dear friend. I see a DCL example at "web2.airmail.net" .


Code: [Select]

//---------------------------------------------------------------------------------------------------------
// MyYesNo
// Note: The width for the Text1 key was determined by the syntax example and
// will need to be changed as per your requirements. Also note that the buttons
// for Yes and No, the added fixed_width = true;.
//---------------------------------------------------------------------------------------------------------
MyYesNo : dialog {
  key = "Title";
  label = "";//Title$ from lsp file
  spacer;
  : text {
    key = "Text1";
    label = "";//Question$ from lsp file
    width = 35.0;
    alignment = centered;
  }
  spacer;
  : row {
    fixed_width = true;
    alignment = centered;
    : button {
      key = "Yes";
      label = "&Yes";
      is_default = true;
      width = 7.92;
      fixed_width = true;
    }
    : button {
      key = "No";
      label = "&No";
      is_cancel = true;
      width = 7.92;
      fixed_width = true;
    }
  }
}//MyYesNo

Code: [Select]
;----------------------------------------------------------------------------------------------------------
; MyYesNo - Question dialog with one question line
; Arguments: 2
;   Title$ = Dialog Title
;   Question$ = Question line
; Syntax: (MyYesNo " My Yes No" "Do you like creating programs in AutoLISP?")
;----------------------------------------------------------------------------------------------------------
(defun MyYesNo (Title$ Question$ / Answer$ Dcl_Id% Return#)
  (princ "\nMyYesNo")(princ)
  ; Load Dialog
  (setq Dcl_Id% (load_dialog "MyDialogs.dcl"))
  (new_dialog "MyYesNo" Dcl_Id%)
  ; Set Dialog Initial Settings
  (set_tile "Title" Title$)
  (set_tile "Text1" Question$)
  ; Dialog Actions
  (action_tile "Yes" "(done_dialog 1)")
  (action_tile "No" "(done_dialog 0)")
  (setq Return# (start_dialog))
  ; Unload Dialog
  (unload_dialog Dcl_Id%)
  (if (= Return# 1)
    (setq Answer$ "Yes")
    (setq Answer$ "No")
  );if
  (princ "\n")(princ Answer$)(princ);Optional
  Answer$
);defun MyYesNo

usage:
Code: [Select]
(MyYesNo " My Yes No" "Do you like creating programs in AutoLISP?")
"My Yes No" is Title.
"Do you like creating programs in AutoLISP?" is message need to display.   I want use a variable[ eg: (getvar "dwgprefix") ]  in this message .  How do it ?
Title: Re: A question about an DCL example.
Post by: Peter2 on March 17, 2017, 09:36:59 AM
To concatenate strings usually strcat is used:

Code - Auto/Visual Lisp: [Select]
  1. (MyYesNo " My Yes No" (strcat "Do you want to open "  (getvar "dwgprefix") " now?")
(Untested ...)
Title: Re: A question about an DCL example.
Post by: andy_lee on March 17, 2017, 10:43:30 AM
To concatenate strings usually strcat is used:

Code - Auto/Visual Lisp: [Select]
  1. (MyYesNo " My Yes No" (strcat "Do you want to open "  (getvar "dwgprefix") " now?")
(Untested ...)

Thanks Peter . Nice !
The result is
Code: [Select]
Do you want to open  C:\\Users\\Administrator\\Documents\\ now?"
But I want like this

Code: [Select]
Do you want to open  "C:\\Users\\Administrator\\Documents\\" now?"

possible?
Title: Re: A question about an DCL example.
Post by: Lee Mac on March 17, 2017, 01:33:36 PM
Escape the double-quotes using a backslash, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (MyYesNo " My Yes No" (strcat "Do you want to open \""  (getvar "dwgprefix") "\" now?")
Title: Re: A question about an DCL example.
Post by: andy_lee on March 19, 2017, 09:47:51 AM
Escape the double-quotes using a backslash, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (MyYesNo " My Yes No" (strcat "Do you want to open \""  (getvar "dwgprefix") "\" now?")

Thanks  Lee,  you are so smart.
Title: Re: A question about an DCL example.
Post by: efernal on March 21, 2017, 04:49:10 PM
Code - Auto/Visual Lisp: [Select]
  1. ;;try
  2. (acet-ui-message "message" "title" 36)
  3. ;;6 for yes, 7 for no
  4. ;;no dcl needed...
  5.  
  6.