Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotation Matrix between CSYS objects

Status
Not open for further replies.

jbhunter

Aerospace
Feb 10, 2011
2
I would like to be able to identify a 4x4 matrix for rotation/tranlation of a CSYS object to another CSYS object. Is this possible with any NX features? Will I need to do some NXOpen coding for this?
 
Replies continue below

Recommended for you

You want to move an object from a reference csys to a new csys? If so, you can do this in the "move object" command.

If you have a different end goal in mind, we'll need more info...

www.nxjournaling.com
 
so basically do you want to know the direction of the three axis of the object CSYS?
 
I don't want to move anything in NX, but I would like to find a method to get a 4x4 matrix from one CSYS to another CSYS. I am looking for something to display the matrix to the information window so I can copy and paste to another application.
 
As an example, run the following code on this part file. You can move the csys objects around as desired before running the code; blue is the start csys, green is the destination csys (if you forget, you can turn on the object names in Preferences -> Visualization -> names/borders -> show object names = work view). The line that computes the transformation matrix is highlighted, the rest of the code is just setup and output.

Code:
'run this journal on the supplied "transform_matrix.prt" (NX 8)
'running it on other parts will result in an error, the journal looks for specific objects in the file

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim myStartObject As CoordinateSystem

        For Each tempCsys As CoordinateSystem In workPart.CoordinateSystems
            If tempCsys.Name = "CSYS_START" Then
                myStartObject = tempCsys
            End If
        Next

        Dim startPoint As Point3d = myStartObject.Origin
        Dim startOrientation As NXMatrix = myStartObject.Orientation

        lw.WriteLine("start point")
        lw.WriteLine(startPoint.ToString)
        lw.WriteLine("starting orientation")
        lw.WriteLine(startOrientation.Element.Xx & ", " & startOrientation.Element.Xy & ", " & startOrientation.Element.Xz)
        lw.WriteLine(startOrientation.Element.Yx & ", " & startOrientation.Element.Yy & ", " & startOrientation.Element.Yz)
        lw.WriteLine(startOrientation.Element.Zx & ", " & startOrientation.Element.Zy & ", " & startOrientation.Element.Zz)
        lw.WriteLine("")

        Dim myEndObject As CoordinateSystem

        For Each tempCsys As CoordinateSystem In workPart.CoordinateSystems
            If tempCsys.Name = "CSYS_END" Then
                myEndObject = tempCsys
            End If
        Next

        Dim endPoint As Point3d = myEndObject.Origin
        Dim endOrientation As NXMatrix = myEndObject.Orientation

        lw.WriteLine("end point")
        lw.WriteLine(endPoint.ToString)
        lw.WriteLine("ending orientation")
        lw.WriteLine(endOrientation.Element.Xx & ", " & endOrientation.Element.Xy & ", " & endOrientation.Element.Xz)
        lw.WriteLine(endOrientation.Element.Yx & ", " & endOrientation.Element.Yy & ", " & endOrientation.Element.Yz)
        lw.WriteLine(endOrientation.Element.Zx & ", " & endOrientation.Element.Zy & ", " & endOrientation.Element.Zz)
        lw.WriteLine("")


        Dim fromOrigin() As Double = {startPoint.X, startPoint.Y, startPoint.Z}
        Dim fromXAxis() As Double = {startOrientation.Element.Xx, startOrientation.Element.Xy, startOrientation.Element.Xz}
        Dim fromYAxis() As Double = {startOrientation.Element.Yx, startOrientation.Element.Yy, startOrientation.Element.Yz}

        Dim toOrigin() As Double = {endPoint.X, endPoint.Y, endPoint.Z}
        Dim toXAxis() As Double = {endOrientation.Element.Xx, endOrientation.Element.Xy, endOrientation.Element.Xz}
        Dim toYAxis() As Double = {endOrientation.Element.Yx, endOrientation.Element.Yy, endOrientation.Element.Yz}

        Dim mtx4Transform(15) As Double

[highlight #FCE94F]        theUfSession.Mtx4.CsysToCsys(fromOrigin, fromXAxis, fromYAxis, toOrigin, toXAxis, toYAxis, mtx4Transform)[/highlight]

        lw.WriteLine("transform matrix")
        lw.WriteLine(mtx4Transform(0) & ", " & mtx4Transform(1) & ", " & mtx4Transform(2) & ", " & mtx4Transform(3))
        lw.WriteLine(mtx4Transform(4) & ", " & mtx4Transform(5) & ", " & mtx4Transform(6) & ", " & mtx4Transform(7))
        lw.WriteLine(mtx4Transform(8) & ", " & mtx4Transform(9) & ", " & mtx4Transform(10) & ", " & mtx4Transform(11))
        lw.WriteLine(mtx4Transform(12) & ", " & mtx4Transform(13) & ", " & mtx4Transform(14) & ", " & mtx4Transform(15))


    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor