Copy Parameters to all Sub assemblies and parts

Copy Parameters to all Sub assemblies and parts

donaldleigh
Advocate Advocate
1,004 Views
6 Replies
Message 1 of 7

Copy Parameters to all Sub assemblies and parts

donaldleigh
Advocate
Advocate

Afternoon all

I would like to copy a list of user parameters (Text and Numbers) to each Sub Assembly and part. If that parameter is missing in each sub assembly or part it is to create it.  It should work on editable models only (exclude all CC parts).

 

Can someone help me please.

 

Donald

Inventor 2021

0 Likes
1,005 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @donaldleigh 

Is it a specific list of user parameters you want to copy or do you want to copy all of them?

Are there any relationships between these parameters? ex. param_2 = param_1 * 2.

If so, is it important to keep those relationships or do you just want to copy the value?

0 Likes
Message 3 of 7

donaldleigh
Advocate
Advocate

Yes it will be a specific list of parameters. I would also like to be able to add to the list as I go. At this stage I don't think there will be any relationship between parameters so will only need to copy the values. Most of them will be text

 

Donald

0 Likes
Message 4 of 7

robertast
Collaborator
Collaborator

@donaldleigh 

Look at this example where the rule from @JhoelForshav 

is used, thanks a lot for that. I am very satisfied 😊

 

still convincing him to tackle the “smart component” that would be super general 😉

 

0 Likes
Message 5 of 7

donaldleigh
Advocate
Advocate

@robertast  Thanks for sending that. Couple of things

  • it adds all the user parameter. I would like to be able to enter only the parameters i need in the rule to include
  • This rule misses the sub assemblies
  • When I added a text parameter into the top level and run the rule it added quotation marks to the start and end of the parts.

But this is a start for sure

 

Cheers

Donald

0 Likes
Message 6 of 7

robertast
Collaborator
Collaborator

@donaldleigh 

@JhoelForshav  will write you a program - he is good 😊. I asked my program to get rid of the adaptive part in the assembly. And it works great. The rule does not pass only logical parameters, they must be converted to text.

If he took the time and wrote the right program for the “smart component,” 🤗

0 Likes
Message 7 of 7

JhoelForshav
Mentor
Mentor

Hi @donaldleigh 

I don't know how you want to specify that list of parameters. The way i wrote it now is that all parameters you want to be copied from the top assemblys userparameters should have a name that starts with "XX". So if you have a userparameter named XX_testparam, that will be copied.

 

Dim CopyParams As String = "XX" 'The program will copy all user parameters in top assembly that starts with this string
Dim oAsm As AssemblyDocument = ThisDoc.Document
For Each oDoc As Document In oAsm.AllReferencedDocuments
	If (oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso oDoc.ComponentDefinition.IsContentMember = False) _
		Or oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject

		If oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0
			For Each oParam As Inventor.Parameter In oAsm.ComponentDefinition.Parameters.UserParameters
				If oParam.Name.StartsWith(CopyParams)
					Dim docParam As Inventor.Parameter
					Try
						docParam = oDoc.ComponentDefinition.Parameters.UserParameters.Item(oParam.Name)
						docParam.Value = oParam.Value
					Catch
						docParam = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(oParam.Name, oParam.Value, oParam.Units)
					End Try
				End If
			Next

		End If
	End If
Next

iLogicVB.UpdateWhenDone = True