The code creates 3 user parameters dLength(MAX), dWidth(MID), dHeight(MIN) (lines 60-65) with the dimensions of the entered box. I hope this is what you needed.
Public Sub Main()
oAppInv = ThisApplication
Dim oDoc As Document = oAppInv.ActiveDocument
Dim oTM As TransactionManager = oAppInv.TransactionManager
Dim oDocs As Documents = oAppInv.Documents
Dim oVisDocs As DocumentsEnumerator = oDocs.VisibleDocuments
Dim newTM As Transaction
If TypeOf oDoc Is PartDocument Then
newTM = oTM.StartTransaction(oDoc, "ChangePositionCamera")
Call PackagingComponent(oDoc)
newTM.End()
oAppInv.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute()
Else If TypeOf oDoc Is AssemblyDocument Then
Dim oADoc As AssemblyDocument = oDoc
newTM = oTM.StartTransaction(oADoc, "ChangePositionCamera")
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
If Not TypeOf oRefDoc Is PartDocument Or _
Not oRefDoc.IsModifiable Then Continue For
Dim oPartDoc As PartDocument = oRefDoc
Dim oPartDef As ComponentDefinition = oPartDoc.ComponentDefinition
If oPartDef.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Or _
oPartDoc.DocumentInterests.HasInterest("{C6107C9D-C53F-4323-8768-F65F857F9F5A}") Or _
oPartDoc.DocumentInterests.HasInterest("{4D39D5F1-0985-4783-AA5A-FC16C288418C}") Or _
oPartDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") Or _
oPartDoc.DocumentInterests.HasInterest("{BB8FE430-83BF-418D-8DF9-9B323D3DB9B9}") Then Continue For
Dim bVisible As Boolean
For Each oVisDoc As Document In oVisDocs
If oVisDoc Is oPartDoc Then bVisible = True
Next
If bVisible Then
oPartDoc.Activate()
Call PackagingComponent(oPartDoc)
oPartDoc.Save()
Else
Dim oVisDoc As Document = oDocs.Open(oPartDoc.FullDocumentName, True)
Call PackagingComponent(oVisDoc)
oVisDoc.Save()
oVisDoc.Close()
End If
If Not oADoc.IsOpenExpress Then oADoc.Activate()
Next
newTM.End()
End If
End Sub
Dim oAppInv As Inventor.Application
Dim dLengths(2) As Double
Private Sub PackagingComponent(ByVal oPDoc As PartDocument)
Dim oTG As TransientGeometry = oAppInv.TransientGeometry
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim minBox As OrientedBox = oPDef.SurfaceBodies.Item(1).OrientedMinimumRangeBox
Dim oUofM As UnitsOfMeasure = oPDoc.UnitsOfMeasure
Dim kUnits As UnitsTypeEnum = oUofM.LengthUnits
dLengths(0) = minBox.DirectionOne.Length
dLengths(1) = minBox.DirectionTwo.Length
dLengths(2) = minBox.DirectionThree.Length
Dim oLength, oHeight, oWidth As UserParameter
Dim oUsParams As UserParameters = oPDef.Parameters.UserParameters
Try : oUsParams("dLength").Value = dLengths.Max
Catch : oUsParams.AddByValue("dLength", dLengths.Max, kUnits) : End Try
Try : oUsParams("dWidth").Value = dLengths.Sum() -dLengths.Max - dLengths.Min
Catch : oUsParams.AddByValue("dWidth", dLengths.Sum() -dLengths.Max - dLengths.Min, kUnits) : End Try
Try : oUsParams("dHeight").Value = dLengths.Min
Catch : oUsParams.AddByValue("dHeight", dLengths.Min, kUnits) : End Try
Dim oVectorY As Vector = GetVectorY(minBox)
If oVectorY Is Nothing Then Exit Sub
Dim oVectorZ As Vector = GetVectorZ(minBox)
If oVectorZ Is Nothing Then Exit Sub
Dim oMaxPlane As Plane = oTG.CreatePlane(minBox.CornerPoint, oVectorZ)
Call ChangeViewCam(oPDoc.Views.Item(1).Camera, oMaxPlane, oVectorY)
End Sub
Private Function ChangeViewCam(ByVal oCam As Camera, ByVal oPlane As Plane, ByVal oVector As Vector)
Dim oPoint As Point = oCam.Target.Copy
Call oPoint.TranslateBy(oPlane.Normal.AsVector())
oCam.Eye = oPoint
oCam.UpVector = oVector.AsUnitVector()
Call oCam.ApplyWithoutTransition
Call oCam.Parent.SetCurrentAsFront
End Function
Private Function GetVectorY(ByVal minBox As OrientedBox) As Vector
Dim dMid As Double = dLengths.Sum() -dLengths.Max - dLengths.Min
Select Case Round(dMid, 3)
Case Round(minBox.DirectionOne.Length, 3) : Return minBox.DirectionOne
Case Round(minBox.DirectionTwo.Length, 3) : Return minBox.DirectionTwo
Case Round(minBox.DirectionThree.Length, 3) : Return minBox.DirectionThree
End Select
Return Nothing
End Function
Private Function GetVectorZ(ByVal minBox As OrientedBox) As Vector
Select Case dLengths.Min
Case minBox.DirectionOne.Length : Return minBox.DirectionOne
Case minBox.DirectionTwo.Length : Return minBox.DirectionTwo
Case minBox.DirectionThree.Length : Return minBox.DirectionThree
End Select
Return Nothing
End Function