Populate assembly level multi value list with component model state options

Populate assembly level multi value list with component model state options

gharveyMHN58
Contributor Contributor
373 Views
3 Replies
Message 1 of 4

Populate assembly level multi value list with component model state options

gharveyMHN58
Contributor
Contributor

Hi All,

 

I have a ilogic form driven configurator, which uses a component that has many model states. I would like to populate a multivalue list at the assembly level with either: 1) a parameter from the component that varies by model state, or 2) a custom iProperty of the component that varies by model state. this will then allow the user to select the desired model state. 

 

manually adding wont work, as the component changes, and hence the available model state options, depending on other options in the configurator.

 

Thanks in advance for any help. 

0 Likes
Accepted solutions (1)
374 Views
3 Replies
Replies (3)
Message 2 of 4

gharveyMHN58
Contributor
Contributor

This is what I have been trying, which doesnt seem to work.

Dim AssemDoc As AssemblyDocument
AssemDoc = ThisApplication.ActiveDocument

Dim oAssCompDef As AssemblyComponentDefinition = AssemDoc.ComponentDefinition
Dim oComps As ComponentOccurrences = oAssCompDef.Occurrences
For Each oComp As ComponentOccurrence In oComps 'find the 'piston' component ' If oComp.Name.Contains("Piston") Then Dim ofile As PartDocument ofile = oComp.OccurrencePath Dim oDef As PartComponentDefinition oDef = ofile.ComponentDefinition Dim oStates As ModelStates oStates = oDef.ModelStates Dim oTable As ModelStateTable oTable = oStates.ModelStateTable Dim oRow As ModelStateTableRow Dim MyArrayList As New ArrayList i=1 For Each oRow In oTable.TableRows oStates.Item(i).Activate MyArrayList.Add(Parameter("Piston", "Length")) i=i+1 Next MultiValue.List("Length") = MyArrayList Exit For Else End If Next
0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @gharveyMHN58.  For one thing...this bit of code won't work:

Dim ofile As PartDocument
ofile = oComp.OccurrencePath

...because a ComponentOccurrence.OccurrencePath returns a ComponentOccurrencesEnumerator object, not a PartDocument object.  There are a few ways to get the document that a component is representing.  And you usually want to test which type of document it is before trying to assign it to a specific document type variable, but in this case, since were finding the component by name, we already know what type it will be.  I fixed that bit of code, and I believe I may have fixed the rest of it as needed to, but I have not tested it, because I don't have your data set to test it on.  Give this a try and see if it works for you.

Dim AssemDoc As AssemblyDocument = ThisApplication.ActiveDocument
oAssCompDef = AssemDoc.ComponentDefinition
oComps = oAssCompDef.Occurrences
Dim MyArrayList As New ArrayList
For Each oComp As ComponentOccurrence In oComps  'find the 'piston' component
	If Not oComp.Name.Contains("Piston") Then Continue For
	Dim oPartDoc As PartDocument = oComp.ReferencedDocumentDescriptor.ReferencedDocument
	If oPartDoc.ComponentDefinition.IsModelStateMember Then 'not currently set to "Master"
		oPartDoc = oPartDoc.ComponentDefinition.FactoryDocument
	End If
	oTable = oPartDoc.ComponentDefinition.ModelStates.ModelStateTable
	For Each oRow As ModelStateTableRow In oTable.TableRows
		Try
			MyArrayList.Add(CDbl(oRow.Item("Length").Value))
		Catch
		End Try
	Next
	Exit For	
Next
MultiValue.List("Length") = MyArrayList

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 want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

gharveyMHN58
Contributor
Contributor

That does exactly what I wanted, thank you for your help.

 

One point to note, in my case I was trying to populte the list with a custom iProperty, so oRow.item("Length").Value needed to be oRow.item("Length [Custom]").Value.

 

Thank you for your help.