缩放视口
**** Hidden Message ***** 您是否忽略了纸张空间视图本身? 我不认为你能从一个选择中到达那里。试试这个Public Sub VPzXP2()
Dim oLayout As AcadLayout
Dim oLayouts As AcadLayouts
Dim B As AcadBlock
Dim Ent As AcadEntity
Dim vp As AcadPViewport
Dim N As Double
Set oLayouts = ThisDrawing.Layouts
For Each oLayout In oLayouts
If UCase(oLayout.Name) = "MODEL" Then GoTo skip
Set B = oLayout.Block
For Each Ent In B
If Not TypeOf Ent Is AcadPViewport Then GoTo skipEnts
If Ent.ObjectID = B(0).ObjectID Then GoTo skipEnts
Set vp = Ent
If vp.DisplayLocked = True Then
vp.DisplayLocked = False
End If
ThisDrawing.ActiveLayout = oLayout
vp.Display True
ThisDrawing.MSpace = True
ZoomExtents
N = CDbl(ThisDrawing.GetVariable("DIMSCALE"))
N = 1 / N
ZoomScaled N, 2
ThisDrawing.MSpace = False
vp.DisplayLocked = True
skipEnts:
Next Ent
skip:
Next oLayout
End Sub 不,我知道我忘记了什么我能看到它激活了它,但大脑没有工作 布莱科,效果很好。我想我需要更多的咖啡来让大脑运转起来。 这一直是一种痛苦,我希望我能找到更好的方法。 如果您稍微改变一下逻辑,您可以进一步整理代码并摆脱GOTO:
Public Sub VPzXP2()
Dim oLayout As AcadLayout
Dim oLayouts As AcadLayouts
Dim B As AcadBlock
Dim Ent As AcadEntity
Dim vp As AcadPViewport
Dim N As Double
Set oLayouts = ThisDrawing.Layouts
For Each oLayout In oLayouts
If UCase(oLayout.Name)"MODEL" Then
Set B = oLayout.Block
For Each Ent In B
If TypeOf Ent Is AcadPViewport Then
If Ent.ObjectIDB(0).ObjectID Then
Set vp = Ent
If vp.DisplayLocked = True Then
vp.DisplayLocked = False
End If
ThisDrawing.ActiveLayout = oLayout
vp.Display True
ThisDrawing.MSpace = True
ZoomExtents
N = CDbl(ThisDrawing.GetVariable("DIMSCALE"))
N = 1 / N
ZoomScaled N, 2
ThisDrawing.MSpace = False
vp.DisplayLocked = True
End If
End If
Next Ent
End If
Next oLayout
End Sub
干得好DaveR每天都学东西 我注意到有些人不喜欢goto,我不知道为什么。
我认为它们使代码更易于阅读。 我认为这是因为它有可能生成意大利面条式的代码。如果使用得当,它很好,但也有人认为使用它是不好的做法。
页:
[1]
2