GetPaperMargins Example

Using Programming Languages other than VBA

Sub Example_GetPaperMargins()
	' This example will access the Layouts collection for the current drawing
	' and list the plot size based on the margins returned from the GetPaperMargins
	' property for each Layout except model space.
	Dim Layouts As AcadLayouts, Layout As ACADLayout
	Dim msg As String
	Dim Measurement As String
	Dim MarginLowerLeft As Variant, MarginUpperRight As Variant

	Dim PaperHeight As Double, PaperWidth As Double
	Dim PlotHeight As Double, PlotWidth As Double

	' Get layouts collection from document object
	Set Layouts = ThisDrawing.Layouts

	msg = vbCrLf & vbCrLf   ' Start with a space

	' Get the margin information of every layout in this drawing

	For Each Layout In Layouts
		' Skip model space
		If Layout.name = "Model" Then GoTo NEXT_LAYOUT
		ThisDrawing.ActiveLayout = Layout
	
		msg = msg & Layout.name & vbCrLf
	
		' Get paper size and margin information
		Layout.GetPaperMargins MarginLowerLeft, MarginUpperRight
		Layout.GetPaperSize PaperWidth, PaperHeight
	
		' Do plot area calculations

		PlotWidth = PaperWidth - (MarginUpperRight(0) - MarginLowerLeft(0))
		PlotHeight = PaperHeight - (MarginUpperRight(1) - MarginLowerLeft(1))
	
		' Are we using inches or millimeters
		Measurement = " millimeter(s)"
	
		' Format for display
		msg = msg & vbTab & "The paper size for this layout is: " & PaperWidth & " X " & PaperHeight & Measurement & vbCrLf & vbCrLf

		msg = msg & vbTab & "The paper margins are: " & vbCrLf & _
							vbTab & vbTab & "Left" & vbTab & "(" & MarginLowerLeft(0) & ")" & Measurement & vbCrLf & _
							vbTab & vbTab & "Right" & vbTab & "(" & MarginUpperRight(0) & ")" & Measurement & vbCrLf & _
							vbTab & vbTab & "Top" & vbTab & "(" & MarginUpperRight(1) & ")" & Measurement & vbCrLf & _
							vbTab & vbTab & "Bottom" & vbTab & "(" & MarginLowerLeft(1) & ")" & Measurement & vbCrLf & vbCrLf
		msg = msg & vbTab & "The paper plot area for this layout is: " & PlotWidth & " X " & PlotHeight & Measurement & vbCrLf

		msg = msg & "_____________________" & vbCrLf
	
NEXT_LAYOUT:
	Next

	' Display paper size and margin information
	MsgBox "Paper plot information for the current drawing is: " & msg
End Sub





   Comments?