API: Push Parameter Value of "MainPart" to others

API: Push Parameter Value of "MainPart" to others

Anonymous
Not applicable
729 Views
4 Replies
Message 1 of 5

API: Push Parameter Value of "MainPart" to others

Anonymous
Not applicable

In the assembly, I would like to push the parameter value of the "MainPart" if the parameter exists in the other parts.

 

"MainPart" parameter conditions:  If it contains "x".

Other parts DisplayName conditions: If it contains "Include".

 

I hope my explaination is understandable.

 

In pure ilogic, it would be like this:

Parameter("Include_01:1", "x_Width") = Parameter("MainPart:1", "x_Width")
Parameter("Include_02:1", "x_Height")=Parameter("MainPart:1", "x_Height")

 

Here is the unfinished code that my brain can only do.

 

Dim oDoc As AssemblyDocument = ThisAssembly.Document
Dim asmDef = oDoc.ComponentDefinition
Dim oMainParam As New ArrayList
Dim i As Integer = 0

For Each occ As ComponentOccurrence In asmDef.Occurrences
	Dim occDoc As Document = occ.Definition.Document

	If occ.Name.Contains("Main") Then
		Dim oMain As PartDocument = occDoc
		MsgBox(oMain.DisplayName)
		
		For Each oParam In oMain.ComponentDefinition.Parameters
			If oParam.Name.Contains("x") Then
				oMainParam.Add(oParam.Name)
				'MsgBox(oMain.DisplayName & vblf & vblf & oParam.Name)
			End If			
		Next
		
		For x As Integer = 0 To oMainParam.Count - 1
		xList = xList & vbLf & oMainParam(x) & vbLf
		Next
		
		MessageBox.Show(xList)
		
		
	End If	
	
	If occDoc.DisplayName.Contains("Include") Then
	i += 1
	MsgBox(i)
	End If		
Next

	

Thank you so much.

 

PushParam.JPG

0 Likes
Accepted solutions (1)
730 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

You know, you could link fx-parameters between parts in an assembly? Or you can create your include parts as derived part and derive the parameters you need. Both versions update parameter values automatically on change.

Or try this code.

Dim oAsmDoc As AssemblyDocument = ThisAssembly.Document
Dim oPartDoc As PartDocument
Dim oDoc As Document
Dim oPartCompDef As PartComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oParam As UserParameter
			
For Each oDoc In oAsmDoc.AllReferencedDocuments
	If oDoc.DisplayName.StartsWith("Main") Then
		If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then 
			oPartDoc = TryCast(oDoc, PartDocument)
			If oPartDoc IsNot Nothing Then
				For Each oParam In oPartDoc.ComponentDefinition.Parameters.UserParameters
					If oParam.Name.StartsWith("x_") Then
						For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences
							If oOcc.DefinitionDocumentType= DocumentTypeEnum.kPartDocumentObject  Then
								oPartCompdef = oOcc.Definition
								If oPartCompdef.Document.Displayname.StartsWith("Include") Then
									Try
										oPartCompdef.Parameters.UserParameters.Item(oParam.Name).Expression=oParam.Expression
									Catch
									End Try
								End If
							End If
						Next
					End If
				Next
			End If
		End If
	End If
Next

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi @Ralf_Krieg ,

I almost got it. 

For now the code works only in one parameter,

Im not sure why.

 

 

Dim oDoc As AssemblyDocument = ThisAssembly.Document
Dim asmDef = oDoc.ComponentDefinition
Dim oMain As PartDocument
Dim mParams As New ArrayList
Dim mParam As Parameter
Dim inPart As PartDocument
Dim inParts As New ArrayList

For Each occ As ComponentOccurrence In asmDef.Occurrences
	Dim occDoc As Document = occ.Definition.Document
	
	If occ.Name.Contains("Main") Then
		oMain = occDoc	
	Else If occDoc.DisplayName.Contains("Include") Then
		inPart = occDoc
		inParts.Add(inPart)
	End If		
Next

For Each mParam In oMain.ComponentDefinition.Parameters
	If mParam.Name.Contains("x") Then
		mParams.Add(mParam)
	End If
Next

For Each inPart In inParts
	'This doesnt works.
	For Each inParam As Parameter In inPart.ComponentDefinition.Parameters
		If inParam.Name.Contains("x") AndAlso inParam.Name = mParam.Name Then
			inParam.Value = mParam.Value
		End If
	Next
Next

	

 

 

0 Likes
Message 4 of 5

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

You need also to travers your collected mParams. Try

For Each inParam As Parameter In inPart.ComponentDefinition.Parameters
    For Each mParam As Parameter In mParams
		If inParam.Name.Contains("x") AndAlso inParam.Name = mParam.Name Then
			inParam.Value = mParam.Value
		End If
    Next
Next

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 5 of 5

Anonymous
Not applicable

Thank you @Ralf_Krieg . 

 

Dim oDoc As AssemblyDocument = ThisAssembly.Document
Dim asmDef = oDoc.ComponentDefinition
Dim oMain As PartDocument
Dim mParams As New ArrayList
Dim inPart As PartDocument
Dim inParts As New ArrayList

For Each occ As ComponentOccurrence In asmDef.Occurrences
	Dim occDoc As Document = occ.Definition.Document
	
	If occ.Name.Contains("Main") Then
		oMain = occDoc	
	Else If occDoc.DisplayName.Contains("Include") Then
		inPart = occDoc
		inParts.Add(inPart)
	End If		
Next

For Each mParam In oMain.ComponentDefinition.Parameters
	If mParam.Name.Contains("x") Then
		mParams.Add(mParam)
	End If
Next

For Each inPart In inParts
	For Each inParam As Parameter In inPart.ComponentDefinition.Parameters
		For Each mParam As Parameter In mParams
			If inParam.Name.Contains("x") AndAlso inParam.Name = mParam.Name Then
				inParam.Value = mParam.Value
			End If
		Next
	Next
Next

	
0 Likes