@joris.engelbertink
And this version takes it one step further, filtering the resulting vector lengths from smallest to largest, so you may more accurately name each dimension, in case that is important or applies to your application.
In many cases the smallest dimension is always going to be the Thickness of the material (especially when working with "Plates"). And often the longest of the three dimensions is the Length (or material cut-length). So the remaining dimension can either be labeled as Width, Height, Depth, Gerth, etc.
So here is the same code that takes it that next step further, in case you needed it.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
MsgBox("This rule only works for Part Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oBody As SurfaceBody
If oPDef.SurfaceBodies.Count > 0 Then
oBody = oPDef.SurfaceBodies.Item(1)
Else
MsgBox("This Part has no bodies. Exiting.", , "")
Exit Sub
End If
If Not oBody.IsSolid Then
MsgBox("The body is not Solid. Exiting.", , "")
Exit Sub
End If
Dim oCorner As Point
Dim oV1, oV2, oV3 As Vector
oBody.OrientedMinimumRangeBox.GetOrientedBoxData(oCorner, oV1, oV2, oV3)
Dim oDim1 As Double = oV1.Length / 2.54
Dim oDim2 As Double = oV2.Length / 2.54
Dim oDim3 As Double = oV3.Length / 2.54
Dim oThickness As Double = MinOfMany(oDim1, oDim2, oDim3)
Dim oLength As Double = MaxOfMany(oDim1, oDim2, oDim3)
Dim oWidth As Double
Dim oDims() As Double = {oDim1, oDim2, oDim3}
For Each oDim In oDims
If oDim <> oThickness And oDim <> oLength Then
oWidth = oDim
End If
Next
MsgBox("First Body Size: " & vbCrLf & _
"Thickness = " & oThickness & vbCrLf & _
"Length = " & oLength & vbCrLf & _
"Width = " & oWidth, , "")
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
Wesley Crihfield

(Not an Autodesk Employee)