I'm creating Named Page Setups through LISP and vla-put-CanonicalMediaName doesn't seem to accept papersizes if they have brackets/parenthesis characters in their names. The paper size I'm trying to set does exist and I have tried escaping the brackets with a backslash but I still received the following error from AutoCAD's commandline:
; error: Automation Error. Invalid input
When I comment the vla-put-CanonicalMediaName setting out, or change it to a paper size with only spaces and alphanumeric characters, the functions run flawlessly.
Even when I run the "-PLOT" command and follow the prompts, the program accepts the paper-size I'm trying to set through this LISP command.
Is there a different function I'm supposed to call? Or is my installation of AutoCAD 2009 behaving abnormally?
Thank you for any input you may have.
The entire code I'm running is as follows.
(defun c:pagesetups()
;; Get the current drawing
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Get the PlotConfigurations collection
(setq plotCfgs (vla-get-PlotConfigurations doc))
;; Check to see if the pagesetup already exists
(setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs "Named Page Setup 1")))
;; If the page setup exists, the variable will be of type VLA-OBJECT
(if (/= (type plotCfg) 'VLA-OBJECT)
;; Create a page setup for model
(setq plotCfg (vla-Add plotCfgs "Named Page Setup 1" :vlax-true))
)
;;(vla-put-Name plotCfg "Named Page Setup 1")
(vla-RefreshPlotDeviceInfo plotCfg)
;; Set the plot device
(vla-put-ConfigName plotCfg "DWG To PDG.pc3")
;; Set the paper size
(vla-put-CanonicalMediaName plotCfg "ANSI B \(11.00 x 17.00 Inches\)");<-- HERE'S WHERE THE ERROR OCCURS (I THINK)
(vla-put-PaperUnits plotCfg acMillimeters)
(setq PLOT_BL (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) '(-53.540381 -6.990000))
PLOT_TR (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) '(814.00000000 537.00000000))
)
(vla-SetWindowToPlot plotCfg PLOT_BL PLOT_TR)
(vla-put-PlotType plotCfg acWindow)
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg ac1_2)
(vla-put-CenterPlot plotCfg :vlax-false)
;; Hide paperspace objects
(vla-put-PlotHidden plotCfg :vlax-false)
;; Set the plot offset
(setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill origin (list 0.0 0.0))
(vla-put-PlotOrigin plotCfg origin)
(vla-put-PlotRotation plotCfg ac90degrees)
(vla-put-PlotViewportBorders plotCfg :vlax-false)
(vla-put-PlotViewportsFirst plotCfg :vlax-false)
(vla-put-PlotWithLineweights plotCfg :vlax-true)
(vla-put-ScaleLineweights plotCfg :vlax-false)
(vla-put-PlotWithPlotStyles plotCfg :vlax-true)
(vla-put-ShowPlotStyles plotCfg :vlax-true)
(vla-put-StyleSheet plotCfg "MTO_monochrome_Half_Size.ctb")
(vla-RefreshPlotDeviceInfo plotCfg)
(princ)
)
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Is this plotter name correct?
"DWG To PDG.pc3"
You must provide to the function the correct media name...
(vla-put-CanonicalMediaName plotCfg "ANSI_B_(11.00_x_17.00_Inches)")
EDIT: to see the paper sizes available
(setq paper (vlax-safearray->list (vlax-variant-value (vla-GetCanonicalMediaNames plotCfg))))
HTH
Henrique
I believe an error is happening before where you think.
;; Set the plot device (vla-put-ConfigName plotCfg "DWG To PDG.pc3")
The pc3 file name is incorrect by one letter.
In addition, you do not need to escape the parentheses with a backslash.
Very sorry about that, that was a typo from a few edits I had to make to the code before posting.
I fixed the error and it's still giving me invalid input.
After doing some research, I discovered that paper-size have two names: CanonicalMediaName and LocaleMediaName. Would the vla-put-CanonicalMediaName accept the LocaleMediaName of a paper size?
Also, how would I get the LocaleMediaName?
Did you try this?
(vla-put-CanonicalMediaName plotCfg "ANSI_B_(11.00_x_17.00_Inches)")
Henrique
That worked exactly. I never would have thought about using underscores in place of spaces.
Thank you very much, sir! Your solution is much simpler than what mine was going to be.