Jump to content

Yes No Dialog Box to run seperate functions


Cylis0509

Recommended Posts

.. or if you have express tools loaded, try something like this ..


(SETQ reply (ACET-UI-MESSAGE "Choose dude "
                             "Russells Dialog"
                             (+ Acet:YESNOCANCEL Acet:ICONWARNING)
            )
)
;; Yes = 6
;; No = 7
;; Cancel = 2
(IF (= reply 6)
 (PROGN (ALERT "Yep")
        ;;
        ;; More Yes Mojo
 )
 ;; else
 (PROGN (ALERT "Nope")
        ;;
        ;; More no mojo
 )
)

 

 

How do I get this to "call/goto" another defun within the same lisp. When I try it, it tells me ; error: no function definition:

 

(vl-load-com)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(SETQ reply1 (ACET-UI-MESSAGE (strcat  "Some Text")
                  "Some Header" 36))
(IF (= reply1 6) (c:mos2nsc))
(IF (= reply1 7) (c:runlater))
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:mos2nsc ( / )
(SETQ reply2 (ACET-UI-MESSAGE (strcat  "Some Text")
                               "Some Header" 20))
(IF (= reply2 6) (c:replyyes))
(IF (= reply2 7) (c:runlater))
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:replyyes ( / of_epk of_pt)
(setvar "cmdecho" 0)
(if (null of_dist) (setq of_distx 1.0))
(initget 6)
(if (null (setq of_dist (getdist (strcat "\nPlease Enter the Offset Distance <>: "))))
(setq of_dist of_distx)
)
(setq of_distx of_dist)
(if (null of_elev) (setq of_elevx 0.0))
(if (null (setq of_elev (getreal (strcat "\nPlease Enter the Elevation Difference - For a Negative Use a '-' <>: "))))
(setq of_elev of_elevx)
)
(setq of_elevx of_elev)
(while (or (setq of_epk (entsel)) (eq 7 (getvar "errno")))
(if (and of_epk
(member (cdr (assoc 100 (reverse (entget (car of_epk)))))
'("AcDbPolyline" "AcDb2dPolyline"))
(setq of_pt (getpoint "\nPlease Select the Side to offset: "))
)
(command "_.offset" of_dist of_epk of_pt "" "_.move" (entlast) ""
(list 0.0 0.0 of_elev) "")
)
)
(princ)
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:runlater ( / )
(acet-ui-message "To run later, type 'MOS2NSC' anytime to begin to conversion process." "Some Header" 64)
)

Edited by SLW210
  • Like 1
Link to comment
Share on other sites

Hi,

 

 

I'm having trouble with a current LISP I'm working on. I found some code on this site for yes/no dialog/alert boxes. I am trying to modify it so each button will jump to a different section/different DEFUN within the same lisp. When I run it, it states that the functions do not existing. I have it set up to launch a yes/no box on load. Click yes to run now, click no to run later. When I click no I get: ; error: no function definition: C:RUNLATER. I hope someone can help me out.

 

 

Thank you!

 

 

(vl-load-com)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(SETQ reply1 (ACET-UI-MESSAGE (strcat  "Some Text")
                  "Some Header" 36))
(IF (= reply1 6) (c:mos2nsc))
(IF (= reply1 7) (c:runlater))
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:mos2nsc ( / )
(SETQ reply2 (ACET-UI-MESSAGE (strcat  "Some Text")
                               "Some Header" 20))
(IF (= reply2 6) (c:replyyes))
(IF (= reply2 7) (c:runlater))
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:replyyes ( / of_epk of_pt)
(setvar "cmdecho" 0)
(if (null of_dist) (setq of_distx 1.0))
(initget 6)
(if (null (setq of_dist (getdist (strcat "\nPlease Enter the Offset Distance <>: "))))
(setq of_dist of_distx)
)
(setq of_distx of_dist)
(if (null of_elev) (setq of_elevx 0.0))
(if (null (setq of_elev (getreal (strcat "\nPlease Enter the Elevation Difference - For a Negative Use a '-' <>: "))))
(setq of_elev of_elevx)
)
(setq of_elevx of_elev)
(while (or (setq of_epk (entsel)) (eq 7 (getvar "errno")))
(if (and of_epk
(member (cdr (assoc 100 (reverse (entget (car of_epk)))))
'("AcDbPolyline" "AcDb2dPolyline"))
(setq of_pt (getpoint "\nPlease Select the Side to offset: "))
)
(command "_.offset" of_dist of_epk of_pt "" "_.move" (entlast) ""
(list 0.0 0.0 of_elev) "")
)
)
(princ)
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:runlater ( / )
(acet-ui-message "To run later, type 'MOS2NSC' anytime to begin to conversion process." "Some Header" 64)
)

Edited by Cylis0509
Link to comment
Share on other sites

Modify you reply to include the CODE TAGS for your codes .

 

You received that error message because the required function or routine wasn't loaded yet when the first part of your codes did , so if you try it again it should run normally.

 

Replace the first part of your codes to the bottom and try again .

Link to comment
Share on other sites

Modify you reply to include the CODE TAGS for your codes .

 

You received that error message because the required function or routine wasn't loaded yet when the first part of your codes did , so if you try it again it should run normally.

 

Replace the first part of your codes to the bottom and try again .

 

 

 

Thank you for the reply! I tried to use the "#" button but it didn't do anything. I was trying to figure out how to do the code boxes like you guys. I apologize for that.

 

 

As for the code you are right. When I put the "opening" message at the end of my code it works like a dream. Thank you.

 

 

My next question though is; because of my OCD :) I would really like the "opening" message at the beginning of my code. Is there a way to preload the other functions at the beginning?

Link to comment
Share on other sites

As Tharwat has indicated, the following expressions are evaluated when loading the program:

(SETQ reply1 (ACET-UI-MESSAGE (strcat  "Some Text") "Some Header" 36))
(IF (= reply1 6) (c:mos2nsc))
(IF (= reply1 7) (c:runlater))

However, the functions that you are attempting to evaluate based on the user's response [ (c:mos2nsc) & (c:runlater) ] are not yet evaluated, as the defun expressions appear after the expressions that are being evaluated when loading.

Link to comment
Share on other sites

Thank you guys this is very helpful!! I really appreciate it.

 

 

My next question though is; because of my OCD :) I would really like the "opening" message at the beginning of my code. Is there a way to preload/pre-evaluate the defun expressions at the beginning?

Link to comment
Share on other sites

My next question though is; because of my OCD :) I would really like the "opening" message at the beginning of my code. Is there a way to preload/pre-evaluate the defun expressions at the beginning?

(vl-load-com)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun onloadexpressions ( / reply1 )
   (SETQ reply1 (ACET-UI-MESSAGE (strcat "Some Text") "Some Header" 36))
   (cond
       (   (= 6 reply1) (c:mos2nsc))
       (   (= 7 reply1) (c:runlater))
   )
   (princ)
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:mos2nsc ( / reply2 )
   (SETQ reply2 (ACET-UI-MESSAGE (strcat "Some Text") "Some Header" 20))
   (cond
       (   (= 6 reply1) (c:replyyes))
       (   (= 7 reply1) (c:runlater))
   )
   (princ)
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:replyyes ( / of_dist of_elev of_epk of_pt )
   (setvar "cmdecho" 0)
   (if (null of_distx) (setq of_distx 1.0))
   (initget 6)
   (if (setq of_dist (getdist (strcat "\nPlease Enter the Offset Distance <" (rtos of_distx) ">: ")))
       (setq of_distx of_dist)
   )
   (if (null of_elevx) (setq of_elevx 0.0))
   (if (setq of_elev (getreal (strcat "\nPlease Enter the Elevation Difference - For a Negative Use a '-' <" (rtos of_elevx) ">: ")))
       (setq of_elevx of_elev)
   )
   (while (or (setq of_epk (entsel)) (= 7 (getvar "errno")))
       (if (and of_epk
               (member (cdr (assoc 100 (reverse (entget (car of_epk))))) '("AcDbPolyline" "AcDb2dPolyline"))
               (setq of_pt (getpoint "\nPlease Select the Side to offset: "))
           )
           (command "_.offset" of_distx of_epk "_non" of_pt "" "_.move" (entlast) "" "_non" (list 0.0 0.0 of_elevx) "")
       )
   )
   (princ)
)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:runlater ( / )
   (acet-ui-message "To run later, type 'MOS2NSC' anytime to begin to conversion process." "Some Header" 64)
   (princ)
)
(onloadexpressions)

Link to comment
Share on other sites

Lee Mac you are the man!! Thank you so much, that worked perfectly. I sent you an email on your website, you can disregard that now. :)

 

 

Tharwat, thank you as well. I really appreciate your help.

Link to comment
Share on other sites

Tharwat, thank you as well. I really appreciate your help.

 

It is very kind of you to say that , I just gave you the direction and Lee did the whole things . :)

 

I recommend you to modify your first post to avoid coming up of a moderator with a warning :lol: it is simple thing , read THIS

Link to comment
Share on other sites

Ok so at the risk of sounding like an idiot; too late; I cant get the "#" to do anything. I read the article you sent me Tharwat and nothing is happening when I try to edit the post.

Link to comment
Share on other sites

I cant get the "#" to do anything. I read the article you sent me Tharwat and nothing is happening when I try to edit the post.

 

After pressing the button Edit Post select the codes then press the button # to obtain them within cod tags .

Link to comment
Share on other sites

That's exactly what I did. It doesn't seem to work for me. I went to edit post, went to advanced, highlighted the section of code, clicked the "#" button, nothing happened, saved edit.

Link to comment
Share on other sites

How do I get this to "call/goto" another defun within the same lisp. When I try it, it tells me ; error: no function definition:

 

You have to think of lisp as a script language (because it is), and in your code, you're calling a function/command before you have loaded in the environment.

 

Move functions that are being called, above the calling function.

For Example. I moved your functions around in the following order and it then works:

c:runlater

c:replyyes

c:mos2nsc

--lastly you would place the non-encapsulated code setq reply1...etc.

 

(vl-load-com)
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:runlater ( / )
 (acet-ui-message "To run later, type 'MOS2NSC' anytime to begin to conversion process." "Some Header" 64)
 )
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:replyyes ( / of_epk of_pt)
 (setvar "cmdecho" 0)
 (if (null of_dist) (setq of_distx 1.0))
 (initget 6)
 (if (null (setq of_dist (getdist (strcat "\nPlease Enter the Offset Distance <>: "))))
   (setq of_dist of_distx)
   )
 (setq of_distx of_dist)
 (if (null of_elev) (setq of_elevx 0.0))
 (if (null (setq of_elev (getreal (strcat "\nPlease Enter the Elevation Difference - For a Negative Use a '-' <>: "))))
   (setq of_elev of_elevx)
   )
 (setq of_elevx of_elev)
 (while (or (setq of_epk (entsel)) (eq 7 (getvar "errno")))
   (if (and of_epk
     (member (cdr (assoc 100 (reverse (entget (car of_epk)))))
      '("AcDbPolyline" "AcDb2dPolyline"))
     (setq of_pt (getpoint "\nPlease Select the Side to offset: "))
     )
     (command "_.offset" of_dist of_epk of_pt "" "_.move" (entlast) ""
       (list 0.0 0.0 of_elev) "")
     )
   )
 (princ)
 )
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:mos2nsc ( / )
 (SETQ reply2 (ACET-UI-MESSAGE (strcat "Some Text") "Some Header" 20))
 (IF (= reply2 6) (c:replyyes))
 (IF (= reply2 7) (c:runlater))
 )
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------
(SETQ reply1 (ACET-UI-MESSAGE (strcat "Some Text") "Some Header" 36))
(IF (= reply1 6) (c:mos2nsc))
(IF (= reply1 7) (c:runlater))

 

On a separate note:

You are also defining all your functions as commands. Which makes sense for c:mos2nsc, but not for any other.

 

Secondly, you have a few instances where your using setq on a var, but not assigning it anything. I'm wondering if the thought, is that this will clear the value (which it does not), or if you are using this method to return the current value of the var.

If the first, then you would clear a var by setting it to nil, "", or 0.

If the second, then you could return the value of a var by simply typing the name of the var, without parenthesis.

Of course if you have purpose other than my limited insight, then please forgive me.

 

Lastly, this really deserves it's own thread in order for it to get the attention it deserves and because the problem you faced isn't so much related to the original post. And to encapsulate your code in the code hashes :)

Link to comment
Share on other sites

Lee Mac you are the man!! Thank you so much, that worked perfectly. I sent you an email on your website, you can disregard that now. :)

 

You're welcome!

 

Aside, regarding the code tags - as SLW210 has suggested, I find it easier to simply type the BBCode tags, i.e.:

 

[highlight][noparse]

[/noparse][/highlight] Your code here [highlight][noparse]

[/noparse][/highlight]

Link to comment
Share on other sites

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...