Check if excel parameter exists in Assembly

Check if excel parameter exists in Assembly

tylwea
Explorer Explorer
191 Views
1 Reply
Message 1 of 2

Check if excel parameter exists in Assembly

tylwea
Explorer
Explorer

I feel I've done this a dozen times before, but it's been about 5 years since I've gotten into the weeds with this, perhaps someone can assist?

 

I have an assembly file that will have a linked excel file and subsequent excel parameters.

The excel parameters have a prefix to identify a specific component for a given configuration of the assembly (i.e., Door1_length, Door2_length, Door3_length, Door4_length, Door5_length, etc.).  However, depending on the configuration of the assembly, there may only be 2x that represent the specific components we're identifying (i.e., Door1_length & Door2_length), or as many as 10x (i.e., Door1_length thru Door10_length). 

 

What I would like to do is check the Excel Parameters if Door1_length exists...

If it doesn't exist, then do nothing, but IF it does exist, then Run Rule "Door1_ABC". 

 

Then check if Door2_length exists...

If it doesn't exist, then do nothing, but IF it does exist, then Run Rule "Door2_ABC". 

 

Then check if Door3_length exists...

If it doesn't exist, then do nothing, but IF it does exist, then Run Rule "Door3_ABC". 

 

and so on..

 

 

Worth noting that we are using Inventor 2019.

 

Many thanks in advance!

-TMW

0 Likes
192 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @tylwea.  Sounds like maybe something like the following should work for a situation like that.  It lets you define pairs of parameter names with rule names, in a Dictionary.  Then it looks for all parameters that are 'Linked' to that document via Excel, and iterates through them, getting their names to a single List.  Then later, as it iterates through your Dictionary entries, it check is that List 'Contains' that entry's parameter name, and if so, runs the rule specified for that entry.

You may have to change 'RunExternalRule' to something like 'RunRule' if those other rules are internal ones, though.

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDoc As Inventor.Document = ThisDoc.FactoryDocument
	If oDoc Is Nothing Then Return 'will be Nothing if a DrawingDocument
	Dim oParams As Inventor.Parameters = oDoc.ComponentDefinition.Parameters
	
	'define pairs of param names and rules to run for them
	Dim oDict As New Dictionary(Of String, String)
	oDict.Add("Door1_length", "Door1_ABC")
	oDict.Add("Door2_length", "Door2_ABC")
	oDict.Add("Door3_length", "Door3_ABC")

	Dim oPTables As Inventor.ParameterTables = oParams.ParameterTables
	If oPTables Is Nothing OrElse oPTables.Count = 0 Then Return
	Dim oPNames As New List(Of String)
	For Each oPTable As Inventor.ParameterTable In oPTables
		If Not oPTable.Linked Then Continue For
		For Each oPTParam As Inventor.TableParameter In oPTable.TableParameters
			oPNames.Add(oPTParam.Name)
		Next
	Next
	If oPNames.Count = 0 Then Return
	For Each oEntry As KeyValuePair(Of String, String) In oDict
		If oPNames.Contains(oEntry.Key) Then 'Key is the parameter name
			iLogicVb.RunExternalRule(oEntry.Value) 'Value is the name of the rule to run
		End If
	Next
	oDoc.Rebuild2(True)
End Sub

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)

0 Likes