Here is the code we use for sheet metal. It doesnt address the orientation issue, but it works for general purposes. you would have to edit the code to work for your purposes, but all of the functionality should be there.
oDoc = ThisDoc.Document
'Get active document unit of measure
Dim uom As UnitsOfMeasure = oDoc.UnitsOfMeasure
'Converts length unit to a string
Dim Units As String = uom.GetStringFromType(uom.LengthUnits)
Dim oParameter As Parameter
Dim oFormat As CustomPropertyFormat
For Each oParameter In oDoc.ComponentDefinition.Parameters.UserParameters
If Units = "inch" Then
If oParameter.ExposedAsProperty Then
oFormat = oParameter.CustomPropertyFormat
oFormat.Units = Units
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
End If
Else
If oParameter.ExposedAsProperty Then
oFormat = oParameter.CustomPropertyFormat
oFormat.Units = Units
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
End If
End If
Next
'Checks To see If the active document Is a standard part
If oDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
'Go To the FlatPattern
Dim oSMCD As SheetMetalComponentDefinition
oSMCD = oDoc.ComponentDefinition
'Look For Flatpattern
If Not oSMCD.HasFlatPattern Then
'Create Flatpattern If the part doesn't have one
oSMCD.Unfold()
oDoc.Update2(True)
oSMCD.FlatPattern.ExitEdit()
End If
'create the component definition of Flatpattern
Dim oFPCD As ComponentDefinition = oSMCD.FlatPattern
'Get the min and max point of the Flatpattern
Dim minPoint As Point = oFPCD.SurfaceBodies.Item(1).RangeBox.MinPoint
Dim maxPoint As Point = oFPCD.SurfaceBodies.Item(1).RangeBox.MaxPoint
'X, Y & Z values are maxPoint - minPoint'Since FlatPattern always returns "cm", we also have to do some conversion to match the document's unit of measure
X = uom.ConvertUnits ((maxPoint.X - minPoint.X), "cm", uom.LengthUnits)
Dim Y As Double = uom.ConvertUnits ((maxPoint.Y - minPoint.Y), "cm", uom.LengthUnits)
Dim Z As Double = uom.ConvertUnits ((maxPoint.Z - minPoint.Z), "cm", uom.LengthUnits)
Dim LengthString As String = MaxOfMany (X,Y,Z)
Dim WidthString As String = X + Y + Z - MaxOfMany (X,Y,Z) - MinOfMany(X,Y,Z)
Dim ThicknessString As String = MinOfMany(X, Y, Z)
RoundThick = Round(CDblAny(ThicknessString), 4)-0.001
RoundWidth = Round(CDblAny(WidthString), 4)-0.001
RoundLength = Round(CDblAny(LengthString), 4)-0.001
'MsgBox(RoundThick)
'MsgBox(RoundWidth)
'MsgBox(RoundLength)
If Units = "inch"
If Parameter("MATL_SHAPE") = "SHEET"
Parameter("EX_TH") = RoundThick.ToString
Parameter("EX_W") = RoundToFraction(RoundWidth, 1/16, RoundingMethod.RoundUp)
Parameter("EX_L") = RoundToFraction(RoundLength, 1/16, RoundingMethod.RoundUp)
Else
Parameter("EX_TH") = RoundToFraction(RoundThick, 1/16, RoundingMethod.RoundUp)
Parameter("EX_W") = RoundToFraction(RoundWidth, 1/16, RoundingMethod.RoundUp)
Parameter("EX_L") = RoundToFraction(RoundLength, 1/16, RoundingMethod.RoundUp)
End If
Else
Parameter("EX_TH") = Round(RoundThick, 1)
Parameter("EX_W") = Round(RoundWidth, 1)
Parameter("EX_L") = Round(RoundLength, 1)
End If
End If
I tried to delete some useless lines from our code (we would convert parts to sheetmetal and back to get the size of them this way as well.
Hope this helps!