Hi,
I don't know which language you are using to develop, but in every language it's possible to detect selections in inventor.
There are several events, they called select events.
You can catch OnSelect, OnPreselect, OnUnselect, OnStopPreSelect events whith them.
I will give example on VB.Net
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents
Sub StartEvent(ByVal invapp As Inventor.Application)
' Create an InteractionEvents object.
Set oInteractEvents = invapp.CommandManager.CreateInteractionEvents
' Ensure interaction is enabled.
oInteractEvents.InteractionDisabled = False
' Set a reference to the select events.
Set oSelectEvents = oInteractEvents.SelectEvents
Register()
End Sub
Public Sub Register()
AddHandler oSelectEvents.OnSelect, AddressOf SelectEvents_OnSelect_Handler
AddHandler oSelectEvents.OnUnSelect, AddressOf SelectEvents_OnUnSelect_Handler
End Sub
Public Sub UnRegister()
RemoveHandler oSelectEvents.OnUnSelect, AddressOf SelectEvents_OnUnSelect_Handler
RemoveHandler oSelectEvents.OnSelect, AddressOf SelectEvents_OnSelect_Handler
End Sub
Public Sub SelectEvents_OnSelect_Handler(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View)
If JustSelectedEntities(JustSelectedEntities.Count - 1) Is PartDocument Then
Dim selectedPart As PartDocument
Set selectedPart = JustSelectedEntities(JustSelectedEntities.Count - 1)
'SelectedPart is your last selected Part. You can look for it's name, internal name, path rtc. to see if its okay to open form or not.
End If
End Sub
Public Sub SelectEvents_OnUnSelect_Handler(ByVal UnSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View)
If UnSelectedEntities(UnSelectedEntities.Count - 1) Is PartDocument Then
Dim selectedPart As PartDocument
Set selectedPart = UnSelectedEntities(UnSelectedEntities.Count - 1)
'SelectedPart is your last unselected Part. You can look for it's name, internal name, path rtc. to see if its okay to close form or not.
End If
End Sub
You should define events like that. When you want to end the event, you can use Unregister function to do it.
Also in this page, there are great examples for to learn how to use select events.
https://spiderinnet2.typepad.com/blog/2013/04/inventor-api-vbnet-select-events.html
Regards
Devrim
If my answer is solved your problem, please mark it as Solution
Freundliche Grüße / Kind Regards