Plotting is a key step in communicating your design with non-AutoCAD users unless you are using AutoCAD WS or another way of hosting your designs for others to see. While many users go straight to the PLOT command and never bother with page setups, page setups can make plotting a drawing much more consistent and easier if you need to plot your designs at different sizes or formats. One reason to plot the same layout or design at different sizes might be for a check plot and the other to a specific scale.
Note: This article does not work for those using AutoCAD for Mac because it does not support ActiveX.
The following demonstrates how to plot a layout using a PC3 file. It first checks to see if a PC3 file is assigned to the current layout for plotting, and if not it assigns the DWF6 ePlot.pc3 file as the current plot device. Using this same approach, you could plot all layouts in a drawing to PDF or DWF files without changing the current plot configuration, much like the way the PUBLISH command works.
(vl-load-com)
(defun c:QDWF( / doc)
;; Get the current drawing
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Plot the current layout
(vla-PlotToDevice (vla-get-Plot doc) "DWF6 ePlot.pc3")
(princ)
)
The vla-PlotToDevice function above is passed a valid PC3 file, but if you do not pass a PC3 file to the method it will use the plot device assigned to the layout which can be accessed with the vla-get-ConfigName function.
Note: The vla-PlotToDevice function will start plotting in the background or foreground based on the current value of the BACKGROUNDPLOT system variable.
Now that you see how to plot a single layout, you can plot multiple layouts using the vla-SetLayoutsToPlot function.
(defun c:PLOTALL( / doc)
;; Get the current drawing
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq lstLayouts nil
arSize 0)
(vlax-for layout (vla-get-layouts doc)
;; Check to see if a plot device is assigned to the layout, if not it will not be plotted
(if (and
(/= (strcase (vla-get-ConfigName layout)) "NONE")
(= (vla-get-ModelType layout) :vlax-false)
)
(progn
(if (= lstLayouts nil)
(setq lstLayouts (list (vla-get-Name layout)))
(setq lstLayouts (append lstLayouts (vla-get-Name layout)))
)
)
)
)
;; Create an array for all the layouts to be plotted
(setq arLayouts (vlax-make-safearray vlax-vbString (cons 0 (1- (length lstLayouts)))))
;; Add the layout names to the array
(foreach item lstLayouts
(progn
(vlax-safearray-put-element arLayouts arSize item)
(setq arSize (1+ arSize))
)
)
;; Plot the layout to the device
(vla-SetLayoutsToPlot (vla-get-Plot doc) arLayouts)
(vla-PlotToDevice (vla-get-Plot doc))
(princ)
)
The following demonstrates how to create a named page setup, and then assign it to the current layout.
(defun c:CustomPageSetup()
;; 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 "MYPAGESETUP")))
;; If the page setup exists, the variable will be of type VLA-OBJECT
(if (/= (type plotCfg) 'VLA-OBJECT)
;; Create a page setup for model or paper space accordingly
(if (= (getvar "TILEMODE") 0)
(setq plotCfg (vla-Add plotCfgs "MYPAGESETUP" :vlax-false))
(setq plotCfg (vla-Add plotCfgs "MYPAGESETUP" :vlax-true))
)
)
;;(vla-put-Name plotCfg "MYPAGESETUP")
(vla-RefreshPlotDeviceInfo plotCfg)
;; Set the plot device
(vla-put-ConfigName plotCfg "DWF6 ePlot.pc3")
;; Set the paper size
(vla-put-CanonicalMediaName plotCfg "ANSI_C_(22.00_x_17.00_Inches)")
;; Set the plot units (inches, millimeters, pixels)
(vla-put-PaperUnits plotCfg acInches)
;; Set what to plot
;; - If using acView, set the ViewToPlot property
;; - If using acWindow, call GetWindowToPlot
(if (= (getvar "TILEMODE") 0)
(progn
(vla-put-PlotType plotCfg acLayout)
;; Set scale
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg ac1_1)
)
(progn
(vla-put-PlotType plotCfg acExtents)
;; Set scale
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg acScaleToFit)
;; Center the plot on the page
(vla-put-CenterPlot plotCfg :vlax-true)
)
)
;; Hide paperspace objects
(vla-put-PlotHidden plotCfg :vlax-false)
;; Set the plot origin
(setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill origin (list 0.5 0.5))
(vla-put-PlotOrigin plotCfg origin)
;; Set the plot rotation
(vla-put-PlotRotation plotCfg ac0degrees)
;; Set viewport plot behavior
(vla-put-PlotViewportBorders plotCfg :vlax-false)
(vla-put-PlotViewportsFirst plotCfg :vlax-true)
;; Set lineweight behavior
(vla-put-PlotWithLineweights plotCfg :vlax-true)
(vla-put-ScaleLineweights plotCfg :vlax-true)
;; Set plot styles behavior
(vla-put-PlotWithPlotStyles plotCfg :vlax-true)
(vla-put-ShowPlotStyles plotCfg :vlax-true)
(if (= (getvar "PSTYLEMODE") 0)
(vla-put-StyleSheet plotCfg "acad.stb")
(vla-put-StyleSheet plotCfg "acad.ctb")
)
;; Assign the page setup to the current layout
(vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)
)
Hope you enjoyed the sample code.
Sincerely,
Lee
Recent Comments