@chris,
The "Logger.Trace" is a way to write a message in the iLogic Logger. I prefer this over messageboxes for testing as you do not have to clear each messagebox, but it will still give you a look at each step. In order to use it, you need to set log level to trace and have the iLogic Log window open:
Settings in ilogic window
results
Then For changing units you will need to do your own unit conversion for volume as the conversions from UnitsOfMeasure will not work for compound units. I added the conversions to the rule I posted before:
Sub Main
Dim pDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, PartDocument)
If IsNothing(pDoc) Then Logger.Debug("Not Run In Part Document") : Exit Sub
For Each sb As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
If Not sb.IsSolid Then Continue For
Dim sbVolume As Double = sb.Volume(.0001)
' Logger.Trace(String.Format("{0} = {1} cm^3", sb.Name, sbVolume))
sbVolume/=2.54^3 'cm are the database units, so cm^3 to in^3 conversion
Logger.Trace(String.Format("{0} = {1} in^3", sb.Name, sbVolume))
Next
Call AlignedBoxSize(pDoc.ComponentDefinition.PreciseRangeBox)'Box aligned with origin
Call OrientedBoxSize(pDoc.ComponentDefinition.OrientedMinimumRangeBox)'Box allowed to rotate for tightest fit
End Sub
Sub AlignedBoxSize(aRangeBox As Box)
Dim xLength, yLength, zLength As Double
xLength = aRangeBox.MaxPoint.X - aRangeBox.MinPoint.X
yLength = aRangeBox.MaxPoint.Y - aRangeBox.MinPoint.Y
zLength = aRangeBox.MaxPoint.Z - aRangeBox.MinPoint.Z
' Logger.Trace(String.Format("X: {0} cm, Y: {1} cm, Z: {2} cm", xLength, yLength, zLength))
xLength /= 2.54 'cm are the database units, so cm to in conversion
yLength /= 2.54 'cm are the database units, so cm to in conversion
zLength /= 2.54 'cm are the database units, so cm to in conversion
Logger.Trace(String.Format("X: {0} in, Y: {1} in, Z: {2} in", xLength, yLength, zLength))
End Sub
Sub OrientedBoxSize(anOrientedBox As OrientedBox)
Dim SizeOfBox As New List(Of Double)
SizeOfBox.Add(anOrientedBox.DirectionOne.Length)
SizeOfBox.Add(anOrientedBox.DirectionTwo.Length)
SizeOfBox.Add(anOrientedBox.DirectionThree.Length)
SizeOfBox.Sort()
' Logger.Trace(String.Format("Min Length: {0} cm, Mid Length: {1} cm, Max Length: {2} cm",SizeOfBox.Item(0), SizeOfBox.Item(1), SizeOfBox.Item(2)))
SizeOfBox.Item(0) /= 2.54 'cm are the database units, so cm to in conversion
SizeOfBox.Item(1) /= 2.54 'cm are the database units, so cm to in conversion
SizeOfBox.Item(2) /= 2.54 'cm are the database units, so cm to in conversion
Logger.Trace(String.Format("Min Length: {0} in, Mid Length: {1} in, Max Length: {2} in",SizeOfBox.Item(0), SizeOfBox.Item(1), SizeOfBox.Item(2)))
End Sub
Note that you could perform the conversion at the same time as you are setting initial values, but I left both the original and new traces available by separating the operations.