Shape.SpatialRelation Property

Visio Automation Reference

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.

Version Information
 Version Added:  Visio 2000

Syntax

expression.SpatialRelation(OtherShape, Tolerance, Flags)

expression   A variable that represents a Shape object.

Parameters

Name Required/Optional Data Type Description
OtherShape Required [IVSHAPE] The other Shape object involved in the comparison.
Tolerance Required Double A distance in internal drawing units with respect to the coordinate space defined by the Shape object's parent.
Flags Required Integer Flags that influence the result. See Remarks for the values of this argument.

Return Value
Integer

Remarks

  • The interger 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.
    Constant Value Description

    visSpatialIncludeDataGraphics

    &H40

    Includes 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

    &H2

    Considers a guide's Geometry section. By default, guides do not influence the result.

    visSpatialIncludeHidden

    &H10

    Considers hidden Geometry sections. By default, hidden Geometry sections do not influence the result.

    visSpatialIgnoreVisible

    &H20

    Does not consider visible Geometry sections. By default, visible Geometry sections influence the result.

    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.
ms367944.vs_note(en-us,office.12).gif  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.

Visual Basic for Applications
  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

See Also