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

Get RangeBox of Part in Assembly, by Assembly Coordinate System

C_Haines_ENG
Collaborator

Get RangeBox of Part in Assembly, by Assembly Coordinate System

C_Haines_ENG
Collaborator
Collaborator

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. 

0 Likes
Reply
Accepted solutions (1)
258 Views
4 Replies
Replies (4)

C_Haines_ENG
Collaborator
Collaborator
Accepted solution

It would appear that I'm a complete idiot.

 

oOcc.RangeBox.MaxPoint.X
0 Likes

Michael.Navara
Advisor
Advisor

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

0 Likes

C_Haines_ENG
Collaborator
Collaborator

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

0 Likes

Michael.Navara
Advisor
Advisor

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
0 Likes