1
votes

I made an AutoHotkey script to print drawings to PDF; however, I am having issues with a particular combobox in AutoCAD's plot dialog box. This combobox allows you to select one of your installed printers or printer configuration files. The printer I want to choose is one of the built-in ones, called "DWG To PDF.pc3". Here is my code snippet that DOESN'T work (it appears to do nothing): Control , ChooseString , DWG , ComboBox1 , Plot - Model

Additionally, I've tried with and without quotes (it's always hard for me to tell when I need to quote literal text) and the full name -- nothing works. My workaround (temporarily, I hope) is to use Control , Choose , N. This is undesirable as different users may have more or fewer printers installed and this will affect where the desired printer is placed in the list. Here is a snippet of that code: Control , Choose , 20 , ComboBox1 , Plot - Model

For reference, I have installed AutoHotkey version 1.1.30.01 - November 11, 2018.

What am I missing? Or any suggestions or creative solutions (even from other programming languages)? Thank you!

EDIT:

TL;DR - This is mainly geared for LT.

Full Context - I have full AutoCAD (Mechanical) and use LISP for many tasks. In fact, I've used your (Lee Mac's) tutorials and helpful posts across many forums to get started with it years ago. At my company, we have 27 seats of LT (11 full) where I've set up a company ribbon with SCR files for a few things, including printing. This case is a little different because some of the users need to be able to select a few different pre-configured print options.

Of course, I could make more SCR files for this purpose, but they lack user-error-prevention that AHK can provide. Really, I have a working program with AHK, but it's just short of meeting my standard since there seems to be something goofy going on with just that one particular combobox. So, if someone could steer me towards figuring that out, I would greatly appreciate it.

1

1 Answers

1
votes

Firstly, it would be helpful if you could clarify whether the host application is the full version of AutoCAD or the lite version AutoCAD LT, since the former supports full customisation using the AutoLISP, .NET, or ObjectARX APIs (and hence this task is straightforward) whereas the latter does not support customisation, meaning third-party tools (such as AutoHotKey) must be used.


If you have access to the full version of AutoCAD, then the task of plotting to a PDF can be accomplished with an AutoLISP program such as the following:

(defun c:pdfall ( / *error* cmd ctb )

    (defun *error* ( msg )
        (if ctb (setvar 'ctab ctb))
        (if cmd (setvar 'cmdecho cmd))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (setq ctb (getvar 'ctab)
          cmd (getvar 'cmdecho)
    )
    (setvar 'cmdecho 0)
    (foreach lay (layoutlist)
        (setvar 'ctab lay)
        (command
            "_.-plot"
            "_Y" ;; Detailed plot configuration? [Yes/No]:
            ""   ;; Enter a layout name <Current-Layout>:
            "DWG To PDF.pc3" ;; Enter an output device name:
            "ISO full bleed A4 (297.00 x 210.00 MM)" ;; Enter paper size:
            "_M" ;; Enter paper units [Inches/Millimeters]:
            "_L" ;; Enter drawing orientation [Portrait/Landscape]:
            "_N" ;; Plot upside down? [Yes/No]:
            "_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
            "_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
            "_C" ;; Enter plot offset (x,y) or [Center]:
            "_Y" ;; Plot with plot styles? [Yes/No]:
            "monochrome.ctb" ;; Enter plot style table name (enter . for none):
            "_Y" ;; Plot with lineweights? [Yes/No]:
            "_N" ;; Scale lineweights with plot scale? [Yes/No]:
            "_N" ;; Plot paper space first? [Yes/No]:
            "_N" ;; Hide paperspace objects? [Yes/No]:
            (LM:uniquefilename (strcat (getvar 'dwgprefix) lay ".pdf"))
            "_N" ;; Save changes to page setup [Yes/No]:
            "_Y" ;; Proceed with plot [Yes/No]:
        )
    )
    (setvar 'ctab ctb)
    (setvar 'cmdecho cmd)
    (princ)
)

;; Unique Filename  -  Lee Mac
;; Returns a filename suffixed with the smallest integer required for uniqueness

(defun LM:uniquefilename ( fnm )
    (if (findfile fnm)
        (apply
           '(lambda ( pth bse ext / tmp )
                (setq tmp 1)
                (while (findfile (setq fnm (strcat pth bse "(" (itoa (setq tmp (1+ tmp))) ")" ext))))
            )
            (fnsplitl fnm)
        )
    )
    fnm
)

(princ)

However, assuming you only have access to the basic AutoCAD LT platform, I would suggest using the command-line version of the PLOT command: -PLOT, so that you only need to supply keyboard input to a predictable sequence of prompts, rather than interacting with a dialog interface which differs depending on the last used settings.

When using the -PLOT command, the sequence of prompts for a Paperspace Layout will be as shown in the AutoLISP program posted above, i.e.:

"_.-plot"
"_Y" ;; Detailed plot configuration? [Yes/No]:
""   ;; Enter a layout name <Current-Layout>:
"DWG To PDF.pc3" ;; Enter an output device name:
"ISO full bleed A4 (297.00 x 210.00 MM)" ;; Enter paper size:
"_M" ;; Enter paper units [Inches/Millimeters]:
"_L" ;; Enter drawing orientation [Portrait/Landscape]:
"_N" ;; Plot upside down? [Yes/No]:
"_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
"_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
"_C" ;; Enter plot offset (x,y) or [Center]:
"_Y" ;; Plot with plot styles? [Yes/No]:
"monochrome.ctb" ;; Enter plot style table name (enter . for none):
"_Y" ;; Plot with lineweights? [Yes/No]:
"_N" ;; Scale lineweights with plot scale? [Yes/No]:
"_N" ;; Plot paper space first? [Yes/No]:
"_N" ;; Hide paperspace objects? [Yes/No]:
<Your PDF Filename Here>
"_N" ;; Save changes to page setup [Yes/No]:
"_Y" ;; Proceed with plot [Yes/No]: