这里有一些东西可以让你达到目的。
- Public Sub AlignMsToVp()
- Dim Vp As AcadPViewport
- Dim VpsCol As New Collection
- Dim Ent As AcadEntity
- Dim oBref As AcadBlockReference
- Dim M1, M2, P1, P2, CenPt(2) As Double
- Dim Mdist As Double, PDist As Double
-
- ThisDrawing.ActiveSpace = acPaperSpace
- 'Get the viewport
- For Each Ent In ThisDrawing.PaperSpace
- If TypeOf Ent Is AcadPViewport Then
- VpsCol.Add Ent
- End If
- Next
- 'The first Vp is the layout itself
- If VpsCol.count VpsCol(1).ObjectID Then
- Set Vp = VpsCol(2)
- Else
- Set Vp = VpsCol(1)
- End If
-
- If ThisDrawing.MSpace = False Then
- Vp.Display True
- ThisDrawing.MSpace = True
- End If
- 'Define your modelspace area
- 'Here you need a blockref called "MyLayoutArea"
- 'That is a rectangle on defpoints
- Dim Ss As AcadSelectionSet
- Set Ss = sset(2, "MyLayoutArea")
- Ss(0).GetBoundingBox M1, M2
- Vp.GetBoundingBox P1, P2
- Mdist = M2(0) - M1(0)
- PDist = P2(0) - P1(0)
- ThisDrawing.MSpace = True
- CenPt(0) = (M2(0) + M1(0)) / 2: CenPt(1) = (M2(1) + M1(1)) / 2
-
- Vp.StandardScale = acVpCustomScale
- 'This is how it is done, set the ZoomCenter
- ThisDrawing.Application.ZoomCenter CenPt, 1
- Vp.CustomScale = PDist / Mdist
- ThisDrawing.MSpace = False
- End Sub
|