iLogic rule to change the value of the same parameter of multiple components

iLogic rule to change the value of the same parameter of multiple components

Anonymous
Not applicable
3,108 Views
8 Replies
Message 1 of 9

iLogic rule to change the value of the same parameter of multiple components

Anonymous
Not applicable

Hello everybody,

 

I'd like to do an assembly with multiple iLogic component. In every component I want to place to the assembly is about 20 parameter that needs to be driven by the assembly parameters. I have named parameters in every component same way for example "Module_lenght", "Width_1", "Width_2" and so on.

 

I know that there is the possibility to choose whether the parameters is driven by the assembly or by the user when user is placing the component. Hence there is over twenty components in the assembly it would be great if there is a rule to change all the parameters at the same time.

 

I know that there is a very simple rule to change parameters of one component to match the assembly parameters. For example:

 

  Parameter("Window_module:1", "Module_lenght") = Module_lenght

 

 If I place new "Window_module" to the assembly, I have to do new line to the rule:

 

  Parameter("Window_module:2", "Module_lenght") = Module_lenght

 

Is there a way to chance component parameter "Module_lenght" to assembly parameter for all the components that I have placed whit one rule?

 

Any help would be appreciated. I'm using Inventor 2015.

 

Best Regards

Mika

0 Likes
Accepted solutions (1)
3,109 Views
8 Replies
Replies (8)
Message 2 of 9

LukeDavenport
Collaborator
Collaborator
Accepted solution
Hi Mika, In a previous life I created an iLogic rule that runs through the
entire assembly (all levels) and if it finds any part parameters that have
the same name as an assembly parameter, it sets the value of the part
parameter equal to the assembly parameter. I don't have the link to hand,
but if you search on Cadline community for 'iLogic parameters assembly' it
should come up. Luke
Message 3 of 9

Anonymous
Not applicable

Hi Luke and thank you for your answer!

 

I came up with the code that works just after I had posted my question. Thanks for ThomasB44 for the link he gave to me (when I first posted my question to the wrong section of the forum) and for the APatterson 1 for the code. I didn't really understand the code first but after studying it makes sense now.

 

SyntaxEditor Code Snippet

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Iterate through all occurrences
Dim oOcc As ComponentOccurrence

For Each oOcc In oAsmCompDef.Occurrences

Try

Parameter(oOcc.Name,"Module_lenght") = Module_lenght

Catch

End Try

Next

MessageBox.Show("Module_lenght was updated.")

 

I did although find almost the same code from the Cadline community. So I thank you for your help. It's amazing what one can do with the Inventor.

 

Best Regards

Mika

0 Likes
Message 4 of 9

LukeDavenport
Collaborator
Collaborator

 Hi Mika,

That code you posted will only do the top level assembly components (and obviously only work with the single parameter name you mention).

 

If you don't want those limitations, the iLogic code below will automatically drive any part parameters with the same name as an assembly parameter (excluding non-renamed ‘d0’, ‘d1’, ‘d2’ etc parameters) in all levels of the assembly - I'll post it here as others may also find it useful.

Luke

 

Sub Main DriveAllAssemblyParams
' Set reference to active document.
'check this file is an assembly
doc = ThisDoc.ModelDocument
If doc.DocumentType = kPartDocumentObject Then
MessageBox.Show("This rule can only be run in an assembly file!", "Cadline iLogic")
Return
End If
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oParam As Parameter
Dim oParams As Parameters = oDef.Parameters
Dim oModParams As ModelParameters = oParams.ModelParameters
Dim oRefParams As ReferenceParameters = oParams.ReferenceParameters
Dim oUserParams As UserParameters = oParams.UserParameters
Dim oCompOcc As Inventor.ComponentOccurrence
' Create list of assembly parameters. Note this will add ALL
' User parameters, table (spreadsheet) parameters, and derived
' parameters to the list for matching. Only renamed model and ref
' parameters will be added
Dim ParamsArray As New ArrayList
For Each oParam In oParams
If oParam.ParameterType = 11524 _ ' User parameters
OrElse oParam.ParameterType = 11523 _ ' Table parameters
OrElse oParam.ParameterType = 11525 _ ' Derived parameters
OrElse oParam.Renamed = True Then ' Renamed model/ref parameters
ParamsArray.Add(oParam)
End If
Next
'---------------------------------
For Each oCompOcc In oDef.Occurrences
If oCompOcc.Suppressed = False Then
Compcount = oCompOcc.Name.Substring(oCompOcc.Name.LastIndexOf(":")+1)
If IsNumeric(Compcount) = False OrElse Compcount = 1 Then
For Each oParam In oCompOcc.Definition.Parameters
If oParam.ParameterType = 11524 OrElse oParam.Renamed = True Then
'MessageBox.Show("Adding Parameter " & oSubCompParam.Name & _
'" from component " & oSubCompOcc.Name, "Title")
Call CompareParams(oParam,ParamsArray)
End If
Next
' Check if child occurences exist
If oCompOcc.SubOccurrences.Count > 0 Then
Call processAllSubOcc(oCompOcc,ParamsArray)
End If
End If
End If
Next
RuleParametersOutput()
InventorVb.DocumentUpdate()
ThisApplication.ActiveView.Update()
End Sub
' Sub function to traverse through the entire assembly tree recursively
Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence, _
ByVal ParamsArray As ArrayList)
Dim oSubCompParam As Parameter
Dim oSubCompOcc As ComponentOccurrence
For Each oSubCompOcc In oCompOcc.SubOccurrences
If oSubCompOcc.Suppressed = False Then
Compcount2 = oSubCompOcc.Name.Substring(oSubCompOcc.Name.LastIndexOf(":")+1)
If IsNumeric(Compcount2) = False OrElse Compcount2 = 1 Then
For Each oSubCompParam In oSubCompOcc.Definition.Parameters
If oSubCompParam.ParameterType = 11524 OrElse _
oSubCompParam.Renamed = True Then
'MessageBox.Show("Adding Parameter " & oSubCompParam.Name & _
'" from component " & oSubCompOcc.Name, "Title")
Call CompareParams(oSubCompParam,ParamsArray)
End If
Next
' Check if child exists
If oSubCompOcc.SubOccurrences.Count > 0 Then
Call processAllSubOcc(oSubCompOcc,ParamsArray)
End If
End If
End If
Next
End Sub
' Sub function to change parameter value if matches asm name
Sub CompareParams(ByVal Param As Parameter, _
ByVal ParamsArray As ArrayList)
For Each a As Parameter In ParamsArray
If Param.Name = a.Name AndAlso Not Param.Value = a.Value Then
Param.Value = a.Value
End If
Next
End Sub
'

0 Likes
Message 5 of 9

Anonymous
Not applicable

Thank you Luke. I really don't know what to say.  It's a little bit more complex than I expected but it really does the trick. I still managed to brake it somehow.

 

Problem is that it doesn't update all of the components that I have placed in the assembly. It worked fine when I placed two Window_module to the assembly at the same time. They were named as Window_module:1 and Window_module:2. I then placed the third Window_module to the assembly and when I tried to change the parameter it only updated to the first two Window_modules. I don't see where the problem is. Do you?

 

Best Regards

Mika

0 Likes
Message 6 of 9

LukeDavenport
Collaborator
Collaborator

Hi Mika,

It looks like you might have found a bug in the code. Haven't got time to check it now, but you could try deleting from the original code the red lines below - that might work.

Good luck!
Luke

 

Dim oSubCompOcc As ComponentOccurrence
For Each oSubCompOcc In oCompOcc.SubOccurrences
If oSubCompOcc.Suppressed = False Then
Compcount2 = oSubCompOcc.Name.Substring(oSubCompOcc.Name.LastIndexOf(":")+1)
If IsNumeric(Compcount2) = False OrElse Compcount2 = 1 Then
For Each oSubCompParam In oSubCompOcc.Definition.Parameters
If oSubCompParam.ParameterType = 11524 OrElse _
oSubCompParam.Renamed = True Then
'MessageBox.Show("Adding Parameter " & oSubCompParam.Name & _
'" from component " & oSubCompOcc.Name, "Title")
Call CompareParams(oSubCompParam,ParamsArray)
End If
Next
' Check if child exists
If oSubCompOcc.SubOccurrences.Count > 0 Then
Call processAllSubOcc(oSubCompOcc,ParamsArray)
End If
End If
End If

0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi Luke,

 

Thanks again for the answer, I appreciate it.

 

Eliminating those lines didn't work. I'm placing components as iLogic component because there is other (key)parameters that I'd like to change when I'm placing the component. Could it cause the bug?

 

It would be great if you can you explain what happens in the "Compcount2" definition. I don't get how the number of components is counted.

 

Best Regards

Mika

0 Likes
Message 8 of 9

Anonymous
Not applicable

Hello Everybody,

 

I still have troubles to get the parameters right. I thought that I have solved this problem but I was wrong. I thought that if I make a rule in the sub-assembly that defines that the parameters of the parts in that sub-assembly is controlled by the parameters of the sub-assembly and then if I run a rule in the final assembly that defines that the parameters of the sub-assembly is controlled by the parameters of the final assembly everything should be just fine. Apparently the rule of the sub-assembly doesn't apply in the final assembly. I hope that my explanation clears things out.

Rules.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Does anyone have an idea how to make this happen? I would use Luke's code but there is something wrong with it.

 

Best Regards

Mika

0 Likes
Message 9 of 9

Anonymous
Not applicable

Hi again,

 

I managed to solve it out.

 

SyntaxEditor Code Snippet

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

Dim oCompOcc As Inventor.ComponentOccurrence
Dim oSubCompOcc As Inventor.ComponentOccurrence

For Each oCompOcc In oDef.Occurrences
For Each oSubCompOcc In oCompOcc.SubOccurrences
Try
Parameter(MakePath(oCompOcc.Name,oSubCompOcc.Name),"Width_1") = Width_1
Parameter(MakePath(oCompOcc.Name,oSubCompOcc.Name),"Width_2") = Width_2
Catch
MessageBox.Show(oSubCompOcc.Name & "Parameter doesn't exist")
End Try
Next
Next

 

This changes only two parameter so I have to write more lines but that's easy to do. I had to use MakePath-command because the names of the parts in the sub-assemblies are the same. I guess that identifies which parameter we are changing. Thanks for Luke. Your code was the key.

 

BR

Mika

 

0 Likes