VBA 使用 ActiveViewPort方法
下面是创建一个VIEW的例子代码,
Sub createViewWithTwistAngle()
' This example creates a new paperspace viewport.
' It then sets the viewdirection, and the TwistAngle
' Then view is then created using SendCommand (VIEW)
' The viewport erased it is only created to set the
' TwistAngle
Dim pviewportObj As AcadPViewport
Dim viewportObj As AcadViewport
Dim myView As AcadView
Dim center(0 To 2) As Double
Dim width As Double
Dim height As Double
Dim int1 As Integer
' Define the pviewport
center(0) = 3: center(1) = 3: center(2) = 0
width = 4
height = 4
' Change from model space to paperspace
ThisDrawing.ActiveSpace = acPaperSpace
' Create the pviewport
Set pviewportObj = ThisDrawing.PaperSpace.AddPViewport(center, width,
height)
pviewportObj.Display True
pviewportObj.ViewportOn = True
ThisDrawing.MSpace = True
ThisDrawing.ActivePViewport = pviewportObj
' Change the viewing direction of the ViewPort
Dim NewDirection(0 To 2) As Double
NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
pviewportObj.Direction = NewDirection
' Set the twist angle for the viewport
pviewportObj.twistAngle = 0.57
' Remove view named test1
For int1 = 0 To ThisDrawing.Views.Count - 1
If ThisDrawing.Views(int1).Name = "test1" Then
ThisDrawing.Views(int1).Delete
End If
Next int1
ThisDrawing.Application.ZoomExtents
' Create a view
SendCommand "-view" & Chr(13) & "Save" & Chr(13) & "test1" & Chr(13)
' Erase the paper space view port
pviewportObj.Delete
ThisDrawing.ActiveSpace = acModelSpace
' Reference model space viewport and set the view to the one
' created above
Set viewportObj = ThisDrawing.ActiveViewport
Set myView = ThisDrawing.Views.Item("Test1")
viewportObj.SetView myView
ThisDrawing.ActiveViewport = viewportObj
End Sub
|