TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cadplayer on March 21, 2013, 08:29:09 AM

Title: Is there a DCL-editor
Post by: cadplayer on March 21, 2013, 08:29:09 AM
Hello!

I have began with OpenDCL and I like the comfortable way to create own menu. Have the simple DCL a menuEditor too ? Or how create buttons, listbox... with right size and position, is there any trick to do them easier ?

I found this testRoutine which can control a DCLmenu as all have that it does it looks like.
But how create a menu with DCL.

Code: [Select]
(defun c:testdcl (/ nam$ nam id loop)
;;; lisp for checking dialogboxes at the beginning of their design
  (setq nam$ (getfiled "Select a DCL file" "" "dcl" 0))
  (setq nam (identify nam$))
)
(defun identify (nam$ / file x dd dd$)
  (setq file (open nam$ "r")
dd$  nil
dd   nil
x    0
  )
  (while (setq dd (read-line file))
    (if (wcmatch dd "*: dialog {")
      (progn
(setq dd$ (substr dd 1 (- (strlen dd) 11)))
(if (wcmatch dd$ " *")
  (setq dd$ (substr dd$ 2 (strlen dd$)))
  ;; added for eliminating blank
)
(rundcl nam$ dd$)
      )


    )

  )
  (close file)
  dd$
)
(defun rundcl (nam$ nam)
  (setq id (load_dialog nam$))
  (if (not (new_dialog nam id))
    (exit)
  )
  (action_tile "cancel" "(done_dialog 0)")
;;; cancel button dialog.. normally in all DCLs
  (action_tile "accept" "(done_dialog 0)")
;;; accept button dialog.. normally in all DCLs
  (setq loop (start_dialog))


Title: Re: Is there a DCL-editor
Post by: Lee Mac on March 21, 2013, 08:38:56 AM
I've seen a number of applications in the past which claim to offer a 'WYSIWYG' DCL editor for AutoCAD, however, I've never tried such applications and am not aware of any mainstream DCL editors, other than using a standard code editing application.

I personally write DCL using the VLIDE which conveniently has an in-built DCL preview utility.
Title: Re: Is there a DCL-editor
Post by: cadplayer on March 21, 2013, 08:46:03 AM
Hi Lee!
Do I understand you that VLIDE have a preview-methode for DCL-files.
Title: Re: Is there a DCL-editor
Post by: Lee Mac on March 21, 2013, 08:48:48 AM
Do I understand you that VLIDE have a preview-methode for DCL-files.

Yes, open the DCL file in the VLIDE and go to Tools ŧ Interface Tools ŧ Preview DCL in Editor
Title: Re: Is there a DCL-editor
Post by: cadplayer on March 21, 2013, 09:03:56 AM
that is great, I didnīt know this. When you start create a new dialogbox, what are you think about:
1- which type buttons, listbox, graphic... I need
2- set entities in right position
3- finally test the dcl exactly after your explantion
Title: Re: Is there a DCL-editor
Post by: Lee Mac on March 21, 2013, 09:27:12 AM
Generally, when designing a GUI, I tend to follow the following thought process:
That's simply my personal way of approaching DCL dialog design, with many other tricks and shortcuts incorporated over the years to speed up the process and obtain a cleaner and neater end result; I'm sure everyone has their own methodology which has evolved over the course of their learning.
Title: Re: Is there a DCL-editor
Post by: cadplayer on March 21, 2013, 10:28:42 AM
Thanks Lee! I have done my first try with DCL and have now simple question, I type in values in 3 textboxes but where can I request them to get my result ?

Code: [Select]
(defun c:TEST ( / dcl_id fn fname)
    (vl-load-com)
    (create_dialog)
    (setq dcl_id (load_dialog fname))
    (if (not (new_dialog "VolymCalculate" dcl_id))
        (exit )
        )
   
    (set_tile "Text1" "Enter length [m]")
    (mode_tile "Text1" 2)
    (action_tile "Text1" "(setq Text1 $value)")
   
    (set_tile "Text2" "Enter width [m]")
    (mode_tile "Text2" 2)
    (action_tile "Text2" "(setq Text2 $value)")

    (set_tile "Text3" "Enter heiht [m]")
    (mode_tile "Text3" 2)
    (action_tile "Text3" "(setq Text3 $value)")

    (start_dialog)
    (unload_dialog dcl_id)

    (alert (strcat "Volum is " " m" (chr 179)))
    (vl-file-delete fname)
    (princ)
    )

-------------------

(defun create_dialog ()
    (setq fname (vl-filename-mktemp "dcl.dcl"))
    (setq fn (open fname "w"))
    (write-line
       
  "VolymCalculate : dialog {
  label = \"Calculate volym\";
  spacer;
  : row { fixed_width = true;
    : column { width = 17.5; spacer;
      : text { key = \"Text1\"; }
    }
    : edit_box { edit_width = 6.5;
      key = \"Edit1\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5; spacer;
      : text { key = \"Text2\"; }
    }
    : edit_box { edit_width = 6.5;
      key = \"Edit2\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5; spacer;
      : text { key = \"Text3\"; }
    }
    : edit_box { edit_width = 6.5;
      key = \"Edit3\";
    }
  }
  spacer;
  : row {
    : column {
      : ok_button { width = 11;
        alignment = right;
      }
    }
    : column {
      : cancel_button { width = 11;
        alignment = left;
      }
    }
  }
}" fn)
    (close fn)
    (princ)
    )
           
Title: Re: Is there a DCL-editor
Post by: kruuger on March 21, 2013, 01:01:15 PM
Thanks Lee! I have done my first try with DCL and have now simple question, I type in values in 3 textboxes but where can I request them to get my result ?

Code: [Select]
(defun c:TEST ( / dcl_id fn fname)
    (vl-load-com)
    (create_dialog)
    (setq dcl_id (load_dialog fname))
    (if (not (new_dialog "VolymCalculate" dcl_id))
        (exit )
        )
   
    (set_tile "Text1" "Enter length [m]")
    (mode_tile "Text1" 2)
    (action_tile "Text1" "(setq Text1 $value)")
   
    (set_tile "Text2" "Enter width [m]")
    (mode_tile "Text2" 2)
    (action_tile "Text2" "(setq Text2 $value)")

    (set_tile "Text3" "Enter heiht [m]")
    (mode_tile "Text3" 2)
    (action_tile "Text3" "(setq Text3 $value)")

    (start_dialog)
    (unload_dialog dcl_id)

    (alert (strcat "Volum is " " m" (chr 179)))
    (vl-file-delete fname)
    (princ)
    )

-------------------

(defun create_dialog ()
    (setq fname (vl-filename-mktemp "dcl.dcl"))
    (setq fn (open fname "w"))
    (write-line
       
  "VolymCalculate : dialog {
  label = \"Calculate volym\";
  spacer;
  : row { fixed_width = true;
    : column { width = 17.5; spacer;
      : text { key = \"Text1\"; }
    }
    : edit_box { edit_width = 6.5;
      key = \"Edit1\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5; spacer;
      : text { key = \"Text2\"; }
    }
    : edit_box { edit_width = 6.5;
      key = \"Edit2\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5; spacer;
      : text { key = \"Text3\"; }
    }
    : edit_box { edit_width = 6.5;
      key = \"Edit3\";
    }
  }
  spacer;
  : row {
    : column {
      : ok_button { width = 11;
        alignment = right;
      }
    }
    : column {
      : cancel_button { width = 11;
        alignment = left;
      }
    }
  }
}" fn)
    (close fn)
    (princ)
    )
           

Code: [Select]
1. (action_tile "accept" "(if (CheckVal) (done_dialog))")2.then
Code: [Select]
(defun (CheckVal) ()
- get all tiles value with (get_tile "TextX")
- if one of them is empty display alert or add errtile (error tile) under ok_cancel button
- convert all text values to real
- CheckVal should return T or nil
)
one of possible solution
kruuger
Title: Re: Is there a DCL-editor
Post by: fixo on March 21, 2013, 01:02:27 PM
Hi dude, I would like use dcl along this way,
save dcl in the current folder and use private subroutines
within main program, e.g.:
Code: [Select]
(defun c:test ( / create_dialog dcl_id run_dcl);; keep 'fname' as global

(defun create_dialog ()
    (setq fb (vl-filename-base (getvar "dwgname")))
    (setq fname (strcat (getvar "dwgprefix") fb  ".dcl"));; better to create dcl in current folder for debug !
    ;;(setq fname (vl-filename-mktemp "dcl.dcl"))
    (setq fn (open fname "w"))
    (write-line
   "//dcl_settings : default_dcl_settings { audit_level = 3; } //Remember to strip out the dcl_settings line before shipping DCL files to users.     
  VolymCalculate : dialog {
  label = \"Calculate volym\";
  spacer;
  : row { fixed_width = true;
    : column { width = 17.5;
      : text { width = 10; key = \"Text1\"; }
    }
    : edit_box {  edit_width = 6.5;  key = \"leng\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5;
      : text { width = 10; key = \"Text2\"; }
    }
    : edit_box {  edit_width = 6.5; key = \"wid\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5;
      : text { width = 10; key = \"Text3\"; }
    }
    : edit_box {  edit_width = 6.5;  key = \"hgt\";
    }
  }
  spacer;
  : row {
    : column {
      : ok_button { width = 11;
        alignment = right;
      }
    }
    : column {
      : cancel_button { width = 11;
        alignment = left;
      }
    }
  }
}" fn)
    (close fn)
    (princ)
    )

 
  (defun run_dcl (fname / hgt leng result wid)

  (if (<= (setq dcl_id (load_dialog fname)) 0)
      (alert "Error loading DCL file.")
    )

(if (not (new_dialog "VolymCalculate" dcl_id))
      (alert "Error loading  dialog."))
 (set_tile "Text1" "Enter length [m]")
    (set_tile "Text2" "Enter width [m]")
   
  (action_tile "leng" "(setq leng $value)")
(action_tile "wid" "(setq wid $value)")
    (set_tile "Text3" "Enter heiht [m]")
 (action_tile "hgt" "(setq hgt $value)")
      (action_tile "OK" "(done_dialog 1)")
      (action_tile "CANCEL" "(done_dialog 0)")
      (setq result (start_dialog))
      (unload_dialog dcl_id)
  (if (= result 1)
  (if (and leng wid hgt)
   (setq data(list leng wid hgt))
 
  (setq data nil)
 )
    )
  data
    )

;; main part   ;;

 
    (create_dialog)
  (setq lst (run_dcl fname))
  (setq lst (mapcar 'atof lst))
(alert (strcat "\nVolume is " (rtos (* (car lst) (cadr lst) (caddr lst)) 2 3) " m" (chr 179)))
(vl-file-delete fname)
    (princ)
    )

;;   ;;
Title: Re: Is there a DCL-editor
Post by: cadplayer on March 21, 2013, 01:33:02 PM
Thanks guys for big helping, the mainstream is clear but here there are some obscurities.

fixo, very nice also for error handling (sometimes itīs to easy)
But here in the end of your code I donīt understand why I must have 3 variables (leng wid hgt) more ?
what it means
set_tile ... set a value
action_tile ... get a value

or miss I something ?

Code: [Select]
(if (not (new_dialog "VolymCalculate" dcl_id))
      (alert "Error loading  dialog."))
 (set_tile "Text1" "Enter length [m]")
    (set_tile "Text2" "Enter width [m]")
   
  (action_tile "leng" "(setq leng $value)")
(action_tile "wid" "(setq wid $value)")
    (set_tile "Text3" "Enter heiht [m]")
 (action_tile "hgt" "(setq hgt $value)")
      (action_tile "OK" "(done_dialog 1)")
      (action_tile "CANCEL" "(done_dialog 0)")
      (setq result (start_dialog))
      (unload_dialog dcl_id)
  (if (= result 1)
  (if (and leng wid hgt)
   (setq data(list leng wid hgt))
 
  (setq data nil)
 )
    )
  data
    )
Title: Re: Is there a DCL-editor
Post by: fixo on March 21, 2013, 01:52:31 PM
I've forgot to add 'data' to globals,
here is one with addition, it will let you
click Enter to jump up to next textbox:
Code: [Select]
(defun c:test ( / create_dialog data dcl_id run_dcl);; keep 'fname' as global

(defun create_dialog ()
    (setq fb (vl-filename-base (getvar "dwgname")))
    (setq fname (strcat (getvar "dwgprefix") fb  ".dcl"));; better to create dcl in current folder for debug !
    ;;(setq fname (vl-filename-mktemp "dcl.dcl"))
    (setq fn (open fname "w"))
    (write-line
   "//dcl_settings : default_dcl_settings { audit_level = 3; } //Remember to strip out the dcl_settings line before shipping DCL files to users.     
  VolymCalculate : dialog {
  label = \"Calculate volym\";
  spacer;
  : row { fixed_width = true;
    : column { width = 17.5;
      : text { width = 10; key = \"Text1\"; }
    }
    : edit_box {  edit_width = 6.5;  key = \"leng\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5;
      : text { width = 10; key = \"Text2\"; }
    }
    : edit_box {  edit_width = 6.5; key = \"wid\";
    }
  }
  : row { fixed_width = true;
    : column { width = 17.5;
      : text { width = 10; key = \"Text3\"; }
    }
    : edit_box {  edit_width = 6.5;  key = \"hgt\";
    }
  }
  spacer;
  : row {
    : column {
      : ok_button { width = 11;
        alignment = right;
      }
    }
    : column {
      : cancel_button { width = 11;
        alignment = left;
      }
    }
  }
}" fn)
    (close fn)
    (princ)
    )

 
  (defun run_dcl (fname / hgt leng result wid)

  (if (<= (setq dcl_id (load_dialog fname)) 0)
      (alert "Error loading DCL file.")
    )

(if (not (new_dialog "VolymCalculate" dcl_id))
      (alert "Error loading  dialog."))
(set_tile "Text1" "Enter length [m]")
(set_tile "Text2" "Enter width [m]")
(set_tile "Text3" "Enter heiht [m]")
(mode_tile "leng" 2)
(action_tile "leng" "(setq leng $value)(if (/= $reason 2)(mode_tile \"wid\" 2))")
(action_tile "wid" "(setq wid $value)(if (/= $reason 2)(mode_tile \"hgt\" 2))")
(action_tile "hgt" "(setq hgt $value)(if (/= $reason 2)(mode_tile \"OK\" 2))")
      (action_tile "OK" "(done_dialog 1)")
      (action_tile "CANCEL" "(done_dialog 0)")
      (setq result (start_dialog))
      (unload_dialog dcl_id)
  (if (= result 1)
    (if (and leng wid hgt)
      (setq data (list leng wid hgt))

      (setq data nil)
      )
    )
  data
    )


;; main part   ;;

 
    (create_dialog)
  (setq lst (run_dcl fname))
  (setq lst (mapcar 'atof lst))
(alert (strcat "\nVolume is " (rtos (* (car lst) (cadr lst) (caddr lst)) 2 3) " m" (chr 179)))
(vl-file-delete fname)
    (princ)
    )

;;   ;;
Title: Re: Is there a DCL-editor
Post by: cadplayer on March 22, 2013, 08:22:33 AM
Thanks fixo "fixed all" - Sure comes little questions - at the moment up to busy. Thanks for your comments ... see later