Autodesk Community Tipsではちょっとしたコツ、やり方、ショートカット、アドバイスやヒントを共有しています。
AutoCAD のActiveX API SetWindowToPlot()で指定した印刷範囲が特定の図面でずれる場合がある。
指定した範囲で正しく印刷する方法はありますか。
印刷範囲がずれる図面では、TARGETシステム変数の値に0ではない値が設定されている可能性があります。
※TARGETシステム変数変数については、以下のリファレンスを参照
https://help.autodesk.com/view/ACD/2022/JPN/?guid=GUID-0649E4B8-B11A-411E-96CE-125BEBEB5B42
この場合、SetWindowToPlotで指定した座標がオフセットされてるため、指定した印刷範囲で印刷されません。
以下サンプルコードの様にSetWindowToPlot()に指定する点の座標を、ActiveViewport.Targetの値で減算することで、指定範囲で印刷されるようになります。
Sub Example_SetWindowToPlot()
Dim point1 As Variant, point2 As Variant
point1 = ThisDrawing.Utility.GetPoint(, "Click the lower-left of the window to plot.")
ReDim Preserve point1(0 To 1) ' Change this to a 2D array by removing the Z position
point2 = ThisDrawing.Utility.GetPoint(, "Click the upper-right of the window to plot.")
ReDim Preserve point2(0 To 1) ' Change this to a 2D array by removing the Z position
Dim currTarget As Variant
currTarget = ThisDrawing.ActiveViewport.Target
point1(0) = point1(0) - currTarget(0)
point1(1) = point1(1) - currTarget(1)
point2(0) = point2(0) - currTarget(0)
point2(1) = point2(1) - currTarget(1)
ThisDrawing.ActiveLayout.SetWindowToPlot point1, point2
ThisDrawing.ActiveLayout.PlotType = acWindow
ThisDrawing.ActiveLayout.ConfigName = "DWG to PDF.pc3"
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
End Sub