- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I know I am doing something simple wrong here, but after 2 days of messing with it I am throwing my hands up.
I am using VB.net 2017. I need to allow a user to select a part or a sub-assembly in an assembly. I want to return the occurrence object from the selection.
When the code runs it never reaches the oInteractEvents_OnTerminate or oSelectEvents_OnSelect subs. It just remains in the Do While bStillSelecting loop.
Any help would be greatly appreciated!
Here is my entire class...
Imports System.Runtime.InteropServices
Imports System.Activator
Imports System.Type
Public Class clsSelect
' Declare the event objects
Private WithEvents oInteractEvents As Inventor.InteractionEvents
Private WithEvents oSelectEvents As Inventor.SelectEvents
' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean
Public invApp As Inventor.Application
Public Function Pick(filter As Inventor.SelectionFilterEnum) As Object
Call StartInventor()
' Initialize flag.
bStillSelecting = True
' Create an InteractionEvents object.
oInteractEvents = invApp.CommandManager.CreateInteractionEvents
' Ensure interaction is enabled.
oInteractEvents.InteractionDisabled = False
' Set a reference to the select events.
oSelectEvents = oInteractEvents.SelectEvents
' Set the filter using the value passed in.
oSelectEvents.AddSelectionFilter(Inventor.SelectionFilterEnum.kAllEntitiesFilter)
' Start the InteractionEvents object.
oInteractEvents.Start()
' Loop until a selection is made.
Do While bStillSelecting
invApp.UserInterfaceManager.DoEvents()
Loop
' Get the selected item. If more than one thing was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As Inventor.ObjectsEnumerator
oSelectedEnts = oSelectEvents.SelectedEntities
If oSelectedEnts.Count > 0 Then
Pick = oSelectedEnts.Item(1)
Else
Pick = Nothing
End If
' Stop the InteractionEvents object.
oInteractEvents.Stop()
invApp.CommandManager.StopActiveCommand()
' Clean up.
oSelectEvents = Nothing
oInteractEvents = Nothing
End Function
Private Sub oInteractEvents_OnTerminate()
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As View)
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
Public Function StartInventor() As Boolean
'Everything in this sub is fluff stolen from
'elsewhere with variable names changed to suit my purposes
Try
invApp = Marshal.GetActiveObject("Inventor.Application")
Return True
Catch ex As Exception
Try
Dim invAppType As Type = GetTypeFromProgID("Inventor.Application")
invApp = CreateInstance(invAppType)
invApp.Visible = True
'Note: if you shut down the Inventor session that was started
'this(way) there Is still an Inventor.exe running. We will use
'this Boolean to test whether or not the Inventor App will
'need to be shut down.
StartInventor = True
Catch ex2 As Exception
MsgBox(ex2.ToString(), MsgBoxStyle.Critical, "Unable to get or start Inventor")
Return False
End Try
End Try
End Function
End Class
Master Drafter/ CAD Programmer
Using Inventor 2018
Solved! Go to Solution.