External rule to run first local form of a part / assembly / drawing

External rule to run first local form of a part / assembly / drawing

Kay_Rethmeier
Advocate Advocate
226 Views
5 Replies
Message 1 of 6

External rule to run first local form of a part / assembly / drawing

Kay_Rethmeier
Advocate
Advocate

Hi,

 

I would love to have an external rule, which would start the first local form of an opened document independent of it's naming. If there is no form nothing should happen or maybe a hint, that the current document does not provide a local form. 

 

So far I created this external rule with a list of possible names, which is not that clever. It should be more general by detecting local forms.

Dim PossibleFormNames As New ArrayList				' list with all possible names
PossibleFormNames.Add("GO")
PossibleFormNames.Add("Values")
PossibleFormNames.Add("WebInput")					' Customer 1
PossibleFormNames.Add("Formular 1")					' Customer 2
PossibleFormNames.Add("FactoryDesignProperties")	' Factory 
PossibleFormNames.Add("DrawingControl")
PossibleFormNames.Add("nn")

Check = 0														' for debugging

For Each FormName In PossibleFormNames							' running through list
	Try
		If Check > 0 Then MsgBox("Try show form " & FormName)	' debugging
		iLogicForm.Show(FormName)								' try opening the form
		Exit Sub 												' if successful, leaving this rule
	Catch : End Try
Next

' feedback, in case of no form
MessageBox.Show("Document doesn't provide a local form.", "No Form available")

 

P.S.: I'm not a  computer programmer/developer, I'm a technical designer/engineer!

Cheers
Kay (Principal CAD-Consultant)
0 Likes
Accepted solutions (2)
227 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Kay_Rethmeier.  Maybe this will do what you want.  It gets the names of all 'local / internal' iLogic Forms in the 'current' Document, checks to make sure there are some, then tries to show the first one.

Dim oLocalFormNames As IEnumerable(Of String) = iLogicForm.FormNames
If oLocalFormNames IsNot Nothing AndAlso oLocalFormNames.Any() Then
	iLogicForm.Show(oLocalFormNames.First())
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

ryan.rittenhouse
Advocate
Advocate
Accepted solution

This will launch the first form in the list when run:

If iLogicForm.FormNames.Count() > 0 Then iLogicForm.Show(iLogicForm.FormNames(0))

 

If you want to iterate through all of them, you can use FormNames to see them all:

For Each name As String In iLogicForm.FormNames
	Logger.Info("Found rule: " & name)
Next name
If this solved your problem, or answered your question, please click Accept Solution.
Message 4 of 6

Kay_Rethmeier
Advocate
Advocate

Wonderfull, thank you both! So I mixed it a bit and created myself following rule:

Dim oLocalFormNames As IEnumerable(Of String) = iLogicForm.FormNames
If oLocalFormNames.Count = 0 Then MessageBox.Show("Document doesn't provide a local form.", "No form available")
If oLocalFormNames.Count = 1 Then iLogicForm.Show(oLocalFormNames.First())
If oLocalFormNames.Count > 1 Then
	Dim oAllFormNames As New ArrayList
	For Each Name In iLogicForm.FormNames
		oAllFormNames.Add(Name)
	Next
	sSel = InputListBox("if nothing is selected the first form will be selected", oAllFormNames, (1), "Choose Form", "Available Forms")
	If sSel = "" Then
		iLogicForm.Show(oLocalFormNames.First())
	Else
		iLogicForm.Show(sSel)
	End If
End If

 Best regards!

Cheers
Kay (Principal CAD-Consultant)
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

No need to create a new list of the form names just for use within the 'InputListBox', because you already have an 'IEnumerable' containing them, and that 'InputListBox' method is actually looking for that type of collection already.  See Link below:

RunDialogs.InputListBox Method (String, IEnumerable, Object, String, String, Int32, Int32) 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

Kay_Rethmeier
Advocate
Advocate

Thank you Wesley, 

 

because of your tip I was able to shrink the code a lot.

Dim oLocalFormNames As IEnumerable(Of String) = iLogicForm.FormNames
Dim oDoc As Document = ThisApplication.ActiveDocument
If oLocalFormNames.Count = 0 Then MessageBox.Show("'" & oDoc.DisplayName & "' doesn't provide a local form.", "No form available")
If oLocalFormNames.Count = 1 Then iLogicForm.Show(oLocalFormNames.First())
If oLocalFormNames.Count > 1 Then
	sSel = InputListBox("if nothing is selected the first form will be selected", iLogicForm.FormNames, iLogicForm.FormNames.First, "Choose Form", "Available Forms")
	iLogicForm.Show(sSel)
End If

 Bye!

Cheers
Kay (Principal CAD-Consultant)
0 Likes