How can I run a rule that references "ActiveDcoument" from a different active document

How can I run a rule that references "ActiveDcoument" from a different active document

leopoldo_valenciaJVJ9R
Explorer Explorer
638 Views
4 Replies
Message 1 of 5

How can I run a rule that references "ActiveDcoument" from a different active document

leopoldo_valenciaJVJ9R
Explorer
Explorer

Good evening,

 

I created a rule in a subassembly to turn al courrences as Default or reference depnding on a parameter I pass from a top level assembly. When I open the subassembly it runs fine, when I open the top assembly and pass the parameter to the subassembly file I get an error becaus I am trying to define the objects in "Active Document". How can I make this run?

 

' set a reference to the assembly component definintion
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition


'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
	'set BOM Structure
	If  z_visRefCtrl = True
		oOccurrence.BOMStructure = BOMStructureEnum.kDefaultBOMStructure	
	Else
		oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If
Next
' pass parameter to angle subassembly
Parameter("280-091:1", "z_visRefCtrl") = z_visRefCtrl

Can you hep me figure out what I need to change in the code to have the rule in the subassembly runing? 

0 Likes
Accepted solutions (1)
639 Views
4 Replies
Replies (4)
Message 2 of 5

Michael.Navara
Advisor
Advisor

This looks like you need two rules. The first which put  z_visRefCtrl value to subassembly and the second which set BOM structure.

In both of them use ThisDoc instead of ThisApplication.ActiveDocument. Because ThisDoc returns document in which context the rule is running.

 

'This should be in top-level assembly

' pass parameter to angle subassembly
Parameter("280-091:1", "z_visRefCtrl") = z_visRefCtrl

 

'This should be in sub-assembly

Dim asm As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef = asm.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
    'set BOM Structure
    If z_visRefCtrl = True Then
        oOccurrence.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
    Else
        oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
    End If
Next

 

 

 

0 Likes
Message 3 of 5

Q_Visser
Contributor
Contributor
Accepted solution

Hi @leopoldo_valenciaJVJ9R, do you want to update everything from the top level assembly or are you wanting to send the parameter and then manually open the sub assembly and run a rule within that?

If you are wanting to complete the entire process from the top level assembly, here are 2 options:

Use @Michael.Navara's method and add the following line in the top level assembly rule after passing the parameter to the sub assembly:

iLogicVb.RunRule("280-091:1", "ruleName")

Or, if you don't need to have the BOM Structure rule in the sub assembly, you can do the entire process from the top level assembly with the following:

'This rule should be in the top level assembly
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

Dim oSubAsmDocName As String = "280-091:1" 'Please note it is better to set this part with a static name in the tree, eg. "280-091"
Dim oSubAsmDoc As AssemblyDocument = oAsmCompDef.Occurrences.ItemByName(oSubAsmDocName).Definition.Document
Dim oSubAsmCompDef As AssemblyComponentDefinition = oSubAsmDoc.ComponentDefinition
Dim oSubAsmUserParam As UserParameter = oSubAsmCompDef.Parameters.UserParameters.Item("z_visRefCtrl")
oSubAsmUserParam.Value = Parameter("z_visRefCtrl")

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oSubAsmCompDef.Occurrences
	'set BOM Structure
	If oSubAsmUserParam.Value = True Then
		oOccurrence.BOMStructure = BOMStructureEnum.kDefaultBOMStructure	
	Else
		oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If
Next

InventorVb.DocumentUpdate()

 

Cheers,
Q Visser

Current Software:
Inventor Professional 2024.2 & Vault Professional 2024.2
0 Likes
Message 4 of 5

leopoldo_valenciaJVJ9R
Explorer
Explorer

Thank you for your help! It is good to have you guys answering so fast. I had t use a different approach because I needed to release the document,, but I will try this option also. 

0 Likes
Message 5 of 5

leopoldo_valenciaJVJ9R
Explorer
Explorer

Thank you for your quick response Michael. It helps me better understand how ilogic works.

0 Likes