Message 1 of 1
MiniToolbar's EnableApply property not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a problem with the MiniToolbar in Inventor API. When I set MiniToolbar.EnableApply = False, the Apply button remains fully enabled - it doesn't visually change to a disabled state and can still be clicked by the user. This is different from the OK button, which properly disables (grays out and becomes unclickable) when I set EnableOK = False.
Here's my test log showing the issue:
14:01:00: Initial state: EnableOK = False, EnableApply = False
14:01:01: After selection: Bodies = 1, EnableOK = True, EnableApply = True
14:01:02: Apply button clicked: Bodies = 1, EnableApply before = True
14:01:03: After Apply and reset: EnableOK = False, EnableApply = False
14:01:03: After view update: EnableOK = False, EnableApply = False
14:01:27: Apply button clicked: Bodies = 0, EnableApply before = False
Note that at 14:01:03, I set EnableApply = False, but at 14:01:27 the Apply button was still clickable. When I check the property value it correctly returns False, but the button's visual state and functionality don't change at all.
Is it a bug?
iLogic:
Sub Main()
oApp = ThisApplication
oLog = ""
isRunning = True
' Check if a part document is open
If Not TypeOf oApp.ActiveDocument Is PartDocument Then
MessageBox.Show("Please open a part document")
Exit Sub
End If
oPartDoc = oApp.ActiveDocument
' Create InteractionEvents
oInteractionEvents = oApp.CommandManager.CreateInteractionEvents
oInteractionEvents.Name = "MiniToolbar Test"
' Setup SelectEvents
oSelectEvents = oInteractionEvents.SelectEvents
oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kPartBodyFilter)
oSelectEvents.Enabled = True
' Set up event handlers
AddHandler oSelectEvents.OnSelect, AddressOf OnSelect
AddHandler oSelectEvents.OnUnSelect, AddressOf OnUnSelect
' Create MiniToolbar
oMiniToolbar = oInteractionEvents.CreateMiniToolbar()
oMiniToolbar.ShowOK = True
oMiniToolbar.ShowApply = True
oMiniToolbar.ShowCancel = True
' Disable buttons by default
oMiniToolbar.EnableOK = False
oMiniToolbar.EnableApply = False
WriteLog("Initial state: EnableOK = " & oMiniToolbar.EnableOK & ", EnableApply = " & oMiniToolbar.EnableApply)
' Add info label
oMiniToolbar.Controls.AddLabel("InfoLabel", "Bodies selected: 0", "Information")
' Set toolbar position
Dim oPoint As Point2d = oApp.TransientGeometry.CreatePoint2d(100, 100)
oMiniToolbar.Position = oPoint
' Set up button handlers
AddHandler oMiniToolbar.OnOK, AddressOf OnOK
AddHandler oMiniToolbar.OnApply, AddressOf OnApply
AddHandler oMiniToolbar.OnCancel, AddressOf OnCancel
oMiniToolbar.Visible = True
' Start interactive events
oInteractionEvents.Start()
WriteLog("Events started")
' Main loop
Do While isRunning
oApp.UserInterfaceManager.DoEvents()
Loop
' Cleanup
Cleanup()
' Show full log at the end
MessageBox.Show(oLog, "MiniToolbar Test Log")
End Sub
' Global variables
Public oApp As Inventor.Application
Public oPartDoc As PartDocument
Public oInteractionEvents As InteractionEvents
Public oSelectEvents As SelectEvents
Public oMiniToolbar As MiniToolbar
Public oLog As String
Public isRunning As Boolean
' Logging function
Sub WriteLog(message As String)
oLog = oLog & message & vbCrLf
' Create or open log file
Dim logPath As String = "C:\Temp\MiniToolbarTest.log"
Dim fileStream As System.IO.StreamWriter
Try
fileStream = New System.IO.StreamWriter(logPath, True)
fileStream.WriteLine(DateTime.Now.ToString() & ": " & message)
fileStream.Close()
Catch ex As Exception
MessageBox.Show("Log writing error: " & ex.Message)
End Try
End Sub
' OnSelect event handler
Sub OnSelect(JustSelectedEntities As ObjectsEnumerator, SelectionDevice As SelectionDeviceEnum, _
ModelPosition As Inventor.Point, ViewPosition As Point2d, View As Inventor.View)
Dim count As Integer = oSelectEvents.SelectedEntities.Count
' Update label with selected bodies count
Dim oLabel As MiniToolbarControl = oMiniToolbar.Controls("InfoLabel")
oLabel.DisplayName = "Bodies selected: " & count
' Enable/disable buttons
oMiniToolbar.EnableOK = (count > 0)
oMiniToolbar.EnableApply = (count > 0)
WriteLog("After selection: Bodies = " & count & ", EnableOK = " & oMiniToolbar.EnableOK & ", EnableApply = " & oMiniToolbar.EnableApply)
oApp.ActiveView.Update()
End Sub
' OnUnSelect event handler
Sub OnUnSelect(UnselectedEntities As ObjectsEnumerator, SelectionDevice As SelectionDeviceEnum, _
ModelPosition As Inventor.Point, ViewPosition As Point2d, View As Inventor.View)
Dim count As Integer = oSelectEvents.SelectedEntities.Count
' Update label with selected bodies count
Dim oLabel As MiniToolbarControl = oMiniToolbar.Controls("InfoLabel")
oLabel.DisplayName = "Bodies selected: " & count
' Enable/disable buttons
oMiniToolbar.EnableOK = (count > 0)
oMiniToolbar.EnableApply = (count > 0)
WriteLog("After unselection: Bodies = " & count & ", EnableOK = " & oMiniToolbar.EnableOK & ", EnableApply = " & oMiniToolbar.EnableApply)
oApp.ActiveView.Update()
End Sub
' OK button handler
Sub OnOK()
WriteLog("OK button clicked: Bodies = " & oSelectEvents.SelectedEntities.Count)
isRunning = False
End Sub
' Apply button handler
Sub OnApply()
WriteLog("Apply button clicked: Bodies = " & oSelectEvents.SelectedEntities.Count & ", EnableApply before = " & oMiniToolbar.EnableApply)
' Process selected bodies (just show a message in this test)
MessageBox.Show("Processed bodies: " & oSelectEvents.SelectedEntities.Count)
' Reset selection
oSelectEvents.ResetSelections()
' Force disable buttons and check their state
oMiniToolbar.EnableOK = False
oMiniToolbar.EnableApply = False
WriteLog("After Apply and reset: EnableOK = " & oMiniToolbar.EnableOK & ", EnableApply = " & oMiniToolbar.EnableApply)
' Update label
Dim oLabel As MiniToolbarControl = oMiniToolbar.Controls("InfoLabel")
oLabel.DisplayName = "Bodies selected: 0"
oApp.ActiveView.Update()
' Check button state after update
WriteLog("After view update: EnableOK = " & oMiniToolbar.EnableOK & ", EnableApply = " & oMiniToolbar.EnableApply)
End Sub
' Cancel button handler
Sub OnCancel()
WriteLog("Cancel button clicked")
isRunning = False
End Sub
' Resource cleanup
Sub Cleanup()
If oSelectEvents IsNot Nothing Then
RemoveHandler oSelectEvents.OnSelect, AddressOf OnSelect
RemoveHandler oSelectEvents.OnUnSelect, AddressOf OnUnSelect
oSelectEvents.Enabled = False
oSelectEvents.ResetSelections()
End If
If oMiniToolbar IsNot Nothing Then
RemoveHandler oMiniToolbar.OnOK, AddressOf OnOK
RemoveHandler oMiniToolbar.OnApply, AddressOf OnApply
RemoveHandler oMiniToolbar.OnCancel, AddressOf OnCancel
oMiniToolbar.Visible = False
End If
If oInteractionEvents IsNot Nothing Then
oInteractionEvents.Stop()
End If
End Sub
INV 2025.3