Move body from selected CSYS to Absolute CSYS

I am new to journal developing and i need some help. The concept is that the user selects a body and a CSYS and the journal computes the body dimensions(X, Y, Z) and the Xmin, Xmax, Ymin, Ymax, Zmin, Zmax values from the selected CSYS. First i have to move the body from CSYS to ABS and then make the calculations to extract the values, but i cant find the command or the syntax...

i have made this so far (with a lot of help)... but i have errors.. Can somebody help me?

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

lw.Open()
Dim workPart As Part = theSession.Parts.Work

' === Select solid body ===
Dim solid1 As Body
If SelectSolid("Select solid", solid1) = Selection.Response.Cancel Then
Return
End If

' === Select CSYS ===
Dim myCsys As CoordinateSystem = Nothing
If SelectCSYS("Select a Cartesian CSYS feature", myCsys) = Selection.Response.Cancel Then
Return
End If

' === Get bounding box in ABS coordinates (WCS) ===
Dim bbox(5) As Double
theUfSession.Modl.AskBoundingBox(solid1.Tag, bbox)

' Generate all 8 corners of the bounding box
Dim corners As New List(Of Double())
corners.Add(New Double() {bbox(0), bbox(1), bbox(2)})
corners.Add(New Double() {bbox(0), bbox(1), bbox(5)})
corners.Add(New Double() {bbox(0), bbox(4), bbox(2)})
corners.Add(New Double() {bbox(0), bbox(4), bbox(5)})
corners.Add(New Double() {bbox(3), bbox(1), bbox(2)})
corners.Add(New Double() {bbox(3), bbox(1), bbox(5)})
corners.Add(New Double() {bbox(3), bbox(4), bbox(2)})
corners.Add(New Double() {bbox(3), bbox(4), bbox(5)})

' === Get CSYS origin and orientation ===
Dim csysOrigin As Point3d = myCsys.Origin
Dim csysNXMatrix As NXMatrix = myCsys.Orientation
Dim m(2, 2) As Double
csysNXMatrix.AskMatrix(m)

' Extract X and Y axes for UF transformation
Dim xAxis(2) As Double
Dim yAxis(2) As Double
xAxis(0) = m(0, 0) : xAxis(1) = m(1, 0) : xAxis(2) = m(2, 0)
yAxis(0) = m(0, 1) : yAxis(1) = m(1, 1) : yAxis(2) = m(2, 1)

' Compute 4x4 transformation matrix from WCS to CSYS
Dim mtx4(15) As Double
theUfSession.Mtx4.CsysToCsys({0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
{csysOrigin.X, csysOrigin.Y, csysOrigin.Z}, xAxis, yAxis, mtx4)

' Initialize min/max
Dim xMin As Double = Double.MaxValue, xMax As Double = Double.MinValue
Dim yMin As Double = Double.MaxValue, yMax As Double = Double.MinValue
Dim zMin As Double = Double.MaxValue, zMax As Double = Double.MinValue

' Transform each corner to CSYS
For Each pt As Double() In corners
Dim x As Double = pt(0)
Dim y As Double = pt(1)
Dim z As Double = pt(2)

Dim newX As Double = mtx4(0) * x + mtx4(1) * y + mtx4(2) * z + mtx4(3)
Dim newY As Double = mtx4(4) * x + mtx4(5) * y + mtx4(6) * z + mtx4(7)
Dim newZ As Double = mtx4(8) * x + mtx4(9) * y + mtx4(10) * z + mtx4(11)

xMin = Math.Min(xMin, newX) : xMax = Math.Max(xMax, newX)
yMin = Math.Min(yMin, newY) : yMax = Math.Max(yMax, newY)
zMin = Math.Min(zMin, newZ) : zMax = Math.Max(zMax, newZ)
Next

' === Output results to Listing Window ===
lw.WriteLine("Bounding Box relative to selected CSYS:")
lw.WriteLine(String.Format("Xmin: {0:F3}, Xmax: {1:F3}, SizeX: {2:F3}", xMin, xMax, xMax - xMin))
lw.WriteLine(String.Format("Ymin: {0:F3}, Ymax: {1:F3}, SizeY: {2:F3}", yMin, yMax, yMax - yMin))
lw.WriteLine(String.Format("Zmin: {0:F3}, Zmax: {1:F3}, SizeZ: {2:F3}", zMin, zMax, zMax - zMin))

End Sub

' === Selection Helpers ===
Function SelectSolid(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, "Select Body", _
Selection.SelectionScope.WorkPart, Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, selectionMask_array, selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Function SelectCSYS(ByVal prompt As String, ByRef csysObj As CoordinateSystem) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_coordinate_system_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, prompt, _
Selection.SelectionScope.WorkPart, Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, selectionMask_array, csysObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.AtTermination
End Function

End Module

I'd like to introduce you to the .AskBoundingBoxAligned function, which will calculate the bounding extents based on the given csys. The example below uses a null tag for the csys tag, which makes it use the WCS. Pass in the tag to your desired csys in place of the null tag.

[code]

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim bbox(5) As Double
Dim dblAcc_Value(11) As Double
Dim dblMass_Props(46) As Double
Dim dblStats(12) As Double
Dim strOutput As String
Dim boundX As Double
Dim boundY As Double
Dim boundZ As Double
Dim minCorner(2) As Double
Dim boxDirections(2, 2) As Double
Dim boxDistances(2) As Double

Dim solid1 As Body = SelectSolid()
If solid1 Is Nothing Then
Return
End If

Dim tagList(0) As NXOpen.Tag
tagList(0) = solid1.Tag

'get volume
dblAcc_Value(0) = 0.999
'AskMassProps3d(in_Tags(),in_num_objs,in_type,in_units,in_density,in_accuracy,in_accuracy_values(),out_mass_props(),out_stats())
ufs.Modl.AskMassProps3d(tagList, 1, 1, 1, 0.0375, 1, dblAcc_Value, dblMass_Props, dblStats)
strOutput = "Surface Area: " & dblMass_Props(0) & vbcrlf
strOutput = strOutput & "Volume: " & dblMass_Props(1) & vbcrlf
strOutput = strOutput & "Mass: " & dblMass_Props(2) & vbcrlf
strOutput = strOutput & "COG: " & dblMass_Props(3) & ", " & dblMass_Props(4) & ", " & dblMass_Props(5) & vbcrlf
strOutput = strOutput & "Density: " & dblMass_Props(46)
MsgBox(strOutput, vbOKOnly)

'get solid body bounding box extents aligned to absolute csys
'ufs.Modl.AskBoundingBox(solid1.Tag, bbox)
'get solid body bounding box extents aligned to work csys (pass null tag to use work csys)
ufs.Modl.AskBoundingBoxAligned(solid1.Tag, Tag.Null, expand:=False, min_corner:=minCorner, directions:=boxDirections, distances:=boxDistances)
' msgbox ("min X: " & bbox(0) & " max X: " & bbox(3) & vbcrlf _
' & "min Y: " & bbox(1) & " max Y: " & bbox(4) & vbcrlf _
' & "min Z: " & bbox(2) & " max Z: " & bbox(5) & vbcrlf & vbcrlf & _
' "X dim: " & bbox(3) - bbox(0) & vbcrlf & _
' "Y dim: " & bbox(4) - bbox(1) & vbcrlf & _
' "Z dim: " & bbox(5) - bbox(2), vbokonly)

'boundX = bbox(3) - bbox(0)
'boundY = bbox(4) - bbox(1)
'boundZ = bbox(5) - bbox(2)

boundX = boxDistances(0)
boundY = boxDistances(1)
boundZ = boxDistances(2)

MsgBox("X: " & boundX & vbCrLf & _
"Y: " & boundY & vbCrLf & _
"Z: " & boundZ)

'convert units to inches, based on the part units of the work part
If workPart.PartUnits = Part.Units.Millimeters Then
'convert distances to inches
boundX = boundX / 25.4
boundY = boundY / 25.4
boundZ = boundZ / 25.4
End If

'workPart.SetAttribute("Bounding_X", boundX.ToString("0.000"))
'workPart.SetAttribute("Bounding_Y", boundY.ToString("0.000"))
'workPart.SetAttribute("Bounding_Z", boundZ.ToString("0.000"))

End Sub

'**********************************************************
Public Function SelectSolid() As Body

Dim ui As UI = ui.GetUI
Dim message As String = "Select solid body"
Dim title As String = "Selection"

Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = True
Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(1) As Selection.MaskTriple
Dim selectedObject As NXObject = Nothing
Dim cursor As Point3d

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

ui.SelectionManager.SelectObject(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObject, cursor)

Dim solid As Body = CType(selectedObject, Body)

If solid Is Nothing Then
Return Nothing
End If

Return solid

End Function
'*******************

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module
[/code]

Thanks for the tip!
Everything work just fine now!

sfot