Hit test example

D

dave

Hi All,

i want to put some functionality into a shape. basically something like the
Hit Test example. Unfortunately I not confortable with the code. After
reading the example several times I'm still quite lost. Basically I want to
drop one shape onto another which would trigger an event. The event would
be the resizing of the first shape using parameters from the second shape.
Something like A square shape dropped onto a retangle shape. The square
shape width and length would be changed to the width of the retangle less
one inch. Any points would be great.
Dave
 
D

David Parker [Visio MVP]

HitTest requires that you know both of the shapes in question already,
however SpatialNeighbors is more flexible.
I suggest you look it up in the developer help file. There is example code
there.
 
D

dave

Hi David
Thanks for the reply,
I've read through the spatail neighbor thingy several times. I've tried
getting the sample to run without success.
it fails at Set vsoReturnedSelection =
Shape.SpatialNeighbors(intSpatialRelation, intTolerance, 0)
Any points would be appreciated
 
D

dave

This is the sample code I'm using to research spatial property codes.. But
It doesn't fire the event for some reason (probably cause i don't understand
the event)

the example reads as follows

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.

Can you just add this to your project. Even if this is the only VBA within
the Project?


Public Sub Document_ShapeAdded(ByVal Shape As IVShape)
Dim vsoShapeOnPage As Visio.Shape
Dim intTolerance As Double 'This was my correction of the Developer's
Sample Code

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top