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

0 Members and 1 Guest are viewing this topic.

bmossman

  • Guest
How to Create a Dialog Box
« on: July 24, 2008, 02:05:58 PM »
Can someone steer me in the right direction on creating a dialog box with check boxes that run script files?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #1 on: July 24, 2008, 02:18:20 PM »
By Script Files, do you mean other lisp routines?

I would think you would want buttons for each routine. But do you want to check several & have then run concurrently?

More explanation is needed. Can you describe the process you want the user to do & what the dialog box is to do for the user?
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 #2 on: July 24, 2008, 02:32:45 PM »
By Script Files, do you mean other lisp routines?

I would think you would want buttons for each routine. But do you want to check several & have then run concurrently?

More explanation is needed. Can you describe the process you want the user to do & what the dialog box is to do for the user?

I have a series of script files that manipulate layering to achieve a certain plan. I would like for a user to  bring up the dialog box and have the option to check multiple plan options that would call the corresponding script commands. See below:

[X]     Site Plan
[  ]     Landscape Plan
[X]     Utility Plan


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #3 on: July 24, 2008, 05:03:57 PM »
Here's a quick example of how to set up the lisp & dcl file.
Download the dcl into a folder in the ACAD search path.
Then load & run the lisp.
You will need to fill in what script action is needed.
Code: [Select]
(defun c:LayerSetUp(/ dclfile dcl# action layers2load)
  (vl-load-com)
  (defun get_checks(/ result)
    (if (= (get_tile "ck1") "1")
      (setq result (cons "Site Plan" result))
    )
    (if (= (get_tile "ck2") "1")
      (setq result (cons "Landscape Plan" result))
    )
    (if (= (get_tile "ck3") "1")
      (setq result (cons "Utility Plan" result))
    )
    result
  )
  ;;================================================================
  ;;                    Start of Routine                           
  ;;================================================================
  (setq dclfile "LayersSetUp.dcl")
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) (prompt (strcat "\nCannot load " dclfile ".")))
    ((not (new_dialog "layersetup" 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
           ;; layers2load = a list of checked items
         )
         (print "User Quit.")
       )
    )
  ) ; end cond
  (princ)
)
(prompt "\nLayer Setup loaded, enter LayerSetUp 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.

Patrick_35

  • Guest
Re: How to Create a Dialog Box
« Reply #4 on: July 25, 2008, 05:04:14 AM »
Hi

You have this great site

@+

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: How to Create a Dialog Box
« Reply #5 on: July 25, 2008, 07:05:10 AM »
James Buzbee
Windows 8

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #6 on: July 28, 2008, 08:25:46 AM »
Here's a quick example of how to set up the lisp & dcl file.
Download the dcl into a folder in the ACAD search path.
Then load & run the lisp.
You will need to fill in what script action is needed.
Code: [Select]
(defun c:LayerSetUp(/ dclfile dcl# action layers2load)
  (vl-load-com)
  (defun get_checks(/ result)
    (if (= (get_tile "ck1") "1")
      (setq result (cons "Site Plan" result))
    )
    (if (= (get_tile "ck2") "1")
      (setq result (cons "Landscape Plan" result))
    )
    (if (= (get_tile "ck3") "1")
      (setq result (cons "Utility Plan" result))
    )
    result
  )
  ;;================================================================
  ;;                    Start of Routine                           
  ;;================================================================
  (setq dclfile "LayersSetUp.dcl")
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) (prompt (strcat "\nCannot load " dclfile ".")))
    ((not (new_dialog "layersetup" 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
           ;; layers2load = a list of checked items
         )
         (print "User Quit.")
       )
    )
  ) ; end cond
  (princ)
)
(prompt "\nLayer Setup loaded, enter LayerSetUp to run.")
(princ)

Thanks Cab...That worked beautifully

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #7 on: July 28, 2008, 08:53:37 AM »
How do you call a script file from within lisp?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #8 on: July 28, 2008, 09:03:10 AM »
If you are talking about another lisp you use
(my-lisp-name) when the lisp starts like this (defun my-lisp-name
or this
(c:my-lisp-name) when the lisp starts like this (defun c:my-lisp-name
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 #9 on: July 28, 2008, 09:09:08 AM »
It's actually a command. Don't I have to call the command function similar to this:

(command "script" "script file name here")

Alan Cullen

  • Guest
Re: How to Create a Dialog Box
« Reply #10 on: July 28, 2008, 09:23:20 AM »
(sorry CAB...about time I joined in here...hope you don't mind)

For invocing a script file...which is a series of commands, then you must issue each command as you would issue a command from within lisp. In other words you have a lisp within a lisp, but not as the same stucture you would use as a script file......

Use this format for each command.....

(command "CHANGE" sspipe "" "P" "C" pen12 "")
(command "chprop" "L" "" "C" ptc "LA" ptlay "" )
(command "COPY" name "" p1 p6)
(command "ELLIPSE" p1 p2 p3)
(command "ERASE" sstxt "")

call it whatever...but comply with CAB's advise...and call it in as CAB suggested.

A script ceases to be a script if you want to invoke it from within a lisp routine.

I really hope that makes sense......... :|

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #11 on: July 28, 2008, 09:28:36 AM »
Ok, I inserted the the command to call the script files, but how do i associate the script file to the corresponding function in the dialog box?

ie, line 5 corresponds to line 33
and line 6 corresponds to line 34

Quote
(defun c:LayerSetUp(/ dclfile dcl# action layers2load)
  (vl-load-com)
  (defun get_checks(/ result)
    (if (= (get_tile "ck1") "1")
      (setq result (cons "Site Plan" result))
    )
    (if (= (get_tile "ck2") "1")
      (setq result (cons "GEOMETRY Plan" result))
    )
    (if (= (get_tile "ck3") "1")
      (setq result (cons "Utility Plan" result))
    )
    result
  )
  ;;================================================================
  ;;                    Start of Routine                           
  ;;================================================================
  (setq dclfile "LayersSetUp.dcl")
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) (prompt (strcat "\nCannot load " dclfile ".")))
    ((not (new_dialog "layersetup" 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")
      (command "script" "M:/Resources/Acad/Scripts/S-SITE.scr")
      (command "script" "M:/Resources/Acad/Scripts/S-GEOM.scr")
          ;;  do you scripr files here
           ;; layers2load = a list of checked items
         )
         (print "User Quit.")
       )
    )
  ) ; end cond
  (princ)
)
(prompt "\nLayer Setup loaded, enter LayerSetUp to run.")
(princ)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #12 on: July 28, 2008, 09:35:30 AM »
Alan, thank you for juping in. :-)

I already typed this so here are my comments:

Usually you would supply the COMMAND with the same information you type at the
ACAD Command Line. Like this:
Code: [Select]
Command: zoom                                                 
                                                             
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window] <real time>: e
       
So the lisp code would look like this:
Code: [Select]
(command "zoom" "e")
You may use Lisp variables to supply arguments to the commands.
Using the ACAD LINE command you might want to have the Lisp supply the points
needed to draw the line. Something like this:
Code: [Select]
(setq pt1 '(0 0))
(setq pt2 '(10 20))
(command "line" pt1 pt2 "")
Note that the "" is the same as pressing the ENTER key when you are entering
information at the command line.

Alan feel free to continue, please.
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 #13 on: July 28, 2008, 09:41:38 AM »
Perhaps this will do what you want.
Note that there are many ways to set this up and this is only one example:
Code: [Select]
(defun c:LayerSetUp(/ dclfile dcl# action layers2load)
  (vl-load-com)
  (defun get_checks(/ result)
    (if (= (get_tile "ck1") "1")
      (setq result (cons "Site Plan" result))
    )
    (if (= (get_tile "ck2") "1")
      (setq result (cons "Landscape Plan" result))
    )
    (if (= (get_tile "ck3") "1")
      (setq result (cons "Utility Plan" result))
    )
    result
  )
  ;;================================================================
  ;;                    Start of Routine                           
  ;;================================================================
  (setq dclfile "LayersSetUp.dcl")
  (cond
    ((< (setq dcl# (load_dialog dclfile)) 0) (prompt (strcat "\nCannot load " dclfile ".")))
    ((not (new_dialog "layersetup" 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
           ;; layers2load = a list of checked items
           (if (member "Site Plan" layers2load)
             (command "script" "M:/Resources/Acad/Scripts/S-SITE.scr")
           )
           (if (member "Landscape Plan" layers2load)
             (command "script" "M:/Resources/Acad/Scripts/S-GEOM.scr")
           )
           (if (member "Utility Plan" layers2load)
             (princ)
           )
         )
         (print "User Quit.")
       )
    )
  ) ; end cond
  (princ)
)
(prompt "\nLayer Setup loaded, enter LayerSetUp 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.

Alan Cullen

  • Guest
Re: How to Create a Dialog Box
« Reply #14 on: July 28, 2008, 09:46:24 AM »
Yup...thanks CAB...I reckon you nailed it

I just thought it was time I earnt my place here...so I will try to help with lisp where I can. I'm still trying to come to grips with the level of knowledge that exists here with regard to lisp.

Alan Cullen

  • Guest
Re: How to Create a Dialog Box
« Reply #15 on: July 28, 2008, 09:53:05 AM »
bmossman,

Care to chuck up the script file that you are trying to call in? We will have a look at it and see if it needs any modification.  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #16 on: July 28, 2008, 10:20:00 AM »
All help is welcome 8-)
Thanks
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.

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #17 on: July 28, 2008, 10:24:40 AM »
Here are a few of them...
Thank you all for your help!

bmossman,

Care to chuck up the script file that you are trying to call in? We will have a look at it and see if it needs any modification.  :-)

Alan Cullen

  • Guest
Re: How to Create a Dialog Box
« Reply #18 on: July 28, 2008, 10:31:02 AM »
oops...didn't help...it was coded.....can you shoot me the ascii format?

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #19 on: July 28, 2008, 10:39:12 AM »
oops...didn't help...it was coded.....can you shoot me the ascii format?

Is there a way to convert to Ascii in notepad?

Alan Cullen

  • Guest
Re: How to Create a Dialog Box
« Reply #20 on: July 28, 2008, 08:18:12 PM »
Doesn't matter....just me being stupid and not looking properly. I opened the zip file in the text editor...that's why it was coded.  :oops:

Yup, your script files need to be re-written so they'll work in a lisp routine. Change this.......

-layer
off
*
Y
on
0,*|0,*DEFPOINTS,*A-COMN-*,*S-COMN-*,*S-GEOM-*
ON
*FEMA*,*PROPERTY*,*LANDLINE*,*WETLAND*,*SAFE*UPLAND*
OFF
*D-*TAG*
S
0
C 1 *MAIN*FH*
C 252 *D-*P-*POND*TOB*

To something like this.....

(command "LAYER" "off" "*" "Y" "on" "0,*|0,*DEFPOINTS,*A-COMN" .....ETC, ETC "")

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #21 on: July 30, 2008, 09:34:41 AM »
Doesn't matter....just me being stupid and not looking properly. I opened the zip file in the text editor...that's why it was coded.  :oops:

Yup, your script files need to be re-written so they'll work in a lisp routine. Change this.......

-layer
off
*
Y
on
0,*|0,*DEFPOINTS,*A-COMN-*,*S-COMN-*,*S-GEOM-*
ON
*FEMA*,*PROPERTY*,*LANDLINE*,*WETLAND*,*SAFE*UPLAND*
OFF
*D-*TAG*
S
0
C 1 *MAIN*FH*
C 252 *D-*P-*POND*TOB*

To something like this.....

(command "LAYER" "off" "*" "Y" "on" "0,*|0,*DEFPOINTS,*A-COMN" .....ETC, ETC "")

I got the dialog to work with the external script files, however when calling the dialog I can't select multiple script files without it saying

"Command: --layer
Unknown command "--LAYER".  Press F1 for help."

For some reason when selecting multiple script files it's attempting to execute the layer command again . (see attachments)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #22 on: July 30, 2008, 09:57:03 AM »
Code: [Select]
"Command: [color=red]--[/color]layer
Unknown command "--LAYER".  Press F1 for help."

This is a typo error. There must be only one minus sign in front of Layer.
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 #23 on: July 30, 2008, 10:04:48 AM »
Code: [Select]
"Command: [color=red]--[/color]layer
Unknown command "--LAYER".  Press F1 for help."

This is a typo error. There must be only one minus sign in front of Layer.


That's what I thought, but each script file calls the layer command like this:

-Layer


jbuzbee

  • Swamp Rat
  • Posts: 851
Re: How to Create a Dialog Box
« Reply #24 on: July 30, 2008, 10:24:23 AM »
bmossman,

looks like your making "layer states" on the fly?  what exactly do these scripts do that you can't do with layer states??
James Buzbee
Windows 8

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to Create a Dialog Box
« Reply #25 on: July 30, 2008, 10:27:27 AM »
Your script files contain extra empty lines at the end and some have  TAB character.
I believe that something is causing the script file to issue an extra ENTER which attempts to execute the last command which is LAYER.
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 #26 on: July 30, 2008, 10:35:26 AM »
Try these revised script files. I eliminated any extra characters at the end.
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 #27 on: July 30, 2008, 10:44:13 AM »
Try these revised script files. I eliminated any extra characters at the end.

It needs the two spaces at the end to complete the layer command.

bmossman

  • Guest
Re: How to Create a Dialog Box
« Reply #28 on: July 30, 2008, 10:55:51 AM »
bmossman,

looks like your making "layer states" on the fly?  what exactly do these scripts do that you can't do with layer states??
I'm old school and have been using scripts for layering since the stone age.
The advantage to using the scripts is it allows the user some flexibility when creating layers on the fly...the scripts will turn on all appropriate layers as long as they have an appropriate prefix.

It's a pain in Layer States manager to continuously update when a new layer is added.



 

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: How to Create a Dialog Box
« Reply #29 on: July 30, 2008, 11:14:11 AM »
Quote
It's a pain in Layer States manager to continuously update when a new layer is added.

Yes it is.

We have pretty nazi-like standards around here so we try not to change to much stuff.  We use a program that was written in-house that uses the Projects Standards DWS file as a "database" for all our approved layers and layer states.
James Buzbee
Windows 8

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.