- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
At my company we use Frame Generator a lot. In order to make everything work with our vault and resource planning it is crucial that this ckeckbox is unchecked when a frame member is placed (picture below)
I wrote this code to handle the problem in inventor 2018:
Public Class FGBox Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA"(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA"(ByVal hWndParent As Integer, ByVal hWndChildAfter As Integer, ByVal lpszClass As String, ByVal lpszWindow As String) As Integer Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Const BM_CLICK As Integer = &HF5& Private Const BM_SETCHECK As Integer = &HF1& Sub Main If ThisDoc.Document Is ThisApplication.ActiveDocument Then Dim oCommandMgr As CommandManager oCommandMgr = ThisApplication.CommandManager Dim oControlDef As ControlDefinition oControlDef = oCommandMgr.ControlDefinitions.Item("AFG_CMD_InsertProfile") If oControlDef.Enabled = False Then oControlDef.Enabled = True End If Call oControlDef.Execute Dim h1 = FindWindow(Nothing, "Insert") Dim h2 = FindWindowEx(h1, 0, Nothing, Nothing) Dim count As Integer = 0 Do While h2 <> 0 h2 = FindWindowEx(h1, h2, Nothing, Nothing) count += 1 If count = 33 Then SendMessage(h2, BM_SETCHECK, False, 0) h2 = FindWindowEx(h1, h2, Nothing, "Cancel") SendMessage(h2, BM_CLICK, 0, 0) Exit Do End If Loop End If End Sub End Class
And had it triggered on new document and document open. The code basically opens the dialogue, finds the checkbox and unchecks it. Then closes the dialouge. Even though it's an ugly way of doing it it worked just fine.
In Inventor 2020 however, you have to have the assembly saved before the dialouge can be opened, so the code cant do anything on a new document...
Therefore i thought i should write an addin that simply ckecks for the "Insert Frame" command to execute, and when it does, uncheck the box.
My problem now is that i cant find the appropriate event.
Doing it this way tries to uncheck the box before the dialogue is shown:
Public Sub FGopen(CommandName As String, Context As NameValueMap) Handles m_UserInputEvents.OnActivateCommand If CommandName = "AFG_CMD_InsertProfile" Then Dim h1 = FindWindow(Nothing, "Insert") Dim h2 = FindWindowEx(h1, 0, Nothing, Nothing) Dim count As Integer = 0 Do While h2 <> 0 h2 = FindWindowEx(h1, h2, Nothing, Nothing) count += 1 If count = 33 Then SendMessage(h2, BM_SETCHECK, False, 0) Exit Do End If Loop End If End Sub
I also tried looping until h1 <> 0 but then the dialogue never opened and i ended up with an infinity loop.
This way ran the code first when the dialogue was closed:
Public Sub FGopen(CommandName As String, Context As NameValueMap) Handles m_UserInputEvents.OnTerminateCommand If CommandName = "AFG_CMD_InsertProfile" Then Dim h1 = FindWindow(Nothing, "Insert") Dim h2 = FindWindowEx(h1, 0, Nothing, Nothing) Dim count As Integer = 0 Do While h2 <> 0 h2 = FindWindowEx(h1, h2, Nothing, Nothing) count += 1 If count = 33 Then SendMessage(h2, BM_SETCHECK, False, 0) Exit Do End If Loop End If End Sub
So my question is:
Is there a way to see if the dialogue is shown before running the code, or does anybody have a better approach to the entire situation? 🙂
Any help would be much appreciated.
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Solved! Go to Solution.