Message 1 of 3
Run Rule for all Subbassebly Files in Inventor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am trying to make a BoundingBox Rule for all subassembly files. It takes extentions and places them in order of Length, Width and Thickness. But I want to run this rule for all subassembly files (Assemblies and Parts). I added rules for that, but so far, they still only work for current Assembly or part. Can you help me make this rule work?
The main rule starts at "Sub BoundingBox". I tried messing up later with different rules, but so far no success.
Maybe the code should open part and run the BoundingBox rule from within to work? and then close it and repeat for other parts?
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
Dim parentDoc As AssemblyDocument = ThisApplication.ActiveDocument
'Do anything unique to main assembly
Call AssemblyRunner(parentDoc)
End Sub
Sub AssemblyRunner(aDoc As AssemblyDocument)
'Do things to the assembly file if any
'MessageBox.Show(aDoc.DisplayName, "Assembly:")
'Start Looping
For Each oOcc As ComponentOccurrence In aDoc.ComponentDefinition.Occurrences
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject
Call AssemblyRunner(oOcc.Definition.Document)
Call BoundingBox
Else If oOcc.DefinitionDocumentType = kPartDocumentObject
Call PartRunner(oOcc.Definition.Document, aDoc)
End If
Next
End Sub
Sub PartRunner(pDoc As PartDocument, parent As AssemblyDocument)
'Do Part things
'MessageBox.Show(pDoc.DisplayName & vbCrLf & vbCrLf & _
' "Found in Assembly: " & parent.DisplayName, "Part:")
Call BoundingBox
End Sub
Sub BoundingBox
'Get Component bounding box measurements
Model_X=Round(Measure.ExtentsLength) 'X-axis BB length
Model_Y=Round(Measure.ExtentsWidth) 'Y-axis BB length
Model_Z=Round(Measure.ExtentsHeight) 'Z-axis BB length'Add / Update Bounding Box measurements to model's Custom Properties
If Model_X >= Model_Y And Model_Y >= Model_Z Then
iProperties.Value("Custom", "DIM") = Model_X & "x" & Model_Y & "x" & Model_Z
iProperties.Value("Custom", "Ilgis")=Model_X
iProperties.Value("Custom", "Plotis")=Model_Y
iProperties.Value("Custom", "Storis")=Model_Z
ElseIf Model_X >= Model_Z And Model_Z >= Model_Y Then
iProperties.Value("Custom", "DIM") = Model_X & "x" & Model_Z & "x" & Model_Y
iProperties.Value("Custom", "Ilgis")=Model_X
iProperties.Value("Custom", "Plotis")=Model_Z
iProperties.Value("Custom", "Storis")=Model_Y
ElseIf Model_Y >= Model_X And Model_X >= Model_Z Then
iProperties.Value("Custom", "DIM") = Model_Y & "x" & Model_X & "x" & Model_Z
iProperties.Value("Custom", "Ilgis")=Model_Y
iProperties.Value("Custom", "Plotis")=Model_X
iProperties.Value("Custom", "Storis")=Model_Z
ElseIf Model_Y >= Model_Z And Model_Z >= Model_X Then
iProperties.Value("Custom", "DIM") = Model_Y & "x" & Model_Z & "x" & Model_X
iProperties.Value("Custom", "Ilgis")=Model_Y
iProperties.Value("Custom", "Plotis")=Model_Z
iProperties.Value("Custom", "Storis")=Model_X
ElseIf Model_Z >= Model_X And Model_X >= Model_Y Then
iProperties.Value("Custom", "DIM") = Model_Z & "x" & Model_X & "x" & Model_Y
iProperties.Value("Custom", "Ilgis")=Model_Z
iProperties.Value("Custom", "Plotis")=Model_X
iProperties.Value("Custom", "Storis")=Model_Y
ElseIf Model_Z >= Model_Y And Model_Y >= Model_X Then
iProperties.Value("Custom", "DIM") = Model_Z & "x" & Model_Y & "x" & Model_X
iProperties.Value("Custom", "Ilgis")=Model_Z
iProperties.Value("Custom", "Plotis")=Model_Y
iProperties.Value("Custom", "Storis")=Model_X
End If
'ThisDoc.Save
'ThisDoc.Document.Close(True)
End Sub