Table of contents
TOC
折叠目录
展开目录

Page.BoundingBox 方法 (Visio)Page.BoundingBox Method (Visio)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

返回一个将页面的形状紧密封闭在内的矩形。Returns a rectangle that tightly encloses the shapes of a page.

语法Syntax

表达式BoundingBox标志lpr8Leftlpr8Bottomlpr8Rightlpr8Topexpression . BoundingBox( Flags , lpr8Left , lpr8Bottom , lpr8Right , lpr8Top )

表达式_一个表示一个Page对象的变量。_expression A variable that represents a Page object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
FlagsFlags必需RequiredIntegerInteger影响为各个形状计算的边框的标志,这些形状影响结果边框。Flags that influence the bounding box calculated for each shape that contributes to the resulting bounding box.
lpr8Leftlpr8Left必需RequiredDoubleDouble返回边框左边缘的 x 轴坐标值。Returns the x-coordinate of the left edge of the bounding box.
lpr8Bottomlpr8Bottom必需RequiredDoubleDouble返回边框下边缘的 y 轴坐标值。Returns the y-coordinate of the bottom edge of the bounding box.
lpr8Rightlpr8Right必需RequiredDoubleDouble返回边框右边缘的 x 轴坐标值。Returns the x-coordinate of the right edge of the bounding box.
lpr8Toplpr8Top必需RequiredDoubleDouble返回边框上边缘的 y 轴坐标值。Returns the y-coordinate of the top edge of the bounding box.

返回值Return Value

Nothing

注解Remarks

对于一个Shape对象, BoundingBox方法返回形状及其子形状紧密封闭在内的矩形。For a Shape object, the BoundingBox method returns a rectangle that tightly encloses the shape and its subshapes.

对于页面主控形状选择对象, BoundingBox方法返回页的、 主,或所选内容的形状和及其子形状紧密封闭在内的矩形。For a Page , Master , or Selection object, the BoundingBox method returns a rectangle that tightly encloses the page's, master's, or selection's shapes and their subshapes.

如果BoundingBox方法将返回错误,或者如果要求它返回包含零形状的矩形,该矩形返回是 {左: 0,底部: 0,右:-1 上:-1};否则,返回的矩形已离开小于或等于 (< =) 右侧和底部小于或等于 (< =) 顶部。返回的数字采用内部单位 (英寸) 是。If the BoundingBox method returns an error, or if it is asked to return the rectangle enclosing zero shapes, the rectangle returned is { left: 0, bottom: 0, right: -1, top: -1 }; otherwise, the rectangle returned has left less than or equal to (<=) right, and bottom less than or equal to (<=) top. The numbers returned are in internal units (inches).

返回单个形状的边框取决于其类型属性。The bounding rectangle returned for an individual shape depends on its Type property.

常量Constant说明Description
visTypePagevisTypePage相当于Page.BoundingBoxMaster.BoundingBoxEquivalent to Page.BoundingBox or Master.BoundingBox .
visTypeGroupvisTypeGroup将组及其子形状紧密封闭在内的矩形。Rectangle that tightly encloses the group and its subshapes.
visTypeShapevisTypeShape确定的矩形取决于标志。请参阅下表。Determined rectangle depends on flags. See the following table.
visTypeForeignObjectvisTypeForeignObject确定的矩形取决于标志。请参阅下表。Determined rectangle depends on flags. See the following table.
visTypeGuidevisTypeGuide确定的矩形取决于标志。请参阅下表。Determined rectangle depends on flags. See the following table.

该方法将引发异常的对象类型visTypeDocThe method will raise an exception for object type visTypeDoc .

Flags_参数有几位来控制边界框检索每个形状。如果多个下表中描述的位被设置,确定形状的矩形覆盖位所暗示的所有矩形。The _Flags argument has several bits that control the bounding box retrieved for each shape. If more than one of the bits described in the following table is set, the rectangle determined for the shape covers all rectangles implied by the bits.

标志FlagValue说明Description
visBBoxUprightWHvisBBoxUprightWH&;H1&;H1返回一个矩形,它是与将形状的宽度-高度框封闭在内的父形状所在的本地坐标系统平行的最小矩形。如果形状未旋转,则其垂直宽高框与其宽高框相同。形状几何图形中的路径不需要并且通常不会完全位于形状的宽高框之内。Returns a rectangle that is the smallest rectangle parallel to the local coordinate system of the shape's parent that encloses the shape's width-height box.If the shape is not rotated, its upright width-height box and its width-height box are the same. Paths in the shape's geometry need not and often do not lie entirely within the shape's width-height box.
visBBoxUprightTextvisBBoxUprightText&;H2&;H2返回一个矩形,它是与将形状文本封闭在内的父形状所在的本地坐标系统平行的最小矩形。Returns a rectangle that is the smallest rectangle parallel to the local coordinate system of the shape's parent that encloses the shape's text.
visBBoxExtentsvisBBoxExtents&;H4&;H4返回一个矩形,它是通过形状的几何图形描边的路径封闭在内的父形状所在的本地坐标系统平行的最小矩形。这可能大于或小于形状的垂直宽高框。确定类型visTypeForeignObject的形状的范围框等于该形状的垂直宽高框。Returns a rectangle that is the smallest rectangle parallel to the local coordinate system of the shape's parent that encloses the paths stroked by the shape's geometry.This may be larger or smaller than the shape's upright width-height box. The extents box determined for a shape of type visTypeForeignObject equals that shape's upright width-height box.
visBBoxIncludeHiddenvisBBoxIncludeHidden&;H 10&;H10包括隐藏的几何图形。Includes hidden geometry.
visBBoxIgnoreVisiblevisBBoxIgnoreVisible&;H20&;H20忽略可见的几何图形。Ignores visible geometry.
visBBoxIncludeDataGraphicsvisBBoxIncludeDataGraphics&;H10000&;H10000包括应用于页上的形状的数据图形标注形状(及其子形状)。默认情况下关闭。Includes data-graphic callout shapes (and their sub-shapes) that are applied to the shapes on the page. Off by default.
visBBoxIncludeGuidesvisBBoxIncludeGuides&;H1000&;H1000包括的类型为visTypeguide的形状的范围。默认情况下,忽略类型visTypeGuide的形状的范围。如果您请求参考线范围,然后只有垂直参考线的_x_位置和水平参考线的_y_位置影响返回的矩形。如果报告任何垂直参考线,则返回无穷大的_y_范围。如果报告任何水平参考线,则返回无穷大 x 扩展盘区。如果报告任何旋转的参考线,则返回无穷大的_x_和_y_范围。Includes extents for shapes of type visTypeguide . By default, the extents of shapes of type visTypeGuide are ignored.If you request guide extents, then only the x positions of vertical guides and the y positions of horizontal guides contribute to the rectangle that is returned. If any vertical guides are reported on, an infinite y extent is returned. If any horizontal guides are reported on, an infinite x extent is returned. If any rotated guides are reported on, infinite x and y extents are returned.
visBBoxDrawingCoordsvisBBoxDrawingCoords&;H2000&;H2000返回正在考虑其形状的页面或主控形状的绘图坐标系统中的数字。默认情况下,返回的数字采用所考虑形状的父形状的本地坐标系统中的绘图单位。Returns numbers in the drawing coordinate system of the page or master whose shapes are being considered. By default, the returned numbers are drawing units in the local coordinate system of the parent of the considered shapes.
visBBoxNoNonPrintvisBBoxNoNonPrint&;H4000&;H4000忽略非打印形状的范围。如果某一形状的 NonPrinting 单元格的值不为零或者该形状仅属于非打印图层,则它是非打印形状。Ignores the extents of shapes that are nonprinting. A shape is nonprinting if the value of its NonPrinting cell is non-zero or it belongs only to nonprinting layers.

范围矩形是使用形状笔划的中心来确定的;它并不考虑笔划的宽度。矩形也不包括任何由阴影或线端标记覆盖的区域。Microsoft Visio 没有公布确定形状的“黑位”框(经调整以便将笔划宽度、阴影和线端包含在内的范围框)的方法。The extents rectangle is determined using the center of the shape's strokes; it does not take into account the width of the strokes. Nor does the rectangle include any area covered by shadows or line end markers. Microsoft Visio does not expose a means to determine a shape's "black bits" box, that is, the extents box adjusted to account for stroke widths, shadows, and line ends.

形状可能有位于该形状报告的所有矩形边框之外的控制点或连接点。通过查询形状单元格的结果,您可以确定控制点和连接点的位置。A shape may have control points or connection points that lie outside any of the bounding rectangles reported by the shape. You can determine the position of control points and connection points by querying results of the shape's cells.

示例Example

下面的过程将打印在立即窗口中所选形状的边界框的尺寸。如果在活动窗口中选择多个形状,将显示一个消息框,指示错误。在所有情况下,绘图的页面或主控形状所属的单位中报告结果。这意味着,如果该形状是子形状的一组, visBBoxDrawingCoords将作为一个标志给BoundingBox方法。The following procedure prints the dimensions of the bounding box of the selected shape in the Immediate window. If more than one shape is selected in the active window, a message box indicating an error is displayed. In all cases, results are reported in the drawing units of the page or master to which the shape belongs. This means that if the shape is a subshape of a group, visBBoxDrawingCoords is passed as a flag to the BoundingBox method.

如果该形状是一个指南,该过程将visBBoxIncludeGuides传递给BoundingBox方法,以便该形状将被视为具有扩展盘区。为该形状报告三个矩形:If the shape is a guide, the procedure passes visBBoxIncludeGuides to the BoundingBox method so that the shape will be considered to have extent. Three rectangles are reported for the shape:

  • visBBoxUprightWH : 环绕形状的宽度-高度框的垂直框visBBoxUprightWH : an upright box that encloses the shape's width-height box

  • visBBoxUprightText : 环绕形状的文本框中垂直框visBBoxUprightText : an upright box that encloses the shape's text box

  • visBBoxExtents : 垂直框中包含该形状的路径visBBoxExtents : an upright box that encloses the shape's paths

要运行以下宏,请确保在 Visio 绘图页上只选择了一个形状。To run this macro, make sure exactly one shape is selected on the Visio drawing page.


Public Sub BoundingBox_Example() 

 Dim vsoSelection As Visio.Selection 
 Set vsoSelection = ActiveWindow.Selection 
 vsoSelection.IterationMode = visSelModeSkipSub 

 If vsoSelection.Count <> 1 Then 
 MsgBox "BoundingBox_Example() expects exactly one selected shape." 

 Else 

 Dim vsoShape As Visio.Shape 
 Set vsoShape = vsoSelection(1) 
 Dim intFlags As Integer 
 intFlags = 0 

 If vsoShape.ContainingShape.Type = visTypeGroup Then 

 intFlags = visBBoxDrawingCoords 

 End If 

 If vsoShape.Type = visTypeGuide Then 

 intFlags = intFlags + visBBoxIncludeGuides 

 End If 

 Dim dblTop As Double 
 Dim dblBottom As Double 
 Dim dblLeft As Double 
 Dim dblRight As Double 

 vsoShape.BoundingBox intFlags + visBBoxUprightWH, dblLeft, dblBottom, dblRight, dblTop 
 Debug.Print "Upright WH "; _ 
 "dblLeft:" &; Application.FormatResult(dblLeft, "in", "", "#0.00 u"); _ 
 "dblBottom:" &; Application.FormatResult(dblBottom, "in", "", "#0.00 u"); _ 
 "dblRight:" &; Application.FormatResult(dblRight, "in", "", "#0.00 u"); _ 
 "dblTop:" &; Application.FormatResult(dblTop, "in", "", "#0.00 u") 

 vsoShape.BoundingBox intFlags + visBBoxUprightText, dblLeft, dblBottom, dblRight, dblTop 
 Debug.Print "Upright text "; _ 
 "dblLeft:" &; Application.FormatResult(dblLeft, "in", "", "#0.00 u"); _ 
 "dblBottom:" &; Application.FormatResult(dblBottom, "in", "", "#0.00 u"); _ 
 "dblRight:" &; Application.FormatResult(dblRight, "in", "", "#0.00 u"); _ 
 "dblTop:" &; Application.FormatResult(dblTop, "in", "", "#0.00 u") 

 vsoShape.BoundingBox intFlags + visBBoxExtents, dblLeft, dblBottom, dblRight, dblTop 
 Debug.Print "Bounding Box "; _ 
 "dblLeft:" &; Application.FormatResult(dblLeft, "in", "", "#0.00 u"); _ 
 "dblBottom:" &; Application.FormatResult(dblBottom, "in", "", "#0.00 u"); _ 
 "dblRight:" &; Application.FormatResult(dblRight, "in", "", "#0.00 u"); _ 
 "dblTop:" &; Application.FormatResult(dblTop, "in", "", "#0.00 u") 

 End If 

End Sub

下面的宏将使用BoundingBox方法和ShapesOverlap()函数来确定一个形状 (vsoShape2) 重叠另一 (vsoShape1)。The following macro uses the BoundingBox method and the ShapesOverlap() function to determine if one shape (vsoShape2) overlaps another (vsoShape1).

Public Sub OverlappingShapes_Example() 

 Dim vsoShape1 As Visio.Shape 
 Dim vsoShape2 As Visio.Shape 
 Dim blsIsOverlapping As Boolean 


 Set vsoShape1 = Application.ActiveWindow.Page.Drop(Application.Documents.Item("BASIC_U.VSS").Masters.ItemU("Square"), 3, 9) 

 Set vsoShape2 = Application.ActiveWindow.Page.Drop(Application.Documents.Item("BASIC_U.VSS").Masters.ItemU("Pentagon"), 3, 8) 

 blsIsOverlapping = ShapesOverlap(vsoShape2, vsoShape1) 

 If blsIsOverlapping Then 
 Debug.Print "Shapes overlap." 
 Else 
 Debug.Print "Shapes do not overlap." 
 End If 

End Sub 


Private Function ShapesOverlap(vsoShape1 As IVShape, vsoShape2 As IVShape) As Boolean 

 Dim dblLeft1 As Double 
 Dim dblLeft2 As Double 
 Dim dblBottom1 As Double 
 Dim dblBottom2 As Double 
 Dim dblRight1 As Double 
 Dim dblRight2 As Double 
 Dim dblTop1 As Double 
 Dim dblTop2 As Double 

 vsoShape1.BoundingBox Flags + visBBoxExtents, dblLeft1, dblBottom1, dblRight1, dblTop1 
 vsoShape2.BoundingBox Flags + visBBoxExtents, dblLeft2, dblBottom2, dblRight2, dblTop2 

 If ((dblLeft2 >= dblLeft1 And dblLeft2 <= dblRight1) Or _ 
 (dblRight2 >= dblLeft1 And dblRight2 <= dblRight1)) And _ 
 ((dblTop2 >= dblBottom1 And dblTop2 <= dblTop1) Or _ 
 (dblBottom2 >= dblBottom1 And dblBottom2 <= dblTop1)) Then 
 ShapesOverlap = True 
 Else 
 ShapesOverlap = False 
 End If 

End Function
© 2018 Microsoft