Author Topic: How to Create a Dialog Box  (Read 7662 times)

0 Members and 1 Guest are viewing this topic.

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #30 on: July 30, 2008, 11:47:16 AM »
Ended up adding the commands to the lisp routine in lieu of calling the script files as Allan suggested and it works fine now. Thanks you all for your help!

Code: [Select]
;;==========================================================
           (if (member "Site Plan" layers2load)
             (command "-layer"
"on" "0,*|0,*DEFPOINTS,*A-COMN-*,*S-COMN-*,*S-SITE-*,*P-*TOB*,*MAIN*FH*
*FEMA*,*PROPERTY*,*LANDLINE*,*WETLAND*,*SAFE*UPLAND*"
"C" "1" "*MAIN*FH*"
"C" "252" "*D-*P-*POND*TOB*"
"C" "81" "*S-SITE*P-*TREE* LW 0.50 *S-*P-*TREE*"
"C" "74" "*S-SITE*P-*SHRUB* LW 0.35 *S-*P-*SHRUB*"
"")
   )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #31 on: July 30, 2008, 12:29:31 PM »
Here is another version to try:
Code: [Select]
(defun c:CP(/ dclfile dcl# action layers2load ScrLst MaxChecks)
  (vl-load-com)
 
  ;;  Start with all layers off
  ;(command "-layer" "off" "*" "y" "")
  (command "-layer" "off" "*" "" "")
 
  ;;  Get the check box reference if checked
  (defun get_checks(ckMax / idx sList result)
    ;; Order must match check boxes
    (setq sList '("Site Plan"
                  "Geometry Plan" 
                  "Landscape Plan"   
                  "Water Plan" 
                  "Sanitary Sewer Plan" 
                  "Reuse Water Plan" 
                  "Lift Station Site Plan" 
                  "All Utilities On" 
                  "Mass Grading Plan" 
                  "Predevelopment Plan" 
                  "Surface Water Mgmt Plan" 
                  "Detailed Drainage Plan" 
                  "Roadway Profiles" 
                  "Roadway Details" 
                  "Roadway Sections" 
                 ))
    (setq idx 1) ; 1 through ckMax
    (While (and (<= (setq idx (1+ idx)) ckMax)
           (<= idx (length sList)))
      (if (= (get_tile (strcat "ck" (itoa idx))) "1")
        (setq result (cons (nth (1- idx) sList) result))
      )
    )
    result
  )
  ;;================================================================
  ;;                    Start of Routine                           
  ;;================================================================
  (setq dclfile "ChangePlan.dcl")
  (setq MaxChecks 15) ; check boxes 1-15  <---<< update this number
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) (prompt (strcat "\nCannot load " dclfile ".")))
    ((not (new_dialog "ChangePlan" dcl#)) (prompt (strcat "\nProblem with " dclfile ".")))
    (t ; No DCL problems: fire it up
      ;;  set actions
      (action_tile "accept" ; DCL OK exit action
                   "(setq layers2load (get_checks MaxChecks)) (done_dialog 1)")
      (setq action (start_dialog))
      (unload_dialog dcl#)
      (if (= action 1) ; OK was pressed
        (progn
          (print "OK was pressed")
          ;;  do you scripr files here
          (setq path "M:/Resources/Acad/Scripts/Beta/")
          ;;  This list order does not matter, Case must match
          (setq ScrLst '(("Site Plan"               "S-SITE.scr")
                         ("Geometry Plan"           "Geometry Plan"); <===<< error
                         ("Landscape Plan"          "S-LAND.scr")
                         ("Water Plan"              "u-wat.scr")
                         ("Lift Station Site Plan"  "u-ssls.scr")
                         ("All Utilities On"        "u-allon.scr")
                         ("Mass Grading Plan"       "d-grad.scr")
                         ("Predevelopment Plan"     "d-pred.scr")
                         ("Surface Water Mgmt Plan" "d-swm.scr")
                         ("Detailed Drainage Plan"  "d-dra.scr")
                         ("Roadway Profiles"        "r-prof.scr")
                         ("Roadway Details"         "r-detl.scr")
                         ("Roadway Sections"        "r-sect.scr")
                        ))
          (foreach itm layers2load
            (if (setq scr (cadr (assoc itm ScrLst)))
              (if (vl-catch-all-error-p
                    (setq err (vl-catch-all-apply
                                '(lambda() (command "script" (strcat path scr))))))
                (alert (vl-catch-all-error-message err))
                (princ (strcat "\nLayers set for " itm))
              )
              (princ (strcat "\nNot Found - " itm))
            )
          )

           (princ)
        )
        (print "User Quit.")
      )
    )
  ) ; end cond
  (princ)
)
(prompt "\nLayer Setup loaded, enter CP to run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #32 on: July 30, 2008, 02:17:16 PM »
your latest code works when I select just one script file at a time, but when i select multiple ones it seems to terminate subsequent of turning off all layers.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #33 on: July 30, 2008, 02:45:32 PM »
I'm still kicking this around. I'll let you know what I come up with.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #34 on: July 30, 2008, 03:45:39 PM »
Yet another version.
Rather than call the Script File, this version reads the script file & attempts to execute each
item in the script as a command.

Code: [Select]
;;  CAB 07/30/2008 Version 1.3
;;  Dialog Box for layer setups
;;  Reads a Script file & executes each item as a COMMAND

(defun c:CP(/ dclfile dcl# action layers2load ScrLst err path scr
            lst nlst File2list sparser)
  (vl-load-com)
 
  ;;  TxtFile2List by CAB
  (defun File2list (filename / handle stream FileData)
    (if
      (and
        (eq 'str (type filename))
        (setq filename (findfile filename))
        (setq handle (open filename "r"))
      )
       (progn
         (while (setq stream (read-line handle))
                  (setq  FileData (cons stream FileData))
         ) ; while
         (close handle)
       ) ; progn
    ) ; endif
    (reverse FileData)
  )
 
  ;;  CAB 10.22.2007
  ;;  ignore quoted sections of the string
  (defun sparser (str delim / ok c new$ plst)
    (setq ok t
          new$ ""
    )
    (while (/= str "")
      (setq c   (substr str 1 1)
            str (substr str 2))
      (cond
        ((= c "\"")
         (setq new$ (strcat new$ c)
               ok (null ok)))
        ((and ok (= c delim))
         (setq plst   (cons new$ plst)
               new$ ""))
        ((setq new$ (strcat new$ c)))
      )
    )
    (reverse (cons new$ plst))
  )
 
  ;;  Start with all layers off
  ;(command "-layer" "off" "*" "y" "")
  (command "-layer" "off" "*" "" "")
 
  ;;  Get the check box reference if checked
  (defun get_checks(/ idx sList result ckMax)
    ;; Order must match check boxes
    (setq sList '("Site Plan"
                  "Geometry Plan" 
                  "Landscape Plan"   
                  "Water Plan" 
                  "Sanitary Sewer Plan" 
                  "Reuse Water Plan" 
                  "Lift Station Site Plan" 
                  "All Utilities On" 
                  "Mass Grading Plan" 
                  "Predevelopment Plan" 
                  "Surface Water Mgmt Plan" 
                  "Detailed Drainage Plan" 
                  "Roadway Profiles" 
                  "Roadway Details" 
                  "Roadway Sections" 
                 ))
    (setq ckMax (length sList))
    (setq idx 0) ; 1 through ckMax
    (While (and (<= (setq idx (1+ idx)) ckMax)
           (<= idx (length sList)))
      (if (= (get_tile (strcat "ck" (itoa idx))) "1")
        (setq result (cons (nth (1- idx) sList) result))
      )
    )
    result
  )
  ;;================================================================
  ;;                    Start of Routine                           
  ;;================================================================
  (setq dclfile "ChangePlan.dcl")
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) (prompt (strcat "\nCannot load " dclfile ".")))
    ((not (new_dialog "ChangePlan" dcl#)) (prompt (strcat "\nProblem with " dclfile ".")))
    (t ; No DCL problems: fire it up
      ;;  set actions
      (action_tile "accept" ; DCL OK exit action
                   "(setq layers2load (get_checks)) (done_dialog 1)")
      (setq action (start_dialog))
      (unload_dialog dcl#)
      (if (= action 1) ; OK was pressed
        (progn
          (print "OK was pressed")
          ;;  do you scripr files here
          ;(setq path "M:/Resources/Acad/Scripts/Beta/")
          (setq path "C:/Program Files/ACAD2000/LISP Routines/SubRoutines/temp/")
          ;;  This list order does not matter, Case must match
          (setq ScrLst '(("Site Plan"               "S-SITE.scr")
                         ("Geometry Plan"           "Geometry Plan"); <===<< error
                         ("Landscape Plan"          "S-LAND.scr")
                         ("Water Plan"              "u-wat.scr")
                         ("Lift Station Site Plan"  "u-ssls.scr")
                         ("All Utilities On"        "u-allon.scr")
                         ("Mass Grading Plan"       "d-grad.scr")
                         ("Predevelopment Plan"     "d-pred.scr")
                         ("Surface Water Mgmt Plan" "d-swm.scr")
                         ("Detailed Drainage Plan"  "d-dra.scr")
                         ("Roadway Profiles"        "r-prof.scr")
                         ("Roadway Details"         "r-detl.scr")
                         ("Roadway Sections"        "r-sect.scr")
                        ))
          (foreach itm layers2load
            (if (setq scr (cadr (assoc itm ScrLst)))
              (progn
                (setq lst (File2list (strcat path scr))) ; read the script file
                ;; create a list of command entries as a list of strings
                ;; uses space as a delimiter except within quotes and will
                ;; ignore comment lines in the script
                (mapcar '(lambda(x) (cond
                                      ((= (substr x 1 1) "(") ; LISP in this line
                                       (if nLst
                                         (setq nlst (append nlst (list (read x))))
                                         (setq nlst (list (read x)))
                                       )
                                      )
                                      ((/= (substr x 1 1) ";") ; ignore comment line
                                      (if nlst
                                        (setq nlst (append nlst (sparser x " ")))
                                        (setq nlst (sparser x " "))
                                    )))) lst)
                ;; Execute each command entry from the script file
                (if (vl-catch-all-error-p
                      (setq err (vl-catch-all-apply
                                  '(lambda()
                                     (foreach ln nlst
                                       (if (listp ln)
                                         (eval ln)
                                         (command ln)
                                       )
                                     )
                                     ;;(command) ; make sure command is terminated
                                     ))))
                (alert (vl-catch-all-error-message err))
                (princ (strcat "\nLayers set for " itm))
              )
              )
              (princ (strcat "\nNot Found - " itm))
            )
          )
          (princ)
        ) ; progn
        (print "User Quit.")
      )
    )
  ) ; end cond
  (princ)
)
(prompt "\nLayer Setup loaded, enter CP to run.")
(princ)

<edit: fixed typo>
« Last Edit: July 31, 2008, 12:10:19 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #35 on: July 30, 2008, 11:52:20 PM »
I did find this in the help file:
Quote
If the SCRIPT command is used with the command function, it should be the last function call in the AutoLISP routine.
So that may be the reason you can not run more than one script from within a lisp.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #36 on: July 31, 2008, 01:27:15 PM »
Thanks for your help CAB :-D
How do you format the dcl file to include tabs, borders, etc...
Is there a program that will allow you to graphically build the dialog box? 

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: How to Create a Dialog Box
« Reply #37 on: August 01, 2008, 07:09:18 AM »
« Last Edit: August 01, 2008, 09:54:57 AM by jbuzbee »
James Buzbee
Windows 8

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #38 on: August 01, 2008, 08:19:12 AM »
Thanks for your help CAB :-D
How do you format the dcl file to include tabs, borders, etc...
Is there a program that will allow you to graphically build the dialog box? 

You're welcome.

With DCL it is trial and error.
Open the DCL in VLIDE & use the pull down Tools/Interface Tools/Preview DCL in Editor
Note that you must save any changes before you can view them.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #39 on: August 01, 2008, 08:23:48 AM »
Here is a simple change
Code: [Select]
ChangePlan : dialog { label = "  Drawing Layer Setup" ;
: boxed_row { label = "Check all that apply" ;
 : column {
  : toggle { key = "ck1" ; label = "S-Site Plan" ;}
  : toggle { key = "ck2" ; label = "S-Geometry Plan" ;}
  : toggle { key = "ck3" ; label = "S-Landscape Plan" ;}
  : toggle { key = "ck4" ; label = "U-Water Plan" ;}
  : toggle { key = "ck5" ; label = "U-Sanitary Sewer Plan" ;}
  : toggle { key = "ck6" ; label = "U-Reuse Water Plan" ;}
  : toggle { key = "ck7" ; label = "U-Lift Station Site Plan" ;}
  : toggle { key = "ck8" ; label = "U-All Utilities On" ;}
 }
 : column {
  : toggle { key = "ck9" ; label = "D-Mass Grading Plan" ;}
  : toggle { key = "ck10" ; label = "D-Predevelopment Plan" ;}
  : toggle { key = "ck11" ; label = "D-Surface Water Mgmt Plan" ;}
  : toggle { key = "ck12" ; label = "D-Detailed Drainage Plan" ;}
  : toggle { key = "ck13" ; label = "R-Roadway Profiles" ;}
  : toggle { key = "ck14" ; label = "R-Roadway Details" ;}
  : toggle { key = "ck15" ; label = "R-Roadway Sections" ;}
  spacer_1;
 }
}
ok_cancel;
}
   
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #40 on: August 01, 2008, 08:28:05 AM »
This is the result.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.