plot with message option

plot with message option

Anonymous
Not applicable
2,971 Views
25 Replies
Message 1 of 26

plot with message option

Anonymous
Not applicable

hi everyone,

 

i don't know how to name this in the subject but here is what i wanted to happen.

 

When i click "plot" my drawing, is there a way to insert a message that would pop

out in the screen  before going to the plot dialogue box.  our third party program has

the ability to the hidiing where it bottom objects will show dashed or hidden lines. i just

wanted to ask or remind my fellow draftsmen here at work if they did the hiding. so

when we click to "PLOT", a message would pop up like "Did you do Hiding? the an answer

would be a yes or no so that if yes it would continue plotting and if no it would cancel the

plot command. is this possible? maybe run a lisp before the plot command executes. i

appreciate every help or idea i can get.

 

thank you.

0 Likes
Accepted solutions (1)
2,972 Views
25 Replies
Replies (25)
Message 2 of 26

jggerth
Advisor
Advisor

undefine PLOT, and then redefine it in LISP to fire up an ALERT, and then run .plot

 

0 Likes
Message 3 of 26

Anonymous
Not applicable

Hi JGerth,

 

thanks for quick reply and i know exactly what you mean here but it's writing

that Lisp is my problem, it's been a long time and can't seem to do lisp again.

i'm assuming that the Alert is the lisp. anyway you can help me with this?

 

thank you.

 

0 Likes
Message 4 of 26

Kent1Cooper
Consultant
Consultant

Since an (alert) only has an OK check button, and doesn't offer a Yes/No choice, perhaps something like this [untested].  It puts up an alert so you can't help but notice, but then refers to the command line, where it gives the chance for a Yes/No choice.  It could be made to have No be the default, with a little revising.  It could be done with DCL for a dialog box that would put that Yes/No choice up in the middle of the screen, but that's a lot more complicated.  In simplest terms:

 

(command "_.undefine" "PLOT")
(defun C:PLOT ()
  (alert "Answer the Hiding question at the command line.")
  (initget "Yes No")
  (if (= (getkword "\nDid you do the Hiding? <Yes>: ") "No")
    (prompt "\nDo the Hiding, then Plot."); then
    (command "_.plot"); else -- either "Yes" or nil [Enter default]; proceed
  ); if
); defun

 

Kent Cooper, AIA
Message 5 of 26

john.uhden
Mentor
Mentor

Kent's answer is solid, but for important things, I like to use a message box that can provide Yes or No answers.

Copy the entire code into your acaddoc.lsp file.  If you're not sure where it is located, enter

(findfile "acaddoc.lsp")

at the command prompt.  It will return the full path.

 

(command "_.undefine" "PLOT")
(vl-load-com)
(defun C:PLOT ( / *error* cmd Doc Ans )
  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  ;*                                                                           *
  ;*         PLOTALERT.LSP   by   John F. Uhden                                   *
  ;*                           2 Village Road                                  *
  ;*                           Sea Girt, NJ  08750                             *
  ;*                                                                           *
  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  (gc)
  ;;
  ;; This section initializes environmental and program variables:
  ;;
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (setq cmd (getvar "cmdecho")
             Doc (vla-get-ActiveDocument *acad*)
  )
  (defun *error* (error)
    (if (= (type cmd) 'INT)(setvar "cmdecho" cmd))
    (vla-endundomark Doc)
    (cond
      ((not error))
      ((wcmatch (strcase error) "*QUIT*,*CANCEL*"))
      (1 (princ (strcat "\nERROR: " error)))
    )
    (princ)
  )
;;--------------------------------------------------------
;; MsgBox(prompt[, buttons][, title][, helpfile, context])
;; Buttons:
;; vbOKOnly    0 Display OK button only.
;; vbOKCancel    1 Display OK and Cancel buttons.
;; vbAbortRetryIgnore    2 Display Abort, Retry, and Ignore buttons.
;; vbYesNoCancel    3 Display Yes, No, and Cancel buttons.
;; vbYesNo    4 Display Yes and No buttons.
;; vbRetryCancel    5 Display Retry and Cancel buttons.
;; vbCritical   16 Display Critical Message icon.
;; vbQuestion   32 Display Warning Query icon.
;; vbExclamation   48 Display Warning Message icon.
;; vbInformation   64 Display Information Message icon.
;; vbDefaultButton1    0 First button is default.
;; vbDefaultButton2  256 Second button is default.
;; vbDefaultButton3  512 Third button is default.
;; vbDefaultButton4  768 Fourth button is default.
;; vbApplicationModal    0 Application modal; the user must respond to the message box before continuing work in the current application.
;; vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box.
;; Revised (01-27-03) thanks to Ed Jobe's contribution about snagging the return value.
(defun @msgbox (Title Buttons Message / useri1 value)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (setq useri1 (getvar "useri1"))
  (acad-push-dbmod)
  (vla-eval
    *acad*
    (strcat
      "ThisDrawing.SetVariable \"USERI1\","
      "MsgBox (\""
      Message "\","
      (itoa Buttons) ",\""
      Title "\")"
    )
  )
  (setq value (getvar "useri1"))
  (setvar "useri1" useri1)
  (acad-pop-dbmod)
  value
)
  
  (vla-endundomark Doc)
  (vla-startundomark Doc)
  (setvar "cmdecho" 0)
  (command "_.expert" (getvar "expert")) ;; dummy command
  (setvar "cmdecho" 1)
  (setq Ans (@msgbox "PLOT WARNING" (+ 4 32) "Did you do the hiding?"))
  (if (= Ans 6)
    (command "_.plot")
    (@msgbox "PLOT WARNING" 48  "Do the Hiding, then Plot.")
  )
  (*error* nil)
)

John F. Uhden

Message 6 of 26

scot-65
Advisor
Advisor

From my library of snippets/code blocks discovered on this forum:

 

 
;by hmsilva 7-28-2015
;Yes / No prompt
(defun c:deltext (/ ss)
  (if (and (setq ss (ssget "x" (list (cons 0 "text"))))
           (= (ACET-UI-MESSAGE
                "Do you want to delete all texts?"
                "You are about to delete all texts!!!"
                (+ Acet:YESNO Acet:ICONQuestion)
              )
              6
           )
      )
    (command ".erase" ss "")
    (princ "\nNo text in this drawing!")
  )
  (princ)
)
 

(I cannot readily find the ACET codes, sorry)

 

Rework to your liking...

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 7 of 26

john.uhden
Mentor
Mentor

I think that "ACET" stands for AutoCAD Express Tools.

 

I happen to be one of those stubborn idiots who trusts my own work better.  Ya never know when Autodesk will take something away, or make it obsolete.

Correction: Dale Fugier's continued DOSLIB contributions remain without question.

John F. Uhden

0 Likes
Message 8 of 26

Anonymous
Not applicable

hi Kent,

 

thank you for helping out. i tried this by saving this as a separate .lsp file and just

loaded. it actually works but the only problem is when "yes" it goes to a few questions

of plot configurations, i was hoping that when you answer yes it will bring me to the

regular plot dialogue box. i'm guessing because we undefine the plot command that

i looses the whole plot command and replaced by this .lsp. is it possible that when you

answer yes it will just bring back the original plot command. thank you again.

0 Likes
Message 9 of 26

Anonymous
Not applicable

hi john.uhden,

 

thank you for helping out too. like kent i save this file as a separate .lsp file just to test it out.

it loads successfully but it giving me error after clicking the plot command. see below.

 

Command: APPLOAD
practi_hiding_alert.lsp successfully loaded.


Command: _.undefine
Enter command name: PLOT

Command:
Command:
Command:
Command:
Command:
Command: _PLOT
ERROR: Automation Error. Problem in loading VBA

 

it will be nice to have the diaglogue box, anyway you can tell from this?

 

thanks again.

0 Likes
Message 10 of 26

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... i was hoping that when you answer yes it will bring me to the regular plot dialogue box....


It's only that dialog-box-based commands operate in command-line version when called from inside a (command) function, unless you force them to call up the dialog box with a preceding (initdia) function.  The period/decimal before the command name does bring up the "regular" AutoCAD command.  Try this modification:

 

(command "_.undefine" "PLOT")
(defun C:PLOT ()
  (alert "Answer the Hiding question at the command line.")
  (initget "Yes No")
  (if (= (getkword "\nDid you do the Hiding? <Yes>: ") "No")
    (prompt "\nDo the Hiding, then Plot."); then
(progn ; else -- either "Yes" or nil [Enter default]; proceed
(initdia) (command "_.plot")
); progn ); if ); defun
Kent Cooper, AIA
Message 11 of 26

john.uhden
Mentor
Mentor

Try adding this line to the top of the code:

 

(arxload "acadvba.arx" nil)

Also, Kent's recommendation of including (initdia) is sound.

I think you will have to change the code from:

(command "_.plot")

to

(progn
  (initdia)
  (command "_.plot")
)

John F. Uhden

0 Likes
Message 12 of 26

Anonymous
Not applicable

Kent,

 

this one works just as i ask for. one more tweak if i can ask, users are used

to seeing "yes or no" answer with default 'yes' is great. thanks again.

0 Likes
Message 13 of 26

Anonymous
Not applicable

johm,

 

i added the line you wanted me to add. it still gives me the same

message as the first time. i attached the file.

0 Likes
Message 14 of 26

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... one more tweak if i can ask, users are used to seeing "yes or no" answer with default 'yes' is great. ....


If you mean they're used to having those answer choices shown in the prompt, they're easily added:

 

  (if (= (getkword "\nDid you do the Hiding [Yes/No]? <Yes>: ") "No")

 

That format also has the nice advantage that [in new-enough versions] the User can pick on the option in the prompt itself at the command line.

Kent Cooper, AIA
Message 15 of 26

john.uhden
Mentor
Mentor
The default is "Yes" so the user can just hit Enter rather than pick the
"Yes" button.

John F. Uhden

0 Likes
Message 16 of 26

john.uhden
Mentor
Mentor
The default is "Yes" so the user can just hit Enter rather than pick the
"Yes" button.

John F. Uhden

0 Likes
Message 17 of 26

Anonymous
Not applicable

thank you much kent, i appreciate the effort and help.

0 Likes
Message 18 of 26

Ranjit_Singh
Advisor
Advisor

I like @john.uhden's idea of presenting a dialog box. I just tried it out and it works great at my end. Since you are getting a VBA error try below alternative.

 

(vl-load-com)
(command "_.undefine" "PLOT")
(defun c:plot  (/ wsobj)
 (if (= 7 (vlax-invoke (setq wsobj (vlax-get-or-create-object "wscript.shell"))
                     'popup "Did you do the hiding?" 5 "Plot Warning" 4))
  (progn (vlax-invoke wsobj 'popup "Do the hiding and plot" 5 "Plot Warning" 0)
         (vlax-release-object wsobj))
  (progn (initdia) (command "._plot")))
(princ))

 

0 Likes
Message 19 of 26

sdeschneauEADWZ
Explorer
Explorer

Could the final version of this be shared to me? New @ Lisp files and I had a hard time following the resolution here. Thank you. 

0 Likes
Message 20 of 26

Kent1Cooper
Consultant
Consultant

@sdeschneauEADWZ wrote:

Could the final version of this be shared to me? .... 


Which approach?  If you're talking about what's marked as the accepted solution, just take the blue bits from Message 14 and put them into the code from Message 10 at the equivalent place.

Kent Cooper, AIA
0 Likes