NBC Posted July 22, 2010 Posted July 22, 2010 I would like some guidance on how to 'convert' the code below. It is currently in VBA format, thus: Option Explicit Private Sub AcadDocument_BeginCommand(ByVal CommandName As String) If CommandName = "PUBLISH" Then MsgBox "Please use PageSetups to control printed outputs" End If If CommandName = "PLOT" Then MsgBox "Please use PageSetups to control printed outputs" End If If CommandName = "PRINT" Then MsgBox "Please use PageSetups to control printed outputs" End If End Sub Ideally, I would like the final code to be as a .lsp file. Below is what I have got so far, but it is not working, and I have no idea why: (vl-load-com) (vlr-command-reactor "Use Page Setups" '((:vlr-commandWillStart .startPlot))) (defun startPlot (calling-reactor startcommandInfo / thecommandstart alertc) (setq thecommandstart (nth 0 startcommandInfo)) (if (= thecommandstart "PLOT") (progn (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq alertc (alert "Please use PageSetups to control printed outputs")) ) (princ) ) All help is very much appreciated Quote
lpseifert Posted July 22, 2010 Posted July 22, 2010 this worked the one time I tried it (vl-load-com) (defun pltreact () (if (not plt_react) (setq plt_react (vlr-command-reactor nil '((:vlr-commandWillStart . pltalarm)))) ) ) (pltreact) (defun pltalarm (event parameter) (if (eq (car parameter) "PLOT") (alert "Please use PageSetups to control printed outputs") ) ) Quote
Lee Mac Posted July 22, 2010 Posted July 22, 2010 I tend to use a 'toggle' to control reactors so that it may be switched off if necessary mid-session: (defun c:PlotReactor nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandwillstart foo) ) ) ) ) (princ (if (vlr-added-p react) "\n** Reactor Activated **" "\n** Reactor Deactivated **" ) ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun Plot-Callback ( reactor arguments ) (vl-load-com) (if (eq (strcase (car arguments)) "PLOT") (LM:Popup "Information" 64 "Please use PageSetups to Control Printed Outputs") ) (princ) ) (defun LM:Popup ( title flags msg / WSHShell result ) ;; © Lee Mac 2010 (setq WSHShell (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke WSHShell 'Popup msg 0 title flags)) (vlax-release-object WSHShell) result ) Just putting it out there. Call once with PlotReactor and turn off with the same command. Quote
NBC Posted July 22, 2010 Author Posted July 22, 2010 My reasoning behind this request is I wish it to be a nag to the CAD users at work who insist in not using PageSetups. I intend to remove the lsp file from our system at some point in the near future once they have got the message that it easier to plot (for everyone) if they are used. Quote
NBC Posted July 23, 2010 Author Posted July 23, 2010 Further to the above, is it possible to do the following: 1. for the routine to check to see if a named pagesetup is being used to plot the drawing 1.1 if a named pagesetup is not being used, the routine should cancel the plot command 1.2 if a named pagesetup IS being used, the routine should allow the plot command to continue. 2. to write to a text file (and append each time, not overwrite) whenever a named pagesetup is not being used. this text file should contain the location and name of the drawing file, the user log-in name, the time and date the plot command was issued. It's a big ask for all the above, but all assistance is much appreciated. Quote
woodman78 Posted July 23, 2010 Posted July 23, 2010 LeeMac, I use lisps to load the pagesetup and run purge and a few other commands including finally the plot command. A few guys here in the office are as stubborn as old boots and will not be moved to using them. I figure on using your lisp to annoy the hell out of them into doing so. Can your lisp be modified so that I can run a deactivator at the start of my lisp and an activator at the end rather than a toggle because if it is already off then I will be turning it back on?? Hope I've explained myself. Thanks. Quote
NBC Posted July 26, 2010 Author Posted July 26, 2010 Anybody got any ideas with my last request please? Quote
Lee Mac Posted July 26, 2010 Posted July 26, 2010 Haven't had much time lately - (just started a job) - but will look at it when I get a chance mate. Quote
Lee Mac Posted July 26, 2010 Posted July 26, 2010 LeeMac, I use lisps to load the pagesetup and run purge and a few other commands including finally the plot command. A few guys here in the office are as stubborn as old boots and will not be moved to using them. I figure on using your lisp to annoy the hell out of them into doing so. Can your lisp be modified so that I can run a deactivator at the start of my lisp and an activator at the end rather than a toggle because if it is already off then I will be turning it back on?? Hope I've explained myself. Thanks. (defun c:PlotReactorON nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (not (vlr-added-p react)) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandwillstart foo) ) ) ) ) (if (vlr-added-p react) (princ "\n** Reactor Activated **") (princ "\n** Reactor Failed to Activate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun c:PlotReactorOFF nil (vl-load-com) ;; © Lee Mac 2010 ( (lambda ( data foo / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-command-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) ) ) (if (or (not react) (not (vlr-added-p react))) (princ "\n** Reactor Deactivated **") (princ "\n** Reactor Failed to Deactivate **") ) react ) "Plot-Reactor" 'Plot-Callback ) (princ) ) (defun Plot-Callback ( reactor arguments ) (vl-load-com) (if (eq (strcase (car arguments)) "PLOT") (LM:Popup "Information" 64 "Please use PageSetups to Control Printed Outputs") ) (princ) ) (defun LM:Popup ( title flags msg / WSHShell result ) ;; © Lee Mac 2010 (setq WSHShell (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke WSHShell 'Popup msg 0 title flags)) (vlax-release-object WSHShell) result ) Quote
NBC Posted July 26, 2010 Author Posted July 26, 2010 Haven't had much time lately - (just started a job) - but will look at it when I get a chance mate. Cheers Lee, you're a star. Hope your new job is going well Quote
Lee Mac Posted July 26, 2010 Posted July 26, 2010 Hmm... Your request poses a good question NBC, How does one tell if the user is using a named pagesetup through VL? ... Quote
lpseifert Posted July 28, 2010 Posted July 28, 2010 Hmm... Your request poses a good question NBC, How does one tell if the user is using a named pagesetup through VL? ... I found this here ;;; (getPageSetupName "Model") ;;; (getPageSetupName "Layout1") ;;; (getPageSetupName (getvar "ctab")) ;;; return value: PageSetupName or nil if Page Setup Name doesn't exist (defun getPageSetupName (layout / laydict psn) (setq dn (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))) (setq laydict (dictsearch dn layout)) (setq psn (member '(100 . "AcDbPlotSettings") laydict)) (if (= (caadr psn) 1) ; Page Setup Name exist (setq psn (cdadr psn)) ) ) Quote
lpseifert Posted July 28, 2010 Posted July 28, 2010 Further to the above, is it possible to do the following:1. for the routine to check to see if a named pagesetup is being used to plot the drawing 1.1 if a named pagesetup is not being used, the routine should cancel the plot command 1.2 if a named pagesetup IS being used, the routine should allow the plot command to continue. 2. to write to a text file (and append each time, not overwrite) whenever a named pagesetup is not being used. this text file should contain the location and name of the drawing file, the user log-in name, the time and date the plot command was issued. It's a big ask for all the above, but all assistance is much appreciated. Try this... not a whole lot of testing (defun pltreact (/ plt_react ) (if (not plt_react) (setq plt_react (vlr-command-reactor nil '((:vlr-commandWillStart . pltalarm)))) ) ) (pltreact) (defun pltalarm (event parameter / pltlog) (if (eq (car parameter) "PLOT") (progn (if (= "" (getPageSetupName)) (progn (alert "Plot aborted - No Page Setup detected!") (setq pltlog (open "c:\\PgSetupLog.txt" "a")) (write-line (strcat (getvar "dwgprefix") (getvar "dwgname") "\t" (getvar "loginname") "\t" (rtos (getvar "cdate") 2 6)) pltlog) (close pltlog) (exit) ) ) ) ) ) (defun getPageSetupName (/ dn laydict); thanks to JTBWorld (setq dn (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))) (setq laydict (dictsearch dn (getvar "ctab"))) (setq psn (member '(100 . "AcDbPlotSettings") laydict)) (if (= (caadr psn) 1) (setq psn (cdadr psn)) ) ) Quote
NBC Posted July 28, 2010 Author Posted July 28, 2010 That is great Larry. My only comment with it is that, once the plot command is run (without a pagesetup having been created previously) it shows the expected popup box error two times in a row, but then it allows the plot dialogue box to appear, and to continue to plot as normal Any ideas why, or how to stop it happening ? Quote
lpseifert Posted July 28, 2010 Posted July 28, 2010 (edited) I can't answer that, it works here What happens when you type this at the command line? (getPageSetupName) I opened a new dwg for trial and seem to be having similar problems. I'll try to debug when I get time. Edited July 28, 2010 by lpseifert Quote
lpseifert Posted July 28, 2010 Posted July 28, 2010 I guess I don't know enough about reactors. When I run it from Vlide, it works. When I load it into a fresh dwg I get the problems as you described. Maybe somebody else can help; I'm stumped. Quote
Lee Mac Posted July 28, 2010 Posted July 28, 2010 (edited) Hi NBC, Please try the attached code - it should hopefully function as intended. I would advise you to read the header first. The code will prompt for a directory upon first running (location to store the Log files), this location is then stored in the registry for future use (location noted). Type 'PlotReactorON' to activate, and 'PlotReactorOFF' to Deactivate. As you probably know, you only need to activate it once per session, the reactor does the rest. Lee Plot Setup Log Reactor.lsp Edited July 28, 2010 by Lee Mac Quote
NBC Posted July 28, 2010 Author Posted July 28, 2010 That's darn good Lee. One last request; how would I amend this to control publish in the same manner ? The aim of this is to basically 'force' our CAD users to utilise pagesetups prior to plotting/publishing. If this works, then they will have no option but to do so Quote
Recommended Posts
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.