Table of contents
TOC
Collapse the table of content
Expand the table of content

Shape.SpatialRelation Property (Visio)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Returns an integer that represents the spatial relationship of one shape to another shape. Both shapes must be on the same page or in the same master. Read-only.

Syntax

expression . SpatialRelation( OtherShape , Tolerance , Flags )

expression A variable that represents a Shape object.

Parameters

NameRequired/OptionalData TypeDescription
OtherShapeRequired[IVSHAPE]The other Shape object involved in the comparison.
ToleranceRequiredDoubleA distance in internal drawing units with respect to the coordinate space defined by the Shape object's parent.
FlagsRequiredIntegerFlags that influence the result. See Remarks for the values of this argument.

Return Value

Integer

Remarks

  • The integer returned can be any combination of the values defined in VisSpatialRelationCodes in the Visio type library. The SpatialRelation property returns zero (0) if the two shapes being compared are not in any of the relationships discussed in the table in the VisSpatialRelationCodes topic.

  • The Flags argument can be any combination of the values of the constants defined in the following table. These constants are declared in VisSpatialRelationFlags in the Visio type library. Use the NoShow cell to determine whether a Geometry section is hidden or visible. Hidden Geometry sections have a value of TRUE and visible Geometry sections have a value of FALSE in the NoShow cell.

** Constant**** Value**** Description**
visSpatialIncludeContainerShapes&;H80Include containers. By default, containers are not included.
visSpatialIncludeDataGraphics&;H40Includes data graphic callout shapes and their sub-shapes. By default, data graphic callout shapes and their subshapes are not included. If the parent shape is itself a data graphic callout, searches are made between the parent shape's geometry and non-callout shapes, unless this flag is set.
visSpatialIncludeGuides&;H2Considers a guide's Geometry section. By default, guides do not influence the result.
visSpatialIncludeHidden&;H10Reserved for future use. Do not use.
visSpatialIgnoreVisible&;H20Does not consider visible Geometry sections. By default, visible Geometry sections influence the result.

Note When it compares two shapes, the SpatialRelation property does not consider the width of a shape's line, shadows, line ends, control points, or connection points.

Example

This Microsoft Visual Basic for Applications (VBA) example shows how to use the SpatialRelation property in an event handler for the ShapeAdded event to determine the spatial relationship between shapes.

Before adding the following code to your VBA project, make sure there is at least one shape on the drawing page. Then, after adding the code, add another shape to your drawing.

Public Sub Document_ShapeAdded(ByVal Shape As IVShape) 

    Dim vsoShapeOnPage As Visio.Shape  
    Dim intTolerance As Integer 
    Dim intReturnValue As VisSpatialRelationCodes  
    Dim intFlag As VisSpatialRelationFlags  
    Dim strReturn As String 
    On Error GoTo errHandler  

    'Initialize tolerance argument. 
    intTolerance = 0.25  

    'Initialize flags argument. 
    intFlag = visSpatialIncludeHidden  
    For Each vsoShapeOnPage In ActivePage.Shapes  

        'Get the spatial relationship. 
        intReturnValue = Shape.SpatialRelation(vsoShapeOnPage, _  
            intTolerance, intFlag)  

        'Convert return code to string value. 
        Select Case intReturnValue       
            Case VisSpatialRelationCodes.visSpatialContain  
                strReturn = "Contains"  
            Case VisSpatialRelationCodes.visSpatialContainedIn  
                strReturn = "is Contained in"  
            Case VisSpatialRelationCodes.visSpatialOverlap  
                strReturn = "overlaps"  
            Case VisSpatialRelationCodes.visSpatialTouching  
                strReturn = "is touching"  
            Case Else 
                strReturn = "has no relation with"  
        End Select  

        'Display relationship in the shape's text. 
        vsoShapeOnPage.Text = Shape.Name &; " " &; strReturn &; " " &; _  
            vsoShapeOnPage.Name  

    Next  

errHandler:  

End Sub
© 2017 Microsoft