I had to duck just a bit, because that went really close over my head. I've had no experience calling External Rules automatically.
The thing is I actually have two rules - the first is "TOGGLEWORKFEATURES" which essentially hides all the work features in the part.
For Each oWorkPlane In ThisDoc.Document.ComponentDefinition.WorkPlanes
oWorkPlane.Visible = False
Next
For Each oWorkAxis In ThisDoc.Document.ComponentDefinition.WorkAxes
oWorkAxis.Visible = False
Next
For Each oWorkPoint In ThisDoc.Document.ComponentDefinition.WorkPoints
oWorkPoint.Visible = False
Next
Then a second rule, "EXTENTS_MODEL" which gets the bounding box dimensions and assigns those to custom iprops.
iLogicVb.RunRule("TOGGLEWORKFEATURES")
InventorVb.DocumentUpdate()
SPECAdder = 0
Smallest = Measure.ExtentsLength
Middle = 0
Largest = 0
If Measure.ExtentsWidth > Measure.ExtentsLength Then
Middle = Measure.ExtentsWidth
Else
Smallest = Measure.ExtentsWidth
Middle = Measure.ExtentsLength
End If
If Measure.ExtentsHeight > Middle Then
Largest = Measure.ExtentsHeight
Else
If Measure.ExtentsHeight > Smallest Then
Largest = Middle
Middle = Measure.ExtentsHeight
Else
Largest = Middle
Middle = Smallest
Smallest = Measure.ExtentsHeight
End If
End If
Largest = Largest + SPECAdder
'iProperties.Value("Project", "Stock Number") = Round(Largest, 1) & "x" & Round(Middle ,1) & "x" & Round(Smallest , 1) & " "
iProperties.Value("Custom", "LENGTH") = Round(Largest, 3)
iProperties.Value("Custom", "WIDTH") = Round(Middle, 3)
iProperties.Value("Custom", "HEIGHT") = Round(Smallest, 3)
iProperties.Value("Custom", "DIMENSIONS") = CStr(Round(Largest, 2)) + " X " + CStr(Round(Middle, 2)) + " X " + CStr(Round(Smallest, 2))
iProperties.Value("Custom", "LENGTHMM") = iProperties.Value("Custom", "LENGTH") * 25.4
iProperties.Value("Custom", "WIDTHMM") = iProperties.Value("Custom", "WIDTH") * 25.4
iProperties.Value("Custom", "HEIGHTMM") = iProperties.Value("Custom", "HEIGHT") * 25.4
I wouldn't mind calling on an External Rule, but I have no clue as to how to do that. I do know the two rules above would need to be combined so it turned of the work features and then created the bounding box.
But currently, the Rule above is still throwing an error.

Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDoc As Document = oInvApp.ActiveDocument
If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
Dim oPBar As Inventor.ProgressBar = oInvApp.CreateProgressBar(False, oAsmDoc.AllReferencedDocuments.Count, "Copy rules...")
Dim i As Integer = 1
oPBar.Message = "Loading..."
Dim oDocs As Documents = oInvApp.Documents
Dim oPartDoc As Document = oDocs.Open("E:\Dropbox\02.00 XXXX BUSINESS\00.06 XXXX\MP-22.200 TEMPLATES\Standard.ipt", False) 'PartDocument
Dim oSMDoc As Document = oDocs.Open("E:\Dropbox\02.00 XXXX BUSINESS\00.06 XXXX\MP-22.200 TEMPLATES\Sheet Metal.ipt", False) 'SheetMetalDocument
Dim oADoc As Document = oDocs.Open("E:\Dropbox\02.00 XXXX BUSINESS\00.06 XXXX\MP-22.200 TEMPLATES\Standard.iam", False) 'AssemblyDocument
Dim oFrameDoc As Document = oDocs.Open("E:\Dropbox\02.00 XXXX BUSINESS\00.06 XXXX\MP-22.200 TEMPLATES\Standard.ipt", False) 'Frame Generator PartDocument
Dim oTM As Transaction = oInvApp.TransactionManager.StartTransaction(oAsmDoc, "CopyRulesFromTemplates")
Call CopyRules(oADoc, oAsmDoc)
Call CopyEventsPropSet(oADoc, oAsmDoc)
For Each copyTo As Document In oAsmDoc.AllReferencedDocuments
oPBar.Message = "Copy rules in document. Progress " & i & " of " & oAsmDoc.AllReferencedDocuments.Count & "."
If oOccs.AllReferencedOccurrences(copyTo).Count > 0 Then
If copyTo.IsModifiable Then
If copyTo.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject _
AndAlso Not copyTo.DocumentInterests.HasInterest("{BB8FE430-83BF-418D-8DF9-9B323D3DB9B9}") _
AndAlso Not copyTo.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") Then 'AssemblyDocument
Call CopyRules(oADoc, copyTo)
Call CopyEventsPropSet(oADoc, copyTo)
Else If copyTo.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
If copyTo.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'SheetMetalDocument
Call CopyRules(oSMDoc, copyTo)
Call CopyEventsPropSet(oSMDoc, copyTo)
Else
If copyTo.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") Then 'Frame Generator PartDocument
If Not copyTo.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then
Call CopyRules(oFrameDoc, copyTo)
Call CopyEventsPropSet(oFrameDoc, copyTo)
End If
Else 'PartDocument
Call CopyRules(oPartDoc, copyTo)
Call CopyEventsPropSet(oPartDoc, copyTo)
End If
End If
End If
End If
End If
oPBar.UpdateProgress
i += 1
Next
oTM.End()
oPartDoc.Close()
oSMDoc.Close()
oADoc.Close()
oFrameDoc.Close()
oPBar.Close()
End Sub
Sub CopyRules(ByVal CopyFrom As Document, ByRef CopyTo As Document)
iLogicVb.Automation.DeleteAllRules(CopyTo)
For Each oRule As iLogicRule In iLogicVb.Automation.Rules(CopyFrom)
Try : Dim oCopy As iLogicRule = iLogicVb.Automation.AddRule(CopyTo, oRule.Name, oRule.Text)
Catch : End Try
Next
End Sub
Sub CopyEventsPropSet(ByVal CopyFrom As Document, ByRef CopyTo As Document)
Dim oPropSet As Inventor.PropertySet = CopyFrom.PropertySets("{2C540830-0723-455E-A8E2-891722EB4C3E}")
Try : CopyTo.PropertySets("{2C540830-0723-455E-A8E2-891722EB4C3E}").Delete() : Catch : End Try
Dim newPropSet As Inventor.PropertySet = CopyTo.PropertySets.Add("_iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
For Each prop As Inventor.Property In oPropSet
newPropSet.Add(prop.Value, prop.Name, prop.PropId)
Next
End Sub
@WCrihfield @Andrii_Humeniuk