CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2020 开发者帮助

GetPaperMargins 方法 (ActiveX)

2024-5-18 18:20| 发布者: admin| 查看: 98| 评论: 0|原作者: admin|来自: AutoCAD

GetPaperMargins 方法 (ActiveX)

获取布局或打印配置的边距。

支持的平台:仅限 Windows

签名

VBA:

object.GetPaperMargins LowerLeft, UpperRight
对象

类型:布局PlotConfiguration

此方法应用到的对象。

左下角

访问:仅输出

类型:变体(双精度的双元素数组)

左下边距的 XY 值。

右上

访问:仅输出

类型:变体(双精度的双元素数组)

右上边距的 XY 值。

返回值 (RetVal)

无返回值。

言论

打印原点与纸张边缘的偏移量为此处指定的边距。

这些值的单位由属性指定。PaperUnits

例子

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

可视化 LISP:

(vl-load-com)
(defun c: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.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Get layouts collection from document object
    (setq Layouts (vla-get-Layouts doc))
    
    (setq msg "")   ;; Start with a space
    
    ;; Get the margin information of every layout in this drawing
    (vlax-for Layout Layouts
        ;; Skip model space
        (if (/= (vla-get-Name Layout) "Model")
	           (progn
	               (vla-put-ActiveLayout doc Layout)
	        
	               (setq msg (strcat msg (vla-get-Name Layout) "\n"))
	        
	               ;; Get paper size and margin information
	               (vla-GetPaperMargins Layout 'MarginLowerLeft 'MarginUpperRight)
	               (vla-GetPaperSize Layout 'PaperWidth 'PaperHeight)

	               ;; Do plot area calculations
	               (setq PlotWidth (- PaperWidth (- (vlax-safearray-get-element MarginUpperRight 0) (vlax-safearray-get-element MarginLowerLeft 0))))
	               (setq PlotHeight (- PaperHeight (- (vlax-safearray-get-element MarginUpperRight 1) (vlax-safearray-get-element MarginLowerLeft 1))))
	        
	               ;; Are we using inches or millimeters
	               (setq Measurement " millimeter(s)")
	        
	               ;; Format for display
	               (setq msg (strcat msg "The paper size for this layout is: " (rtos PaperWidth 2) " X " (rtos PaperHeight 2) Measurement "\n\n"))
	               (setq msg (strcat msg "  The paper margins are: \n"
				                              "  Left (" (rtos (vlax-safearray-get-element MarginLowerLeft 0) 2) ")" Measurement "\n"
				                              "  Right (" (rtos (vlax-safearray-get-element MarginUpperRight 0) 2) ")" Measurement "\n"
				                              "  Top (" (rtos (vlax-safearray-get-element MarginUpperRight 1) 2) ")" Measurement "\n"
				                              "  Bottom (" (rtos (vlax-safearray-get-element MarginLowerLeft 1) 2) ")" Measurement "\n\n"))
				  
	               (setq msg (strcat msg "The paper plot area for this layout is: " (rtos PlotWidth 2) " X " (rtos PlotHeight 2) Measurement "\n"))
	               (setq msg (strcat msg "_____________________\n"))
	           )
	       )
    )
    
    ;; Display paper size and margin information
    (alert (strcat "Paper plot information for the current drawing is: " msg))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 12:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部