Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

copy user parameter from assembly to subassembly and parts below

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Ahmed.shawkyXTZHN
231 Views, 4 Replies

copy user parameter from assembly to subassembly and parts below

Hi everyone , I was using the below code to drive the full sheet metal parts for the machine through assembly user parameters and it will copy same parameters to other parts  , but suddenly I start to receive error on line 31 which I can't solve so is there other code to do the same or how to debug old one  , thanks.

 

Sub Main
	Dim asm As AssemblyDocument = ThisDoc.Document
	copyParams(asm)
	iLogicVb.UpdateWhenDone = True
End Sub
Sub copyParams(oAsm As AssemblyDocument)
	For Each oDoc As Document In oAsm.AllReferencedDocuments
		If oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0
			If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
				Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
				' Extra
'				If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
'				Dim cDef As AssemblyComponentDefinition = cDoc.ComponentDefinition
				
				
				For Each oParam As Inventor.Parameter In oAsm.ComponentDefinition.Parameters.UserParameters
					Dim paramInPart As Inventor.Parameter
					Try
						paramInPart = oDef.Parameters.UserParameters.Item(oParam.Name)
						Try
							paramInPart.Expression = oParam.Expression
						Catch
							paramInPart.Value = oParam.Value
						End Try
					Catch
						Try
							oDef.Parameters.UserParameters.AddByExpression(oParam.Name, oParam.Expression, oParam.Units)
						Catch
							oDef.Parameters.UserParameters.AddByValue(oParam.Name, oParam.Expression, oParam.Units)
						End Try
					End Try
				Next
			ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
				'if the referenced document is an assembly
				'the sub will call itself with that document as the argument
				copyParams(oDoc)
			End If
		End If
'	End If
	
	Next
End Sub

 

error line "

oDef.Parameters.UserParameters.AddByValue(oParam.Name, oParam.Expression, oParam.Units)"

 

4 REPLIES 4
Message 2 of 5

Message 3 of 5

Hi , still facing same error
Error on line 31 in rule: Copy for parameters, in document: 00223807.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Message 4 of 5

Hi @Ahmed.shawkyXTZHN . I already answered a similar question, but in this case the rules are copied to the object you choose.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 5

thanks alot Andrii , issue solved , as this was issue with PDM system .

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report