add user parameter for each part in assembly

add user parameter for each part in assembly

Damian_Apex
Enthusiast Enthusiast
1,022 Views
2 Replies
Message 1 of 3

add user parameter for each part in assembly

Damian_Apex
Enthusiast
Enthusiast

Hello,

I am trying to create a rule that will loop through all parts in my assembly and will create "user parameter" according to the filename of part. 

 

I have something like this but the rule is adding all parameters to my top assembly not single parts and I stopped here and I don't know how to go on now.

thank you in advance for your help.

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument 
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oOcc_s As ComponentOccurrences = oCompDef.Occurrences
Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters
For Each oOcc In oOcc_s
	If oOcc.Name.Contains("-P-") = True Then
		oUserParams.AddByValue("IOM", "10", UnitsTypeEnum.kTextUnits)
	Else
	End If
Next

 

0 Likes
Accepted solutions (1)
1,023 Views
2 Replies
Replies (2)
Message 2 of 3

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Try

Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oDoc As Document
Dim oUserParam As UserParameter 

For Each oDoc In oAssDoc.AllReferencedDocuments
	If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		If oDoc.FullDocumentName.Substring(oDoc.FullDocumentName.LastIndexOf("\")+1).Contains("-P-") Then
			Try
				oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("IOM", "10", UnitsTypeEnum.kTextUnits)
			Catch ex As Exception
				MsgBox (ex)
			End Try
		End If
	End If
Next

MsgBox("Done",,"iLogic")

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

Damian_Apex
Enthusiast
Enthusiast

Great, this is exactly what I was looking for. Thank you 

0 Likes