Parameter override ilogc codes

Parameter override ilogc codes

karram
Advocate Advocate
945 Views
9 Replies
Message 1 of 10

Parameter override ilogc codes

karram
Advocate
Advocate

Hello,

 

In main assembly, i had many sub assembly and parts.

if i run my parameter overrides ilogc codes (Sample code below) in main assembly, its read and run all sub assembly and parts related fx user parameters and it will take more time to run full code some time takes 20 to 30 minutes.

 

Parameter("Part:1", "color") = color

 Is there any alternate ilogic codes to run very quickly and read and update all main assembly parameter to sub parts and sub assembly corresponding parameters.

 

Thanks

0 Likes
946 Views
9 Replies
Replies (9)
Message 2 of 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @karram . This code changes the parameter value if there is a match in the parameter name. In line 5, write the name of the parameter.

Sub main 
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oADoc As AssemblyDocument = oDoc
		Dim sNameRaram As String = "color"
		Dim oParam As Inventor.Parameter = GetParam(oADoc.ComponentDefinition.Parameters, sNameRaram)
		If oParam Is Nothing Then Exit Sub
		Call GetComponents(oADoc.ComponentDefinition.Occurrences, oParam)
	Else
	End If
End Sub

Private Sub GetComponents(ByVal oOccs As ComponentOccurrences, ByVal oParam As Inventor.Parameter)
	For Each oOcc As ComponentOccurrence In oOccs
		If Not oOcc.Suppressed Then
			If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
				Dim oADef As AssemblyComponentDefinition = oOcc.Definition
				Dim oADoc As AssemblyDocument = oADef.Document
				If oADoc.IsModifiable Then
					Call ChangeParam(oADef.Parameters, oParam)
				End If
				Call GetComponents(oOcc.SubOccurrences, oParam)
			Else If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
				Dim oPDef As PartComponentDefinition = oOcc.Definition
				Dim oPDoc As PartDocument = oPDef.Document
				If oPDoc.IsModifiable Then
					Call ChangeParam(oPDef.Parameters, oParam)
				End If
			End If
		End If
	Next
End Sub

Private Function ChangeParam(ByVal oParams As Parameters, ByVal newParam As Inventor.Parameter)
	For Each oParam As Inventor.Parameter In oParams
		If oParam.Name = newParam.Name Then
			On Error Resume Next
			oParam.Value = newParam.Value
		End If
	Next
End Function

Private Function GetParam(ByVal oParams As Parameters, ByVal sNameRaram As String) As Inventor.Parameter
	For Each oParam As Inventor.Parameter In oParams
		If oParam.Name = sNameRaram Then
			Return oParam
		End If
	Next
	Return Nothing
End Function

 

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 3 of 10

karram
Advocate
Advocate
Accepted solution

Hello,

 

Its looks perfect,

In real time for my project i used almost 100 nos for user parameters, its very hard to use all parameter names in ilogice codes. instead of use this below parameters name, is there any alternative code that user parameter in main assembly automatically updates for all sub assembly and parts also quick to update whole assembly process

Parameter("Part:1", "color") = color
Parameter("Part:1", "xx") = xx
Parameter("Part:1", "xx") = xx
Parameter("Part:1", "xx") = xx
.
.
.

 

0 Likes
Message 4 of 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

This code creates a list of userparameters in the main assembly, then matches the names of this list with userparameters in subassemblies and details.

 

 

  

Sub main 
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oTm As TransactionManager = ThisApplication.TransactionManager
		Dim oADoc As AssemblyDocument = oDoc
		Dim newTM As Transaction = oTm.StartTransaction(oADoc, "ChangeUserParameters")
		Dim listParams As New List(Of UserParameter)
		listParams = GetParam(oADoc.ComponentDefinition.Parameters)
		If listParams Is Nothing Then Exit Sub
		Call GetComponents(oADoc.ComponentDefinition.Occurrences, listParams)
		newTM.End()
		oADoc.Update()
	Else
	End If
End Sub

Private Sub GetComponents(ByVal oOccs As ComponentOccurrences, ByVal listParams As List(Of UserParameter))
	For Each oOcc As ComponentOccurrence In oOccs
		If Not oOcc.Suppressed Then
			If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
				Dim oADef As AssemblyComponentDefinition = oOcc.Definition
				Dim oADoc As AssemblyDocument = oADef.Document
				If oADoc.IsModifiable Then
					Call ChangeParam(oADef.Parameters, listParams)
				End If
				Call GetComponents(oOcc.SubOccurrences, listParams)
			Else If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
				Dim oPDef As PartComponentDefinition = oOcc.Definition
				Dim oPDoc As PartDocument = oPDef.Document
				If oPDoc.IsModifiable Then
					Call ChangeParam(oPDef.Parameters, listParams)
				End If
			End If
		End If
	Next
End Sub

Private Function ChangeParam(ByVal oParams As Parameters, ByVal listParams As List(Of UserParameter))
	For Each oParam As UserParameter In oParams.UserParameters
		For Each mainParam As UserParameter In listParams
			If oParam.Name = mainParam.Name Then
				On Error Resume Next
				oParam.Value = mainParam.Value
			End If
		Next
	Next
End Function

Private Function GetParam(ByVal oParams As Parameters) As List(Of UserParameter)
	Dim listParams As New List(Of UserParameter)
	For Each oParam As UserParameter In oParams.UserParameters
		listParams.Add(oParam)
	Next
	Return listParams
End Function

Update

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 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Try this code. It runs faster and should import parameter better.

Sub main 
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oTm As TransactionManager = ThisApplication.TransactionManager
		Dim oADoc As AssemblyDocument = oDoc
		Dim newTM As Transaction = oTm.StartTransaction(oADoc, "ChangeUserParameters")
		Dim listParams As New List(Of UserParameter)
		listParams = GetParam(oADoc.ComponentDefinition.Parameters)
		If listParams Is Nothing Then Exit Sub		
		Call GetComponents(oADoc.AllReferencedDocuments, listParams)
		newTM.End()
		oADoc.Update()
	Else
	End If
End Sub

Private Sub GetComponents(ByVal oRefDocs As DocumentsEnumerator, ByVal listParams As List(Of UserParameter))
	For Each oRefDoc As Document In oRefDocs		
		If TypeOf oRefDoc Is AssemblyDocument Then
			Dim oADoc As AssemblyDocument = oRefDoc
			Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
			If oADoc.IsModifiable Then
				Call ChangeParam(oADef.Parameters, listParams)
			End If
		Else If TypeOf oRefDoc Is PartDocument Then
			Dim oPDoc As PartDocument = oRefDoc
			Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
			If oPDoc.IsModifiable Then
				Call ChangeParam(oPDef.Parameters, listParams)
			End If
		End If
	Next
End Sub

Private Function ChangeParam(ByVal oParams As Parameters, ByVal listParams As List(Of UserParameter))
	For Each oParam As UserParameter In oParams.UserParameters
		For Each mainParam As UserParameter In listParams
			If oParam.Name = mainParam.Name Then
				On Error Resume Next
				oParam.Expression = mainParam.Expression
			End If
		Next
	Next
End Function

Private Function GetParam(ByVal oParams As Parameters) As List(Of UserParameter)
	Dim listParams As New List(Of UserParameter)
	For Each oParam As UserParameter In oParams.UserParameters
		listParams.Add(oParam)
	Next
	Return listParams
End Function

 

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

0 Likes
Message 6 of 10

karram
Advocate
Advocate

Here i attached sample test file.

Check in Main assembly Length parameter its not update in sub Assy01 > part3, part4, Part5.

0 Likes
Message 7 of 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

You will not be able to export a parameter with the formula (Test_01 + Test_02) to a part that does not have these parameters. You need to create these parameters in detail, or use "Value" .

1 - Expression; 2 - Value.

Parameters main assembly:

Param(mainAssemb).png

Parameters part:

Param(Part3).png

Parameters part (create parameters):

Param(Part3)+Param.png

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

0 Likes
Message 8 of 10

karram
Advocate
Advocate

Now perfect works

Thanks

Message 9 of 10

karram
Advocate
Advocate

hello again,

 

Regarding override ilogic above code, if i run this code in assembly environment (Assembly contains more sheet metal parts), then its check this check box (Marked red color) always as like default.

But my requirements is, i used to linked user parameter in thickness text box, its stay always as per my user parameters like blue color. If i run the ilogic code the thickness parameter always changed as per main assembly user parameters.

karram_0-1684915906140.pngkarram_1-1684915934499.png

 

0 Likes
Message 10 of 10

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Your situation could not be reproduced. The rule performs actions only with user parameters, maybe you have something else going on in the background of the execution of this rule. I slightly optimized the code by removing redundant functions.

 

Sub main 
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oTm As TransactionManager = ThisApplication.TransactionManager
		Dim oADoc As AssemblyDocument = oDoc
		Dim newTM As Transaction = oTm.StartTransaction(oADoc, "ChangeUserParameters")
		Call GetComponents(oADoc.AllReferencedDocuments, oADoc.ComponentDefinition.Parameters.UserParameters)
		newTM.End()
		oADoc.Rebuild()
		oADoc.Update()
	Else
	End If
End Sub

Private Sub GetComponents(ByVal oRefDocs As DocumentsEnumerator, ByVal newParams As UserParameters)
	For Each oRefDoc As Document In oRefDocs		
		If TypeOf oRefDoc Is AssemblyDocument Then
			Dim oADoc As AssemblyDocument = oRefDoc
			Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
			If oADoc.IsModifiable Then
				Call ChangeParam(oADef.Parameters, newParams)
			End If
		Else If TypeOf oRefDoc Is PartDocument Then
			Dim oPDoc As PartDocument = oRefDoc
			Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
			If oPDoc.IsModifiable Then
				Call ChangeParam(oPDef.Parameters, newParams)
			End If
		End If
	Next
End Sub

Private Function ChangeParam(ByVal oParams As Parameters, ByVal newParams As UserParameters)
	For Each oParam As UserParameter In oParams.UserParameters
		For Each mainParam As UserParameter In newParams
			If oParam.Name = mainParam.Name Then
				oParam.Value = mainParam.Value
			End If
		Next
	Next
End Function

Run the test by changing "Value" to "Expression" in line 37.

 

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

0 Likes