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: 

How to pin open form window to the interface.

13 REPLIES 13
Reply
Message 1 of 14
jedrzej_fiszerMMJKW
495 Views, 13 Replies

How to pin open form window to the interface.

Hi,

I have a question about the forms interface. Is there any way to attach an open form to the Inventor window whenever I start a new document?

 

I created a small rule (screen 1) to save new files with automatic file names and tags. I am trying to pin this open form window somewhere in the ribbon or anywhere in the interface.

 

Is there a command that makes this possible?

 

Best regards.

 

image.png

13 REPLIES 13
Message 2 of 14

Unfortunately, iLogic forms windows are not dockable windows so you cannot "pin" them to the interface at all. This might be a good Idea Station request though if there is not one already. 

Message 3 of 14

Hi @jedrzej_fiszerMMJKW.  There is one possible way that would not be too difficult to achieve, but it would certainly not be ideal.  If you have the iLogic DockableWindow showing (View tab > User Interface > iLogic), then every document will have a sub tab within that window just for 'local' forms (iLogic forms that are saved within that document only).  That tab is labeled Forms (not Global Forms).  That whole Forms tab can be used just like a regular iLogic Form.  It is normally empty, if there are no forms in that document, but you can populate it with either buttons that will launch a form, or a form itself, or a combination of the two.  To look into this, first left click on the Forms tab, to make it the active one you are viewing, then just right mouse button click anywhere within the empty area below that.  To add a button that will launch a form, you would choose 'Add Form', but to make this area actually show a form itself, you can choose 'Edit' option instead.  It will show the same dialog either way, but when you chose the Edit option, you are editing what you will see in that whole area, including buttons for other local forms and buttons to run rules.

 

Edit:  What I said above is not entirely true.  This will not allow all the same functionality as a regular Form, because it will not allow you to drag & drop properties or parameters into the window, like you can when editing a regular Form.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 14
tfrohe_LSI
in reply to: WCrihfield

Doesn't that only allow you to add buttons for existing rules? I see that you can add interface elements, like groups, tabs, splitters, etc. but I can't see how to place parameters or iProperties in that panel directly. The buttons then open the rule in an undockable window. I am using Inventor 2021 though, so this may have changed in future versions am I am unaware of it. 

Message 5 of 14

I need something like this. It always opens from a window when the part file is opened.

 

jedrzej_fiszerMMJKW_0-1695391029824.png

 

 

Message 6 of 14
WCrihfield
in reply to: tfrohe_LSI

Hi @tfrohe_LSI.  You are correct.  I posted before checking out some of my older documents that I had done some stuff similar to this within.  I was not directly entering or changing any parameter or iProperty values.  I just had a lot of stuff going on in that Forms area, and had it all laid out in an unusual way, with tabs, groups, rows, and splitters.  I was remembering wrong.

One other thing also comes to mind though.  We can actually create new DockableWindows within Inventor.  And we can add a Child to the new DockableWindow.  However, I believe this ability is mostly utilized by Inventor add-ins (ApplicationAddIns), rather than by iLogic resources.  You can either assign it a 'dialog' or an ActiveX control.  I am not familiar with creating or using ActiveX controls, and do not currently have the needed permissions to create my own add-ins at work, so I have not really delved into them that much before, other than exploring the ones we do have access to.  That being said, I rather doubt that we can simply add an iLogic 'global' form to a new DockableWindow as its child.  I believe it would need to be a regular externally sourced .Net Windows Form, or something like that for the 'dialog' option. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 14

I think I figured it out using the DockableWindow route and a global iLogic form.  I was able to use an iLogic rule to create a new DockableWindow, then launch a global iLogic Form set to 'Non-Modal' (important), then retrieve the HWND of that iLogic Form dialog while it is open, then use that HWND as the input for the DockableWindow.AddChild method.  That created a DockableWindow on my screen, with the global iLogic Form inside of it.  Then I was able to resize, move, and dock that DockableWindow as I wanted.  You will want to change the names I am using in this example, because this was just a fast and loose test of ability.  And by the way, even after you close this DockableWindow, it will still exist, so if you try to create another using the same name, it will throw an error.  That is why I am trying to find the existing window, before trying to create it again in this example.  And I am just using the ClassId String for the iLogic add-in here, because that is what's being used for the other two built-in DockableWindows.  I doubt this will persist after you restart Inventor though.  That will have to be tested, but other user interface customizations that are done by iLogic rule will also disappear after restarting Inventor.  That why you need an add-in for user interface customizations.

Here is the example iLogic rule:

Imports System.Windows.Forms
Sub Main
	Dim oDWs As Inventor.DockableWindows = ThisApplication.UserInterfaceManager.DockableWindows
	Dim iLogicClassIDString As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
	Dim oDW As Inventor.DockableWindow = Nothing
	Try
		oDW = oDWs.Item("My Window")
	Catch
		oDW = oDWs.Add(iLogicClassIDString, "My Window", "My Window")
	End Try
	Dim oFRV As FormReturnValue = iLogicForm.ShowGlobal("CHANGE CUT LENGTH", FormMode.NonModal)
	Dim oHandle As Long = FindWindow(vbNullString, "CHANGE CUT LENGTH")
	oDW.AddChild(oHandle)
	oDW.DisableCloseButton = False
	oDW.ShowVisibilityCheckBox = True
	oDW.Visible = True
End Sub

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 14
WCrihfield
in reply to: WCrihfield

The good news is that we can also show internal iLogic Forms in a DockableWindow like that, not just 'global' ones.  The bad news, as I suspected, is that the DockableWindows we create that way (with an iLogic rule) will not survive restarting Inventor.  So, you would just have to create them again after restarting Inventor.

 

Also, keep in mind that when you launch a global iLogic form, it will be focused on whichever document was 'active' at that moment, and it will not change its focus to another document, just because you switched to viewing another document.  In order to get the global iLogic form to focus on another document, you must first close that form, then open it again while the other document is active (viewing it on your screen).

 

So, you may want to setup something like this to use the Event Triggers, if trying to keep it simple, and not use an add-in.  When a document opens, if it is the 'active' document, use a rule to ensure that the window exists, then either launch and add the form to the window, or refresh the form within the window by Clearing the window, then adding the form back to the window again.  When a document closes, if it is the 'active' document, use a rule to Clear the window.  If you clear the window when closing the document, then you should not need to clear it when opening another document.

 

This may be complicated to do using the regular Event Triggers dialog though, because documents can open and close invisibly in the background, by simply opening assemblies or drawings that reference them, or opening and closing them invisibly by code, and that will trigger those events.  You would only want these window and form changes to happen for the document that you are actively viewing, not for invisible background documents.  That is why you will most likely want to use 'ThisDoc.Document' to identify the document that triggered the rule to run, but then you will likely want to check it against 'ThisApplication.ActiveDocument' to see if they are the same.  And if they are, then move forward with the rest of the rule, otherwise exit the rule, without doing anything else.

 I attached a few text files for similar external iLogic rules.  But these are just the basics of what would be needed to set up a full automation project that will maintain, and update a form like this across all documents that might open and close while Inventor is open, using just iLogic rules and the Event Triggers dialog.  This type of setup is best handled by an add-in.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 14

It works! Almost. 

 

I have errors like that.

(Exception from HRESULT: 0x80004005 (E_FAIL))

(Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

All my rules.

 

1. Save As Form.

 

Sub Main()
	iLogicForm.Show("SaveForm")
End Sub

 2. Merge the name file from the parameters of the rule 3.

 

Sub Main()
	
    Dim project As String = Parameter("PROJECT")
    Dim area As String = Parameter("AREA")
    Dim partName As String = Parameter("PART_NAME")
    Dim revision As String = Parameter("REVISION")
    Dim number As String = Parameter("OWN_NUMBER")
	
    Dim saveFileDialog As New System.Windows.Forms.SaveFileDialog()
    saveFileDialog.Title = "Save"
    
    saveFileDialog.FileName = project + "_" + area  + "_" + revision + "_" + partName + "_" + number
    saveFileDialog.Filter = "Pliki IPT (*.ipt)|*.ipt"
	
    If saveFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        Dim sciezkaPliku As String = saveFileDialog.FileName
      
        	ThisApplication.ActiveDocument.SaveAs(sciezkaPliku, False)
    End If
End Sub

 

3. Generate parameters to file.

 

Sub Main()
	Dim MyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
	
	FirstParameter = MyParameter.AddByValue("PROJECT", "", UnitsTypeEnum.kTextUnits)
	SecondParameter = MyParameter.AddByValue("AREA", "", UnitsTypeEnum.kTextUnits)
	ThirdParameter = MyParameter.AddByValue("PART_NAME", "", UnitsTypeEnum.kTextUnits)
	FourthParameter = MyParameter.AddByValue("REVISION", "", UnitsTypeEnum.kTextUnits)
	FifthParameter = MyParameter.AddByValue("OWN_NUMBER", "", UnitsTypeEnum.kTextUnits)
	
End Sub

4. Your rule with DockedWindow.

5. Run rule 4.  I put this rule in the event triggers, which opens this rule every time I create a new part.

Message 10 of 14

Hi @jedrzej_fiszerMMJKW.  Those two short error lines do not give me enough information to diagnose specifically what caused them, or where within all of your codes the problem occurred.  One thing that comes to mind is that a truly 'New' part, may not already have those 5 named user parameters within them.  And if that were the case, it would throw an error in the second rule, where it is trying to access those parameters, and they can not be found.  But if the new part was generated from a template which already had those user parameters present, then that would not be a problem.  Which tab within the Event Triggers dialog did you place the rule under the New Document event?  Was it on the 'This Document' tab, or one of the other tabs?  If it was on one of the other tabs, and if these rules are external rules, I could see that potentially causing some problems.  Because if that were the case, it might be possible for some other document to be the 'active' document when those rules got triggered to run, which might cause them to target the wrong document.  Just some thoughts.  It is almost always best to see the contents of the More Info tab of the error dialog when it pops up, because that tab will usually contain more and better information about the error, which could help us narrow down where the error is happening.  No guarantees though.  Sometimes they are not that much help either.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 14

Ok, thanks for the answer. There is an error in the new part. I have a custom template where these parameters are already created. Each rule is on this tab and in this document. I did not use global rules. There are some screens.

 

jedrzej_fiszerMMJKW_0-1695647542500.pngjedrzej_fiszerMMJKW_1-1695647577872.png

Rule 4 is dockablewindow.

 

Imports System.Windows.Forms
Sub Main
	Dim oDWs As Inventor.DockableWindows = ThisApplication.UserInterfaceManager.DockableWindows
	Dim iLogicClassIDString As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
	Dim oDW As Inventor.DockableWindow = Nothing
	Try
		oDW = oDWs.Item("My Window")
	Catch
		oDW = oDWs.Add(iLogicClassIDString, "My Window", "My Window")
	End Try
	Dim oFRV As FormReturnValue = iLogicForm.Show("SaveForm", FormMode.NonModal)
	Dim oHandle As Long = FindWindow(vbNullString, "SaveForm")
	oDW.AddChild(oHandle)
	oDW.DisableCloseButton = False
	oDW.ShowVisibilityCheckBox = True
	oDW.Visible = True
End Sub

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Message 12 of 14

OK.  I see the problem now.  The error message says that the error is happening when it tries to add a child to a DockableWindow.  And I see that you are not using the latest version of my code.  Did you download and look at the text file attached to 'Message 8' named "Create or Refresh DockableWindow With iLogic Form.txt"?  Within that code, I have expanded the code within the Catch side of the Try...Catch block, so that if it does not find the existing DockableWindow and creates a new one, it will set those properties of it.  If the existing one is found, it will not need to set those properties.  Then, after that point, you can see that I am attempting to 'close' the form that was associated with that window.  I think the ability to close an open iLogic form was just added in the latest version of Inventor, so you may not be able to use that step.  Then a couple lines down from there you will notice that I am using oDW.Clear method to clear the form from the window, just before trying to add the form to the window.  This is because you can only add a single child to a DockableWindow.  If the window already has one, you must remove it first, before you can add a different child.  If you try to add a child to a window that already has a child, it will throw an error like that.  I'm sure this code routine could be improved upon even further, with enough time and effort invested into it.  This is just a quick example that was thrown together as a response to your forum post.  I was also a bit curious about it myself, but simply had not taken the time to investigate into it further yet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 13 of 14

Okey thanks. Last try, i have problem with iLogicForm.CloseForm in your code.

 

Error on Line 18 : Element "CloseForm" is not a member of the element "Autodesk.iLogic.Interfaces.IiLogicForm".

I dont have code lines like that in my snippets.

 

jedrzej_fiszerMMJKW_0-1695650369566.png

 

Message 14 of 14

As I mentioned, I believe that ability was added in the latest version of Inventor (2024 version).  Here are a couple links to the online help pages for those code snippets within the 2024 version help.

IiLogicForm.Close Method 

IiLogicForm.CloseGlobal Method 

IiLogicForm.CloseAllForms Method 

iLogic Enhancements (What's New in 2024) 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report