Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Addin 'DoEvents' Doesn't work

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
matt_jlt
1442 Views, 7 Replies

Addin 'DoEvents' Doesn't work

I have a simple selection class I have been using successfully as a macro for a long time. I tried converting it to an addin but have hit a speed bump with 'DoEvents'. It doesn't work at all in an addin. If anyone could help me sort this out it would be great. I inserted all of the relevant code below.

 

Thanks, Matt.

 

I have tried the following in place of the DoEvents

 

Application.DoEvents

ThisApplication.DoEvents

System.Windows.Forms.Application.DoEvents

 

Below is a section of the module code to initialise selection

 

        ' Get user input for mouse position on click
        Dim oGetPoint As New clsSelectPoint
        Dim oCP As Point2d = oGetPoint.GetPoint

 

Below is the select class

 

Public Class clsSelectPoint
' Declare the event objects
    Private WithEvents oInteraction As InteractionEvents
    Private WithEvents oMouseEvents As MouseEvents

    ' Declare a flag that's used to determine when selection stops.
    Private bStillSelecting As Boolean
    Private oSelectedPoint As Inventor.Point2d

    Public Function GetPoint() As Inventor.Point2d
        ' Initialize flag.
        bStillSelecting = True

        ' Create an InteractionEvents object.
        oInteraction = ThisApplication.CommandManager.CreateInteractionEvents()

        ' Set a reference to the mouse events.
        oMouseEvents = oInteraction.MouseEvents

        ' Disable mouse move since we only need the click.
        oMouseEvents.MouseMoveEnabled = False

        ' The InteractionEvents object.
        oInteraction.Start()

        ' Loop until a selection is made.
        Do While bStillSelecting
            'DoEvents ' ############# This is where the issue is
        Loop

        ' Set the return variable with the point.
        GetPoint = oSelectedPoint

        ' Stop the InteractionEvents object.
        oInteraction.Stop()

        ' Clean up.
        oMouseEvents = Nothing
        oInteraction = Nothing
    End Function


    Private Sub oInteraction_OnTerminate()
        ' Set the flag to indicate we're done.
        bStillSelecting = False
    End Sub


    Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View)
        'oSelectedPoint = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y) ' Temporarily commented out
        bStillSelecting = False
        MessageBox.Show("mouse pressed")
    End Sub

End Class

 

7 REPLIES 7
Message 2 of 8
cadull_rb
in reply to: matt_jlt

Hi Matt,

 

I think you might be looking for ThisApplication.UserInterfaceManager.DoEvents.

 

Regards,

cadull

Message 3 of 8
matt_jlt
in reply to: cadull_rb

Thanks cadull, I tried that but it does the same thing as the others, as soon as it gets to the DoEvents it gets stuck in the interaction. clicking the mouse doesn't do anything. I have to press escape to get out of it which cancels the command.

Message 4 of 8
cadull_rb
in reply to: matt_jlt

Hi Matt,

 

I understand VB has some auto event subscription based on the method name, but I don't know how this is configured or if you need to manually subscribe to the event in this case. In C#, we would add a line like:

oMouseEvents.OnMouseClick += oMouseEvents_OnMouseClick;

Regards,

cadull

Message 5 of 8
cadull_rb
in reply to: cadull_rb

Message 6 of 8
matt_jlt
in reply to: cadull_rb

Thanks cadull, i'll have to give that a go. I didn't even think about that. I'll add the event handler and see how it goes. If it works i'll post the final code here.

Regards, Matt.

Message 7 of 8
matt_jlt
in reply to: cadull_rb

All good, worked it out. Thanks for the help cadull. I had completely forgotton the event handler.
Just needed to add the following to the end of the mouse click sub.

 

Handles oMouseEvents.OnMouseClick

 Regards, Matt.

Message 8 of 8
mucip
in reply to: matt_jlt

Dear Matt,

Can you please paste complete your code (class and pick event) and share with us?...

 

Regards,

Mucip:)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report