Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
C_Haines_ENG
257 Views, 4 Replies

Get RangeBox of Part in Assembly, by Assembly Coordinate System

I'm trying to get a rangebox on a part in an assembly, but in the assemblies coordinate system. Does anyone know how to do this?

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oOcc as ComponentOccurance
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick a feature")

xFrameL = oOcc.Definition.RangeBox.MaxPoint.X - oOcc.Definition.RangeBox.MinPoint.X

The code above works great to get the rangebox on the PART coordinate system but I need one for an assembly coordinate system. 

C_Haines_ENG
in reply to: C_Haines_ENG

It would appear that I'm a complete idiot.

 

oOcc.RangeBox.MaxPoint.X

Be careful because it works until the part is not rotated in assembly.

I never could get the oriented range box working, could you post a sample code?

This is a sample, how you can work with OrientedBox of part in assembly context

 

Sub Main()
    Dim asm As AssemblyDocument = ThisDoc.Document
    Dim asmDef As AssemblyComponentDefinition = asm.ComponentDefinition
    Dim partOcc As ComponentOccurrence = asmDef.Occurrences(1)

    Dim partDef As PartComponentDefinition = partOcc.Definition
    Dim orientedBox As OrientedBox = partDef.OrientedMinimumRangeBox

    PrintBoxData(orientedBox, "In part")

    TransformBy(orientedBox, partOcc.Transformation)

    PrintBoxData(orientedBox, "In assembly")

End Sub

Private Sub TransformBy(orientedBox As OrientedBox, matrix As Matrix)
    Dim cornerPoint As Point
    Dim directionOne As Vector
    Dim directionTwo As Vector
    Dim directionThree As Vector
    orientedBox.GetOrientedBoxData(cornerPoint, directionOne, directionTwo, directionThree)

    cornerPoint.TransformBy(matrix)
    directionOne.TransformBy(matrix)
    directionTwo.TransformBy(matrix)
    directionThree.TransformBy(matrix)

    orientedBox.PutOrientedBoxData(cornerPoint, directionOne, directionTwo, directionThree)
End Sub

Private Sub PrintBoxData(orientedBox As OrientedBox, Optional title As String = "")
    Dim stringBuilder As New System.Text.StringBuilder
    stringBuilder.AppendLine(title)
    stringBuilder.AppendLine(String.Format("CornerPoint{3}[{0:N2}, {1:N2}, {2:N2}]", orientedBox.CornerPoint.X, orientedBox.CornerPoint.Y, orientedBox.CornerPoint.Z, vbTab))
    stringBuilder.AppendLine(String.Format("DirectionOne{3}[{0:N2}, {1:N2}, {2:N2}]", orientedBox.DirectionOne.X, orientedBox.DirectionOne.Y, orientedBox.DirectionOne.Z, vbTab))
    stringBuilder.AppendLine(String.Format("DirectionTwo{3}[{0:N2}, {1:N2}, {2:N2}]", orientedBox.DirectionTwo.X, orientedBox.DirectionTwo.Y, orientedBox.DirectionTwo.Z, vbTab))
    stringBuilder.AppendLine(String.Format("DirectionThree{3}[{0:N2}, {1:N2}, {2:N2}]", orientedBox.DirectionThree.X, orientedBox.DirectionThree.Y, orientedBox.DirectionThree.Z, vbTab))
    Logger.Debug(stringBuilder.ToString())
End Sub