Jump to content

Recommended Posts

Posted

I have 3 lisp routines in one file

For Example

(defun c:demo1()...................)

(defun c:demo2()...................)

(defun c:demo3()...................)

 

How Can I create a simple dialog box with the 3 lisp routines in a list box and two buttons ( OK & Cancel )?

I want each time I choose, for ex. demo2, from the list box and by pressin OK, the "demo2" lisp routine start running...

 

 

 

Sorry for my bad english..

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    11

  • Lee Mac

    9

  • alanjt

    6

  • tagkelas

    6

Top Posters In This Topic

Posted Images

Posted

Seems like a lot of legwork for something so simple.

Why not just give a choice at the command line?

 

(initget 0 "1 2 3")
(setq demo (getkword "\nSpecify demo number [1/2/3]: "))

Posted
I have 3 lisp routines in one file

For Example

(defun c:demo1()...................)

(defun c:demo2()...................)

(defun c:demo3()...................)

 

How Can I create a simple dialog box with the 3 lisp routines in a list box and two buttons ( OK & Cancel )?

I want each time I choose, for ex. demo2, from the list box and by pressin OK, the "demo2" lisp routine start running...

 

 

 

Sorry for my bad english..

 

Try this out,

Make sure you keep both files together and the are in the ACAD Support Search Path.

Just type Demo.

Demo.dcl

/////////////////////////////////////////////////////////////////////////////////////////////
DEMO : dialog {
      label = "Demo.lsp";
      : column {
        : boxed_column {
          label = "Select a function:";
          : popup_list {
            key = "FUNCT";
            width = 18.0;
            fixed_width = true;
            alignment = centered;
          }
          : spacer {
            height = 0;
          }
        }
        : button {
          label = "&Ok";
          key = "accept";
          width = 18;
          fixed_width = true;
          alignment = centered;
          is_default = true;
        }  
        : button {
          label = "&Exit";
          key = "cancel";
          width = 18;
          fixed_width = true;
          alignment = centered;
          is_cancel = true;
        }
      }
    }
/////////////////////////////////////////////////////////////////////////////////////////////

 

Demo.lsp

(defun C:DEMO (/ DCL_ID FUNCT FUNCT_LIST)
 (or F:UNCT (setq F:UNCT 0))
 (setq FUNCT_LIST (list "Demo 1" "Demo 2" "Demo 3"))
 (setq DCL_ID (load_dialog "DEMO.dcl"))
 (if (not (new_dialog "DEMO" DCL_ID))
   (exit))
 (start_list "FUNCT")(mapcar 'add_list FUNCT_LIST)(end_list)
 (if F:UNCT-DEF (set_tile "FUNCT" (itoa F:UNCT-DEF)))
 (action_tile "accept"
   (strcat
    "(progn (setq F:UNCT (atoi (get_tile \"FUNCT\")) F:UNCT-DEF F:UNCT)"            
           "(done_dialog)(setq button T))"))
 (action_tile "cancel" "(done_dialog)(setq button nil)")
 (start_dialog)
 (unload_dialog DCL_ID)
 (setq FUNCT F:UNCT)
 (if button
   (cond
     ((= FUNCT 0)(ALERT "You selected Demo 1"))
     ((= FUNCT 1)(ALERT "You selected Demo 2"))
     ((= FUNCT 2)(ALERT "You selected Demo 3"))))
 (princ))

Document1.JPG

Posted
Seems like a lot of legwork for something so simple.

Why not just give a choice at the command line?

 

(initget 0 "1 2 3")
(setq demo (getkword "\nSpecify demo number [1/2/3]: "))

 

If I wanted to do this at the command line I could simply write: demo1 or demo2 or.....

 

 

The Buzzard

I think this would be fine.

Can I "put" the demo.dcl file inside the demo.lsp?

Posted

But you still have to invoke a function to load the List_Box - what is the point? :huh:

Posted
If I wanted to do this at the command line I could simply write: demo1 or demo2 or.....

Which is it?

 

Do you want a dialog? or Do you want to run from the command prompt?

Posted
(initget 0 "1 2 3")
(setq demo (getkword "\nSpecify demo number [1/2/3]: "))

But I prefer this way

(initget "1 2 3")
(setq demo (getkword "\nSpecify demo number [1/2/3] <1>: "))

Posted
If I wanted to do this at the command line I could simply write: demo1 or demo2 or.....

 

 

The Buzzard

I think this would be fine.

Can I "put" the demo.dcl file inside the demo.lsp?

If you compile it to an FAS fast load file, Then yes.

Or it would need to be written differently into the lisp.

I prefer the above method.

Posted

This is how I might approach it

 

(defun c:demo (/ dcl_write DATA DC FLAG PTR)
 (vl-load-com)
 
 (setq data '(("demo1" . (c:demo1))
              ("demo2" . (c:demo2))
              ("demo3" . (c:demo3))))

 
 (defun dcl_write (fname / wPath ofile)
   
   (if (not (findfile fname))
     
     (if (setq wPath (findfile "ACAD.PAT"))
       (progn
         (setq wPath (vl-filename-directory wPath))
         
         (or (eq "\\" (substr wPath (strlen wPath)))
             (setq wPath (strcat wPath "\\")))
         
         (setq ofile (open (strcat wPath fname) "w"))
         
         (foreach str '("demo : dialog   { label = \"Select Function\"; spacer;"
                        "     : list_box { key = \"lst\"; } spacer;  ok_cancel; }" )
           
           (write-line str ofile)) (setq ofile (close ofile)) t)
       
       nil)
     
     t))

 (defun Make_list (key lst)
   (start_list key)
   (mapcar (function add_list) lst) (end_list))

 (cond (  (not (dcl_write "LMAC_demo.dcl"))

          (princ "\n** DCL could not be written **"))

       (  (<= (setq dc (load_dialog "LMAC_demo.dcl")) 0)

          (princ "\n** DCL File not Found **"))

       (  (not (new_dialog "demo" dc))

          (princ "\** Dialog Could not be Loaded **"))

       (t (Make_list "lst" (mapcar (function car) data))

          (setq ptr (set_tile "lst" "0"))

          (action_tile "lst" "(setq ptr $value)")

          (setq flag (start_dialog) dc (unload_dialog dc))

          (if (= 1 flag) (eval (cdr (nth (atoi ptr) data))))))

 (princ))

Posted

tagkelas,

 

There you go, try Lee's method.

 

Nice one Lee.

Posted

Thanks Buzzard,

 

It could be shortened further, but I like to perform more error checking to make sure that the dialog has been found and loaded. :)

Posted
Thanks Buzzard,

 

It could be shortened further, but I like to perform more error checking to make sure that the dialog has been found and loaded. :)

The one I posted, I was going to use the method you showed me, But I kind of put that together in a rush.

Posted
The one I posted, I was going to use the method you showed me, But I kind of put that together in a rush.

 

No worries mate :)

Posted
But I prefer this way

(initget "1 2 3")
(setq demo (getkword "\nSpecify demo number [1/2/3] <1>: "))

 

I would normally have a default as well. I was just offering a very basic one.

Posted

Thanks a lot

Both methods are really good

 

The Buzzard

((= FUNCT 0)(ALERT "You selected Demo 1"))

(ALERT "You selected Demo 1") -> Is this the line where should I write the routine?
Posted
Thanks a lot

Both methods are really good

 

The Buzzard

(ALERT "You selected Demo 1") -> Is this the line where should I write the routine?

Yes, You can call out your function there.

 

Example


Local Functions
(cond
 ((= FUNCT 0)(DEMO1))
 ((= FUNCT 1)(DEMO2))
 ((= FUNCT 2)(DEMO3))) 

or

Global Functions
(cond
 ((= FUNCT 0)(C:DEMO1))
 ((= FUNCT 1)(C:DEMO2))
 ((= FUNCT 2)(C:DEMO3)))

 

 

Then it would go to its respected function.

Local Functions
(defun DEMO1 ()
(defun DEMO2 ()
(defun DEMO3 ()

or

Global Functions
(defun C:DEMO1 ()
(defun C:DEMO2 ()
(defun C:DEMO3 ()

Posted

Thanks a lot

 

In Lee Mac's method, how I change the label's "name"?

 

(foreach str '("demo : dialog { label = \"Select Function\"; spacer;"

" : list_box { key = \"lst\"; } spacer; ok_cancel; }" )

 

Select Function?

Posted

Lee,

 

I think he referring to the label called Select Function.

 

It does not seem to change.

Posted

I mean this one:

How do we change it?

demo.jpg

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...