Inventor Customization

Inventor Customization

Reply
Distinguished Contributor
rschader
Posts: 255
Registered: ‎12-15-2003
Message 1 of 6 (1,337 Views)

Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)

1337 Views, 5 Replies
01-19-2012 12:26 PM

I have a macro that I used to get XY points on a drawing sheet in order to place items. Now that I am on 64bit 2012, it still functions, but it is very erratic and I have to get it to work by clicking the mouse repeatedly and much harder than usual. Eventually it takes and my symbol is placed! The crosshair cursor also blinks in and out during this time also. I am not selecting anything in the drawing, I just want to click on a blank area and get the drawing coordinates like I used to in previous versions. Wondering if there is some new method to get the mouse click and underlying xy point in 2012? Here is the code I have been using:

 

'class module clsGetPoint2D

Option Explicit
Public X As Double, Y As Double, Z As Double
Public JustifyRight As Boolean

' Declare the event objects
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oMouseEvents As Inventor.MouseEvents
' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean
_______________________________________________________________
Public Function GetPoint() As Point
' Initialize flag.
bStillSelecting = True

' Create an InteractionEvents object.
Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

' Define that we want mouse events rather than select events.
oInteractEvents.SelectionActive = False

oInteractEvents.StatusBarText = "Click mouse for 2D location"
oInteractEvents.SetCursor (kCursorBuiltInCrosshair)
' Set a reference to the mouse events.
Set oMouseEvents = oInteractEvents.MouseEvents

'Don't need move events
oMouseEvents.MouseMoveEnabled = False

' Start the InteractionEvents object.
oInteractEvents.Start

' Loop until a (2D) point in the IDW is selected.
Do While bStillSelecting
    ThisApplication.UserInterfaceManager.DoEvents
Loop

' Stop the InteractionEvents object.
oInteractEvents.Stop

' Clean up.
Set oMouseEvents = Nothing
Set oInteractEvents = Nothing
End Function
_____________________________________________________
Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    X = ModelPosition.X
    Y = ModelPosition.Y
    Z = ModelPosition.Z
    bStillSelecting = False
End Sub

 

 

Distinguished Contributor
rschader
Posts: 255
Registered: ‎12-15-2003
Message 2 of 6 (1,321 Views)

Re: Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)

01-20-2012 12:27 PM in reply to: rschader

I have noticed today that if I slowly pan the drawing with my spacepilot while this macro is running, then the mouse clicking and cursor are not erratic anymore and I can place my symbols and leaders from the macro much easier. Since I am using an outdated spacepilot driver which I cannot update unless I buy a new, supported device, for now I will just have to assume this is a bug caused by the spaceball drivers in Inventor? It would be nice if there was someway to programatically ignore the spaceball in VBA to avoid this issue perhaps? Still would be willing to look at new methods of getting the sheet position of a mouse click also.

Valued Contributor
ChrisVandeVoorde
Posts: 52
Registered: ‎01-05-2011
Message 3 of 6 (997 Views)

Re: Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)

12-19-2012 04:14 AM in reply to: rschader

Hello,

 

I want to use this code to get the coördinates of a point2D in a drawing view. But I can't get it to work.

I use Inventor 2013.

 

Can you help me on how to implement this code?

 

thank you!

Distinguished Contributor
rschader
Posts: 255
Registered: ‎12-15-2003
Message 4 of 6 (981 Views)

Re: Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)

12-20-2012 08:28 AM in reply to: rschader

The code I posted is simply for a class module. You need to have macro code elsewhere that calls this class module. Simplest case, something like:

 

Dim oGetPoint2D As New clsGetPoint2D

Call oGetPoint2D.GetPoint

MsgBox "X = " & oGetPoint2D.X & vbNewLine & "Y = " & oGetPoint2D.Y

 

I don't have 2013, but it should still work unless they made some drastic changes?

ADN Support Specialist
adam.nagy
Posts: 566
Registered: ‎03-26-2007
Message 5 of 6 (940 Views)

Re: Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)

01-11-2013 07:53 AM in reply to: rschader

Happy New Year!

One thing I would try is avoiding DoEvents and lets see if that helps:

Class1:

' members
Private WithEvents oInteractionEvents As InteractionEvents
Private WithEvents oMouseEvents As MouseEvents

Public Sub StartInteraction()

    Set oInteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents()

    ' subscribe to receive mouse events
    Set oMouseEvents = oInteractionEvents.MouseEvents
    
    oInteractionEvents.SelectionActive = False

    ' start interaction
    Call oInteractionEvents.Start
    
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)
    Set oMouseEvents = Nothing
    Set oInteractionEvents = Nothing
End Sub

Private Sub oInteractionEvents_OnTerminate()
    ' Nothing got selected - the user started another
    ' command or just cancelled this interaction
    Set oMouseEvents = Nothing
    Set oInteractionEvents = Nothing
End Sub

Module1:

Dim cls1 As Class1

Sub CheckInteractionEvents()
    Set cls1 = New Class1
    Call cls1.StartInteraction
End Sub

Cheers,



Adam Nagy
Developer Technical Services
Autodesk Developer Network
Distinguished Contributor
rschader
Posts: 255
Registered: ‎12-15-2003
Message 6 of 6 (935 Views)

Re: Mouse click event Inventor 2012 VBA is erratic(code worked fine in 2010)

01-11-2013 08:55 AM in reply to: adam.nagy

I will have to try that when I get a chance! I had wanted to switch to using CommandManager.Pick instead, but could find no way to use it to just capture a mouse click without actually picking anything.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.