Controlling Plot Parameters

A number of parameters are normally set using the Plot dialog box shown in Figure 15-4. AutoCAD provides a means to control these settings programmatically. In this section I cover the options that are most commonly modified.

Vba Userforms Collection
Figure 15-4. The Plot dialog box

All the methods and properties for controlling the plot parameters are available to both the PlotConfiguration and Layout objects. Consequently, when I present the syntax in the following sections, I use the word "object" to denote either object.

The CanonicalMediaName Property

You can read or set the paper size to be used when plotting using the CanonicalMediaName property of the Layout or PlotConfiguration object. You specify the paper size by a name given as a string, and changes to this property won't take effect until the drawing has been regenerated.

Object.CanonicalMediaName = strPaperSize

This code snippet shows how to read the current setting of the paper size for the active layout of a drawing:

Public Sub PaperSizeNames()

MsgBox "The paper size for the active layout is " & _ ThisDrawing.ActiveLayout.CanonicalMediaName

End Sub

The result of this code may be similar to that shown in Figure 15-5.

The GetCanonicalMediaNames Method

You can use the GetCanonicalMediaNames method to retrieve the names of the available paper sizes for a specified plot device. The return value for this method is an array of strings holding the names of the available paper sizes.

varPaperSizeNames = Object.GetCanonicalMediaNames()

It's advisable to call the RefreshPlotDeviceInfo method before you use this method for the first time, and each time you're changing the default plot device. This ensures that the plot, paper size names, and plot style table information accurately reflect the current system state.

The GetPaperSize Method

Although you can read the CanonicalMediaName property to find out the name of the paper size to be used, you may want to know the actual width and height dimensions. The GetPaperSize method retrieves the width and height of the configured paper, given in the current paper units.

Object.GetPaperSize Width, Height

Table 15-9 shows the GetPaperSize method's parameters.

Table 15-9. GetPaperSize Method Parameters

Name

Data Type

Description

Width

Double

The width of the paper in units specified by the PaperUnits property of the layout or plot configuration

Height

Double

The height of the paper in units specified by the PaperUnits property of the layout or plot configuration

The following code example incorporates the property and methods associated with the paper size. First, the available paper sizes for the current layout are retrieved and displayed to the user. If the user then enters one of these in an input box, the dimensions of the chosen paper size display.

Public Sub PaperSize()

Dim varPaperSizeNames As Variant

Dim strPaperSizeNames As String

Dim intCount As Integer

Dim strChoosenPaperSize As String varPaperSizeNames = ThisDrawing.ActiveLayout.GetCanonicalMediaNames strPaperSizeNames = "These are the paper sizes available:" & vbCrLf For intCount = 0 To UBound(varPaperSizeNames) strPaperSizeNames = strPaperSizeNames & _ varPaperSizeNames(intCount) & ", " Next intCount strPaperSizeNames = strPaperSizeNames & vbCrLf & " Please choose one."

strChoosenPaperSize = InputBox(strPaperSizeNames, "Pick a paper size")

For intCount = 0 To UBound(varPaperSizeNames)

If StrComp(strChoosenPaperSize, varPaperSizeNames(intCount), 1) = 0 _ Then GoTo DisplaySize Next intCount

MsgBox "You did not enter a valid paper size name." Exit Sub

DisplaySize:

Dim dblPaperWidth As Double Dim dblPaperHeight As Double Dim lngPaperUnits As Long Dim strPaperUnits As String

ThisDrawing.ActiveLayout.GetPaperSize dblPaperWidth, dblPaperHeight lngPaperUnits = ThisDrawing.ActiveLayout.PaperUnits Select Case lngPaperUnits Case 0

strPaperUnits = "inches" dblPaperWidth = dblPaperWidth / 25.4 dblPaperHeight = dblPaperHeight / 25.4 Case 1

strPaperUnits = "millimeters" End Select

MsgBox dblPaperWidth & " by " & dblPaperHeight & " " & strPaperUnits End Sub

+2 0

Responses

  • annunziata
    How to find paper size in autocad vba?
    5 years ago

Post a comment