Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Launching Global Form from specified document

dustinbagley
Advocate

Launching Global Form from specified document

dustinbagley
Advocate
Advocate

I would like create a Global Form with a bespoke set of parameters whose values can be captured for use in creation of new drawing files. 

I attempted to do this by firing a rule from the form that creates a new part document; populates it with the appropriate parameters; and then relaunches the form after activating the new part document. 

dustinbagley_0-1689617477016.png

 

'[Creates a temporary document for parameters used in the "Fabrication
'Drawing Creation Tool" form.
'Dim oDoc As Document = ThisDoc.Document
Dim oTempDoc As PartDocument
oTempDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
oUserParameters = oTempDoc.ComponentDefinition.Parameters.UserParameters
oTempDoc.Activate
SharedVariable("oTempDoc") = oTempDoc
']

'[Add drawing templates to an array list
Dim Templates As New ArrayList
Dim FileLocation As System.IO.DirectoryInfo = _
New System.IO.DirectoryInfo("C:\Vault\CAD Support\Inventor\Templates\")
Dim FileInfo As System.IO.FileInfo() = FileLocation.GetFiles("*" & ".idw")
For Each oFile As System.IO.FileInfo In FileInfo
	Templates.Add(oFile.Name)
Next
']

'[Creates and sets parameters that are used for the "Fabrication Drawing
'Creation Tool" form.
oUserParameters.AddByValue("Template", "", UnitsTypeEnum.kTextUnits)
'MultiValue.List("Template") = Templates
'Parameter("Template") = "Standard.idw"
oUserParameters.AddByValue("CreateBaseView", True, UnitsTypeEnum.kBooleanUnits)
oUserParameters.AddByValue("CreateBaseViewProjs", True, UnitsTypeEnum.kBooleanUnits)
oUserParameters.AddByValue("CreatePcDetails", True, UnitsTypeEnum.kBooleanUnits)
oUserParameters.AddByValue("JobNo", "", UnitsTypeEnum.kTextUnits)
oUserParameters.AddByValue("Detailer", "", UnitsTypeEnum.kTextUnits)
oUserParameters.AddByValue("Checker", "", UnitsTypeEnum.kTextUnits)
oUserParameters.AddByValue("Approver", "", UnitsTypeEnum.kTextUnits)
oUserParameters.AddByValue("Date", "", UnitsTypeEnum.kTextUnits)
']

iLogicForm.CloseGlobal("Fabrication Drawing Creation Tool")
oTempDoc.Activate
iLogicForm.ShowGlobal("Fabrication Drawing Creation Tool", FormMode.Modal)

Because--as seem to be the case, 'iLogicForm.ShowGlobal' does not care which document is active, only which one it was run from-- I cannot get the form to see the parameters that are available after running 'Activate Value Input', I was wondering if there was a way to call the form specifically from the oTempDoc that the rule has created.

0 Likes
Reply
Accepted solutions (1)
385 Views
4 Replies
Replies (4)

WCrihfield
Mentor
Mentor

Hi @dustinbagley.  If the parameters/properties are created in the temporary part, even if the form could recognize and work with them, any values you enter or change, would be set to that temporary part, instead of to the drawing.  You can actually just create the needed user parameters and/or iProperties right within the drawing itself, then launch the global form while the drawing is the active document, and it should not only source them from the drawing, but write the changes to the drawing.  If all that needed data was in a temporary part, then you would need another rule to read the needed data from that temp part, and write it to the drawing (or use it for drawing purposes) while the drawing is active.

To get around the need for creating user parameters, you would likely have to create a custom VBA UserForm within the VBA Editor, or maybe a custom Windows Form within your rule, then launch that.  It is fairly complicated to design a Windows Form from scratch by code alone, without something like Visual Studio, but it's not impossible, because I've done it before a few times.  With either of those two routes, your list sources can just be within the code itself, instead of from multi-value user parameters.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

dustinbagley
Advocate
Advocate

@WCrihfield Thank you for responding. You are correct that I don't yet have any mechanism to get the parameters from the temp file to a new drawing document which will be their ultimate location. However, because in Inventor you can only run rules or launch forms with some document open and because the drawing doesn't exist at the time I run the rule, I believe I will have to same results by adding the parameters to the new drawing file instead of the temporary file. Please correct me if I am wrong. In both of these instances, I can manually close and reopen the form with all of the inputs available. (but I don't want to have to do something like that because my ultimate goal with this form is to reduce clicks and dialog boxes)  I am assuming this is because "iLogicForm.ShowGlobal" is using the active document at the beginning of the rule instead of whatever it has been switched to through the course of the rule; whereas a new click of the form from the global form browser will look at the currently active document, making the parameters available.

 

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Yes.  When a global iLogic form is launched, it simply focusses on whatever document is actively showing on your screen at the time.  And if the form is shown modal, all iLogic code will be paused while it is showing.  And switching to another document while the form is still showing, generally does not cause that form to change its focus to that other document.  However, if you close the form, then switch to the other document, then launch the form again, it should again focus on whatever document was active when it was launched that second time.  But if the parameters only exist in the temporary part, and you open the form while the drawing is active, those parameters will likely be greyed out, because they are not present in the drawing.  Have you thought about including those parameters in the template file that you use to start a new drawing from?  If you use the 'New' command to create a new drawing from a template, that new drawing should still retain all of its user parameters and custom iProperties that were present in the template.  Otherwise I suppose it might be possible for that form to include a button (or multiple buttons) that run an iLogic rule.  And the rule it runs could attempt to find an already open drawing document, then attempt to copy some parameters and such from the active document to that drawing.  But remember that when using a global form, the changes must be 'applied' before they will effect the document, unlike when using a local form.  And if the iLogic rule that the button runs is also an external iLogic rule, you will not have the drop-down list of options available to help control the behavior of the rule button.  I believe that only when the rule is an internal rule (saved within a document), then when you create a rule button, you will have those additional properties for how the button will react.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

dustinbagley
Advocate
Advocate

@WCrihfield Thank you for confirm what I was suspecting. I like like the idea of trying using a template file instead for creating a new one. I will try that to see if I can get the results I'm shooting for. Thanks,

Dustin

0 Likes