Mouse Event does not work in 2011. 2009 no problems.

Mouse Event does not work in 2011. 2009 no problems.

chuck_b
Enthusiast Enthusiast
998 Views
5 Replies
Message 1 of 6

Mouse Event does not work in 2011. 2009 no problems.

chuck_b
Enthusiast
Enthusiast

Code below works perfect in IV 2009 but doesn't work in IV 2011.  Both running on Windows XP 64bit.  All the program does is by running the TestSelection Sub the user clicks on Inventor screen and the code will place WorkPoints (Must have an assembly doc open).  User hits esc button to quit.  Very simple and works great in 2009 but with 2011 once the code hits the  oInteractEvents.Start the  oInteractEvents_OnTerminate() event gets triggered for no reason.  Anyone know why?  Planning on upgrading but always find something that prevents me from doing so.

 

thanks,  Chuck

 

 

Public Sub TestSelection()
    Call SetToTopView
    Dim clsPick As New clsSelect
    
    clsPick.WaitForClick
End Sub
Sub SetToTopView()
    Dim oView As View
    Set oView = ThisApplication.ActiveView
    
    Dim oCamera As Camera
    Set oCamera = oView.Camera
    oCamera.ViewOrientationType = kTopViewOrientation
    oCamera.Apply
End Sub

'Class module code

Private WithEvents oInteractEvents As InteractionEvents

Private WithEvents oMouseEvents As MouseEvents

Private bStillSelecting As Boolean




Public Function WaitForClick() As Variant

    bStillSelecting = True
    Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
    
    oInteractEvents.SelectionActive = True

    Set oMouseEvents = oInteractEvents.MouseEvents

    oMouseEvents.PointInferenceEnabled = True

    oMouseEvents.MouseMoveEnabled = False
    oInteractEvents.Start

    Do While bStillSelecting
        DoEvents
    Loop
  
    oInteractEvents.Stop
    Set oMouseEvents = Nothing
   
    Set oInteractEvents = Nothing
    
End Function


Private Sub oInteractEvents_OnTerminate()
    bStillSelecting = False
    MsgBox "Adding work points complete."
End Sub

Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    Dim oPickPoint As Point
    Set oPickPoint = ModelPosition
    oPickPoint.Y = -0.5 * 2.54
    
    Dim oAssy As AssemblyDocument
    Set oAssy = ThisApplication.ActiveDocument
    
    Dim aPoint As WorkPoint
    Set aPoint = oAssy.ComponentDefinition.WorkPoints.AddFixed(oPickPoint)
    aPoint.Name = "FP " & aPoint.Name
End Sub

 

 

0 Likes
Accepted solutions (1)
999 Views
5 Replies
Replies (5)
Message 2 of 6

chuck_b
Enthusiast
Enthusiast
Private WithEvents oInteractEvents As InteractionEvents
0 Likes
Message 3 of 6

sanjay.ramaswamy
Alumni
Alumni

Try replacing DoEvents with ThisApplication.UserInterfaceManager.DoEvents

0 Likes
Message 4 of 6

chuck_b
Enthusiast
Enthusiast

Thanks Sanjay,

 

I tried that and it didn't make a difference because I think it doesn't make it to that code in IV 2011.  At the time I was hoping that was all it was.  It just gets to this line below.

oInteractEvents.Start

 

And fires this event right after

 

Private Sub oInteractEvents_OnTerminate()

 

I would think IV 2009 would have not worked either because they are both native 64 bit.  IV 2009 works with just DoEvents but I have updated my code to be safe but still no luck with 2011

0 Likes
Message 5 of 6

sanjay.ramaswamy
Alumni
Alumni
Accepted solution

Yes, I see the issue also. The line of code causing the problem seems to be this:

 

oMouseEvents.PointInferenceEnabled = True

I commented out this line and the macro then seems to work. Doesn't look like you are using point inferences in your code, so perhaps you'll be ok removing this line. If not, post back and we'll see if we can find another workaround.

 

I'll have this issue filed in our database. Thanks for reporting this.

 

0 Likes
Message 6 of 6

chuck_b
Enthusiast
Enthusiast

That works!  Thanks!!  Didn't need oMouseEvents.PointInferenceEnabled = True just came with a sample that I copied.  Thanks again...I would of never have found the cause on my own.

 

Chuck

0 Likes