SpacialSearch not returning selected object always

M

Matt

Hello all,

We have to customize context menu depending on the object selected.
And we use SpatialSearch to get the selected object. But it is not getting
the selected object always.
We we right click it is getting the object previously selected.

Following is what we did

We add the code
m_evtList.AddAdvise((short)Visio.VisEventCodes.visEvtCodeMouseDown,
m_evtSink, "", "");

And in VisEventProc, we add the following code

case (short)VisEventCodes.visEvtCodeMouseDown :
{
//Handle the MouseDown event.
myView.OnMouseDown(source, subject);
break;
}

And on onMousedown
public void OnMouseDown(object source, object subject)
{
// Find object behind mouse position
vsoPage = vsoApp.ActivePage;
Selection sel = vsoPage.get_SpatialSearch(lastMouseMoveEvent.x,
lastMouseMoveEvent.y,
(short)VisSpatialRelationCodes.visSpatialContainedIn,
..001,
(short)VisSpatialRelationFlags.visSpatialIncludeHidden);

// sel.count is 0 sometimes.
}

Is there any fix/ workaround for the issue

Please help

Matt
 
P

Paul Herber

Hello all,

We have to customize context menu depending on the object selected.
And we use SpatialSearch to get the selected object. But it is not getting
the selected object always.
We we right click it is getting the object previously selected.

Following is what we did

We add the code
m_evtList.AddAdvise((short)Visio.VisEventCodes.visEvtCodeMouseDown,
m_evtSink, "", "");

And in VisEventProc, we add the following code

case (short)VisEventCodes.visEvtCodeMouseDown :
{
//Handle the MouseDown event.
myView.OnMouseDown(source, subject);
break;
}

And on onMousedown
public void OnMouseDown(object source, object subject)
{
// Find object behind mouse position
vsoPage = vsoApp.ActivePage;
Selection sel = vsoPage.get_SpatialSearch(lastMouseMoveEvent.x,
lastMouseMoveEvent.y,
(short)VisSpatialRelationCodes.visSpatialContainedIn,
.001,
(short)VisSpatialRelationFlags.visSpatialIncludeHidden);

// sel.count is 0 sometimes.
}

You might be getting an exception during this routine.
1. check that vsoPage is valid
2. put an exception handler around the spatial search.

And -
check the values/units of lastMouseMoveEvent.x and y
SpatialSearch takes only internal units (inches) for its parameters,
if the x and y values are not in inches then the coords will be in the
wrong area of the diagram.
 
M

Matt

There is no exception. lastMouseMoveEvent.x and y is correct only.
Second time when we right click Spacial Search will return selection at the
same x and y or if i left click and then right click

I fixed it by moving the code from mousedown to mouseup. Now it works fine.

Thanks

Matt
 

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