Centering plots with VBA

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
To Center My Plot i need to run my project twice
What do i Wrong
1)
Sub test()
Dim sConfig As AcadPlotConfiguration
ThisDrawing.Regen acAllViewports
Set sConfig = ThisDrawing.ActiveLayout
sConfig.PaperUnits = acInches
sConfig.CenterPlot = True
sConfig.RefreshPlotDeviceInfo
ThisDrawing.Regen acAllViewports
ThisDrawing.Plot.DisplayPlotPreview acFullPreview '
End Sub
2)
Sub test()
Dim Layouts As AcadLayouts, Layout As Acadlayout
Dim IsCentered As String
Set Layouts = ThisDrawing.Layouts
' Toggle centered state for Layout1
Layouts("Layout1").PlotType = acExtents
Layouts("Layout1").CenterPlot = Not (Layouts("Layout1").CenterPlot)
ThisDrawing.Regen acAllViewports
ThisDrawing.Plot.DisplayPlotPreview acFullPreview
End Sub
3)
Dim strValue As String
Dim sLayout As AcadPlotConfiguration
Dim varWidth As Double
Dim varHeight As Double
Dim dblpt(0 To 2) As Double
Set sLayout = ThisDrawing.ActiveLayout
sLayout.GetPaperSize varWidth, varHeight
''The center of that paper
dblpt(0) = varHeight / 2: dblpt(1) = varWidth / 2: dblpt(2) = 0#
sLayout.PlotType = acExtents
ThisDrawing.Regen acAllViewports
ThisDrawing.Plot.DisplayPlotPreview acFullPreview