SpatialRelation Property [Visio 2003 SDK Documentation]
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.
intRet = object**.SpatialRelation**(OtherShape, Tolerance, Flags)
intRet Integer. The relationship between two shapes. See Remarks for the values of this argument.
object Required. An expression that returns a Shape object.
OtherShape Required. 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.
Version added
2000
Remarks
The intRet argument 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 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.
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
Applies to | Shape object
See Also | DistanceFrom property | DistanceFromPoint property | SpatialNeighbors property | SpatialSearch property