Export all multi-value parameters to spreadsheet

Export all multi-value parameters to spreadsheet

ahmed.hagi
Enthusiast Enthusiast
3,620 Views
45 Replies
Message 1 of 46

Export all multi-value parameters to spreadsheet

ahmed.hagi
Enthusiast
Enthusiast

Hello,

 

I am trying to compare values which I import from a spreadsheet to the values in my user parameters, i need to compare all the possible values as opposed to the ones which are currently set, for example: If one parameter has imported from the spreadsheet as "Blue" (for a multi value parameter called colour), I want to check that blue is a value in the list for colour. 

Is there a way to do this?

0 Likes
Accepted solutions (2)
3,621 Views
45 Replies
Replies (45)
Message 2 of 46

WCrihfield
Mentor
Mentor

So...you have an Inventor model file that already has some parameters in it, and you have a separate, external Excel spreadsheet file that contains data/specifications for a set of parameters, right?

We would need to know exactly how the Excel spreadsheet is set-up/laid-out.  Specifically where to find each bit of data we are looking for.

If you could create a simplified example model file and Excel file (with no personal/proprietary data in them) for us to test with, it might make the process of one of us developing a solution for you a bit faster.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 46

ahmed.hagi
Enthusiast
Enthusiast

Hello,

 

Sorry for the late reply. Apparently I didn't recieve any emails telling me there was a response.

Actually what I am after isn't related to a spreadsheet. I want to put all the values in a set of multi-value parameters into a single ArrayList, but I cant seem to do that.

I cant create a loop because of the speechmark requirement

For example:

If I have multi value parameters, A, B, C, and D. Each parameter containing a few options.

How do I put all the options represented in side these paramaters into a single array?

 

I can't seem to create a loop. 

There's this snippet:

 

p = MultiValue.List("A")
 

But it won't work for my application because I want to loop through a list of multi-value parameters and place the set of values contained in each of them into one Array.

0 Likes
Message 4 of 46

j.haggenjos
Advocate
Advocate

Hello,

 

Using the iLogic shortcut, I'm not sure there is a way to loop through all parameters. You have to access them by name.

 

If you want to loop through all parameters, you need to use the API to access the UserParameters and loop through those. Then you check if the parameter is a multivalue and at that point, you can get the parameter list:

 

 

For Each oParameter As UserParameter In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	If oParameter.ExpressionList.Count <> 0 Then
		Dim ParameterList() As String = oParameter.ExpressionList.GetExpressionList()
        'Do something with ParameterList
	End If
Next

 

 

This should get you closer to what you need.

0 Likes
Message 5 of 46

ahmed.hagi
Enthusiast
Enthusiast

Thanks for this, I want to compare the values in ParameterList() with another arraylist further down the rule, but it throws up ParameterList not defined error

0 Likes
Message 6 of 46

j.haggenjos
Advocate
Advocate

It's my mistake. If you define ParameterList inside the loop it will only exist in the loop.

 

Dim ParameterList() As String
For Each oParameter As UserParameter In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	If oParameter.ExpressionList.Count <> 0 Then
		ParameterList = oParameter.ExpressionList.GetExpressionList()
        'Do something with ParameterList
	End If
Next

 

After the loop is finished, you only have the parameter list from the last parameter. If you want all of them you need to modify the code a bit. But the easier would be to handle each list inside the loop.

0 Likes
Message 7 of 46

ahmed.hagi
Enthusiast
Enthusiast

I Tried that previously and got an Object reference not set to an instance of an object error

 

Dim ParameterList() As String
For Each oParameter As UserParameter In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	If oParameter.ExpressionList.Count <> 0 Then
		ParameterList = oParameter.ExpressionList.GetExpressionList()
        'Do something with ParameterList
	End If
Next

For Each Value In ParameterList
	MsgBox(Value)
	Next
0 Likes
Message 8 of 46

j.haggenjos
Advocate
Advocate

This code you posted works for me if I copy paste it in a rule.

I think something else is preventing your second loop to access the ParameterList. Is it in a separate loop or If condition?

 

Move the ParameterList variable definition to the top of your rule to prevent issue. At least make sure it is not "hidden" inside a loop or If condition.

Dim ParameterList() As String

 

0 Likes
Message 9 of 46

ahmed.hagi
Enthusiast
Enthusiast

I'm just trying it in a Dummy rule, there is nothing else in the rule, and it is formatted as shown above

0 Likes
Message 10 of 46

j.haggenjos
Advocate
Advocate

Is there a MultieValue parameter in the document from this rule?

0 Likes
Message 11 of 46

ahmed.hagi
Enthusiast
Enthusiast

yes, there are many of them, it is an assembly file

0 Likes
Message 12 of 46

j.haggenjos
Advocate
Advocate

Does this list their name in message boxes?

 

 

Dim ParameterList() As String
For Each oParameter As UserParameter In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	If oParameter.ExpressionList.Count <> 0 Then
		MsgBox(oParameter.Name)
		ParameterList = oParameter.ExpressionList.GetExpressionList()
        'Do something with ParameterList
	End If
Next

 

 

 

0 Likes
Message 13 of 46

ahmed.hagi
Enthusiast
Enthusiast

It does, but then it throws up this error:

 

Object reference not set to an instance of an object.

 

 
0 Likes
Message 14 of 46

j.haggenjos
Advocate
Advocate

Try running the test rule in the attached ipt

0 Likes
Message 15 of 46

ahmed.hagi
Enthusiast
Enthusiast

strange, that one runs with no errors. Is it a parameter that is messing it up?

0 Likes
Message 16 of 46

WCrihfield
Mentor
Mentor

Try it this way.  I'm showing multiple different options within this rule.  I usually prefer to work with a List over an Array, because they are usually much easier to deal with.  And you can easily convert between both types.

You can have a List that contains other Lists, and you can also have multi-dimensional arrays (like an array of arrays), so if you wanted to keep each list seperate, yet all stored in one variable, either of those would be an option.  However, if you really just want them all in one long list, that is easily done with a simple 3-line loop.

Here's the code:

Dim oDocType As DocumentTypeEnum = ThisApplication.ActiveDocumentType
Dim oParams As Parameters
If oDocType = DocumentTypeEnum.kPartDocumentObject Or _
	oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
	oParams = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
ElseIf oDocType = DocumentTypeEnum.kDrawingDocumentObject Then
	oParams = ThisDrawing.Document.Parameters
End If
Dim oParam As Inventor.Parameter
Dim oAllOptions As New List(Of List(Of String))
Dim oOptions As New List(Of String)
For Each oParam In oParams
	If oParam.ExpressionList.Count > 0 Then
		oOptions = oParam.ExpressionList.GetExpressionList.ToList
		oAllOptions.Add(oOptions)
	End If
Next
'now you have a Lisf of all the Lists in one object reference (oAllOptions)
'Lists are usually easier to work with than Arrays
'For Each oSList As List(Of String) In oAllOptions
'	InputListBox(" ", oSList) 'just shows you that it worked
'Next

'but if you want just one long list of all the options, we can do this
Dim oAll As New List(Of String)
For Each oList As List(Of String) In oAllOptions
	oAll.AddRange(oList)
Next
'InputListBox(" ", oAll) 'just to show that it worked

'convert the List back into an Array
Dim oAllArray() As String = oAll.ToArray
InputListBox(" ", oAllArray) 'just to show that it worked

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

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 17 of 46

j.haggenjos
Advocate
Advocate

I found the issue. In the case of a boolean parameter, ExpressionList does not exist and will trigger an error.

 

You need to check the following to properly identify Multivalue parameter:

 

 

If oParameter.ExpressionList IsNot Nothing AndAlso oParameter.ExpressionList.Count <> 0 Then

 

 

Message 18 of 46

ahmed.hagi
Enthusiast
Enthusiast

It didn't crash when i substituted it in the original. But it is only printing 2 items, i'm guessing it is overriding at each step of the loop?

0 Likes
Message 19 of 46

j.haggenjos
Advocate
Advocate

Yes, with the code I gave you, you will only keep the parameter values from the last loop.

 

Check @WCrihfield reply for a more detailed and complete code. I agree with him that a list will be more flexible for you to work with.

0 Likes
Message 20 of 46

ahmed.hagi
Enthusiast
Enthusiast

This doesn't seem to work for me? I'm getting a not set to an instance of an object error.

0 Likes