09-21-2023
03:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-21-2023
03:14 AM
This rule can be run on both PartDocument and AssemblyDocument, it searches all SheetMetal and adds size properties to it. I hope this is what you wanted?
Sub main
Dim oDoc As Document = ThisDoc.Document
oUOfM = oDoc.UnitsOfMeasure
If TypeOf oDoc Is PartDocument Then
Call GetBoxForSheetNetal(oDoc)
Else If TypeOf oDoc Is AssemblyDocument Then
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
If oAsmDoc.AllReferencedDocuments.Count = 0 Then Exit Sub
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
If Not TypeOf oRefDoc Is PartDocument Or
oOccs.AllReferencedOccurrences(oRefDoc).Count = 0 Then Continue For
If CheckPartOnSheet(oRefDoc) Then Continue For
Call GetBoxForSheetNetal(oRefDoc)
Next
End If
End Sub
Dim oUOfM As UnitsOfMeasure
Private Function CheckPartOnSheet(ByVal oPDoc As PartDocument) As Boolean
If Not oPDoc.IsModifiable Or
oPDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Return True
Return False
End Function
Private Sub GetBoxForSheetNetal(ByVal oPDoc As PartDocument)
Dim oCustom As PropertySet = oPDoc.PropertySets("Inventor User Defined Properties")
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
If oBodies.Count = 0 Then Return
Dim oBox As OrientedBox = oBodies(1).OrientedMinimumRangeBox
Dim oTotlL, oTotlW, oTotlH As Inventor.Property
Dim lengths(3) As Double
Dim dSize As New List(Of Double)
dSize.AddRange({oBox.DirectionOne.Length, oBox.DirectionTwo.Length, oBox.DirectionThree.Length })
dSize.Sort()
lengths(0) = Round(oUOfM.ConvertUnits(dSize(2), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
lengths(1) = Round(oUOfM.ConvertUnits(dSize(1), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
lengths(2) = Round(oUOfM.ConvertUnits(dSize(0), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
Try : oCustom("total length").Value = lengths(0)
Catch : oCustom.Add(lengths(0), "total length") : End Try
Try : oCustom("total width").Value = lengths(1)
Catch : oCustom.Add(lengths(1), "total width") : End Try
Try : oCustom("total height").Value = lengths(2)
Catch : oCustom.Add(lengths(2), "total height") : End Try
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.