Hi @Scott_Stubbington. That is usually the problem when using iLogic snippets in your code, without specific document reference, in complex scenarios. They are not always easy to recognize either. The 'Component.InventorComponent()' line of code is an iLogic snippet, and allows you to search for a named component without specifying what assembly to look for them in, because it assumes it will be the 'active' assembly. Seems simpler, and easier to use, but a bit sneaky. Also the 'Parameter("paramName")' line of code is an iLogic snippet, and again, if you did not specify either a component name or document name, as part of the input variable(s), it will target the 'active' document by default. To avoid these types of situations in complex scenarios, I often revert back to the better documented, tried & true API route of doing that task, to be sure.
I created a slightly alternate version of your local rule that you can try. If this code works for you on its own, then I'm hoping it will solve the possible document reference issues and cause it to start running as usual. By the way, maybe as an initial test, before changing the entire local rule code, try putting one or two simple messages into that local rule (maybe one at start and one at end), then run your main routine again. If those messages show up, that will tell us that the rule is actually running, but just not targeting the right document(s), and therefore does not appear to be running. If these measures don't fix the main problem, then there may be something else causing the problem.
I left some comment lines in there to help you understand what I've done. Since I was not sure if all 4 of those components were at the top level of the assembly, and I know that iLogic snippet will retrieve components from any level of the assembly, I assumed that they might not be at the top level of the assembly, and created our own Function to retrieve the named components from any level of the assembly. Only the one I created is definitely being supplied the components from our 'local' assembly, not some other 'active' assembly.
Sub Main
'get the 'local' document
Dim oADoc As AssemblyDocument = ThisDoc.Document 'local document
oOccs = oADoc.ComponentDefinition.Occurrences
'if these components are all on top level, this will work
'varOccR1 = oOccs.ItemByName("Fan Guide#1:1")
'if they are not all on top level, use this to get them by name (referenced from 'local' document)
'use our custom Function below to retrieved named components from any level of assembly
varOccR1 = GetNamedComponent(oOccs, "Fan Guide#1:1")
varOccR2 = GetNamedComponent(oOccs, "Fan Guide#2:1")
varOccL1 = GetNamedComponent(oOccs, "Fan Guide#1:2")
varOccL2 = GetNamedComponent(oOccs, "Fan Guide#2:2")
'make sure they were found, if not let user know then exit rule
If IsNothing(varOccR1) Or IsNothing(varOccR2) Or _
IsNothing(varOccL1) Or IsNothing(varOccL2) Then
MsgBox("One or more of the specified components were not found. Exiting rule.", vbCritical, "iLogic")
Exit Sub
End If
'get the parameter from this local document specifically
'if not found, let user know then exit rule
Dim oParam As Inventor.Parameter
Try
oParam = oADoc.ComponentDefinition.Parameters.Item("CentrePanelLeft")
Catch oEx As Exception
MsgBox("Could not fine the specified Parameter. Exiting rule." & vbCrLf & _
oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "iLogic")
Exit Sub
End Try
'If oParam.Expression = "0" Then ' Right
If oParam.Value = 0 Then ' Right
varOccR1.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
varOccR1.Visible = False
varOccR2.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
varOccR2.Visible = False
varOccL1.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
varOccL1.Visible = True
varOccL2.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
varOccL2.Visible = True
Else ' Left
varOccR1.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
varOccR1.Visible = True
varOccR2.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
varOccR2.Visible = True
varOccL1.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
varOccL1.Visible = False
varOccL2.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
varOccL2.Visible = False
End If
End Sub
Function GetNamedComponent(oComps As ComponentOccurrences, oCompnentName As String) As ComponentOccurrence
For Each oComp As ComponentOccurrence In oComps
If oComp.Name = oCompnentName Then
'exit the function, while returning that component
Return oComp
End If
If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oSComp = GetNamedComponent(oComp.Definition.Occurrences, oCompnentName)
If Not IsNothing(oSComp) Then Return oSComp 'exit the function, while returning that component
End If
Next
'if code reaches this point, the component was not found, so return Nothing
Return Nothing
End Function
Wesley Crihfield

(Not an Autodesk Employee)