cancel
Showing results for 
Search instead for 
Did you mean: 

Rotation about a axis using NX VBA

Pioneer
Pioneer

Hi

Is there a way to rotate an object about the selected axis using NX VBA?

 

Dim selComp As NXOpen.Assemblies.Component = Nothing
        If SelectComponent(selComp) = Selection.Response.Cancel Then
            Exit Sub
        End If
	
	Dim selDatum As DisplayableObject
        If SelectObject("select datum plane or axis", selDatum) = Selection.Response.Cancel Then
            Return
        End If

Through above code selection of object and Selection of Axis is carried out .Function is also defined.

I am alone strugging with the one below.

 

RotMat3.Xx = 1
        RotMat3.Xy = 0
        RotMat3.Xz = 0
        RotMat3.Yx = 0
        RotMat3.Yy = 1
        RotMat3.Yz = 0
        RotMat3.Zx = 0
        RotMat3.Zy = 0
        RotMat3.Zz = 1


workPart.ComponentAssembly.MoveComponent(selComp, pt3, Rot3)

How do i define the above matrix with respect to Selected Datum Axis?

 

Thanks

6 REPLIES

Re: Rotation about a axis using NX VBA

Hi Dinesh,

 

I don't know much about the programming. But there are some sample examples available on GTAC that might help you to solve your problem.

 

rotate selected component about its own x axis

 

rotate selected component about absolute x axis

 

rotate selected components about absolute y azis

 

Ganesh Kadole, QA Analyst (PLM), SQS
Testing: NX 10 | NX 11 | Teamcenter-NX Integration
Teamcenter 11.2 | TC Vis 11.3 | Active Workspace 3.2

Re: Rotation about a axis using NX VBA

Pioneer
Pioneer

Hi Ganesh

This does not solve my problem. I am looking for a code that will rotate about a body about its own centre axis.

Say i have a cylinder any where in between all three planes. I wanted to rotate the cylinder about centre axis.

All three of GTAC codes rotates the body about either X,Y,Z not about its centre axis.

 

Please suggest 

Re: Rotation about a axis using NX VBA

Siemens Phenom Siemens Phenom
Siemens Phenom

Three options, in increasing order of difficulty ...

 

(1) If you have access to SNAP, you can use Snap.Geom.Transform.CreateRotation to create the transformation. One of the options allows you to input a point and an axis vector, which is what you need. Then you apply this transform to various objects by using their Move or Copy methods. The SNAP Reference Guide have examples.

 

(2) If you don't have SNAP, you can use  NXOpen.UF.UFTrns.CreateRotationMatrix.

 

(3) Or, if you want to build the matrix yourself, you need to look up the math. Search for "Rodrigues formula".

山田
yamada

Re: Rotation about a axis using NX VBA

Pioneer
Pioneer

Hi Yamada

 

Here is an typicaal problem i am working on and same as you said for creating a rotation matrix

I had taken it from GTAC

https://solutions.industrysoftware.automation.siemens.com/view.php?sort=desc&q=rotate+object&dt=nx-a...

 

and the code as below.

 

The problem is that the component i am interested has its X axis same as centre axis.I want the code to rotate it about its centre axis .

But the code doesnt work rather rotates it with neiher global axis nor the component axis.

 

Please clarify

 

Option Strict Off

Imports System
Imports System.Math

Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module rotateSelectedComponentAboutItsOwnXAxis

    Dim theSession As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()

        Dim comp As Assemblies.Component = Nothing
        Dim ac As Assemblies.ComponentAssembly = _
            theSession.Parts.Work.ComponentAssembly()

        Do
            comp = SelectAComponent("Rotate 90 degrees about X")
            If comp IsNot Nothing Then
                theSession.SetUndoMark(Session.MarkVisibility.Visible, _
                    "Rotate Component")

                Dim origin As Point3d
                Dim orientation As Matrix3x3
                comp.GetPosition(origin, orientation)

                Dim Xaxis As Vector3d = New Vector3d(orientation.Xx, _
                    orientation.Xy, orientation.Xz)
                displayConehead(origin, Xaxis)

                Dim comp_mx As Double() = _
                    convertMatrix3x3ToDoubleArray(orientation)
                ufs.Mtx3.OrthoNormalize(comp_mx)
                Dim matrix_id As NXOpen.Tag

                ufs.Csys.CreateMatrix(comp_mx, matrix_id)
                Dim comp_origin As Double() = _
                    convertPoint3dToDoubleArray(origin)
                Dim csys_id(0) As NXOpen.Tag

                ufs.Csys.CreateTempCsys(comp_origin, matrix_id, csys_id(0))
                Dim comp_xaxis As Double() = convertVector3dToDoubleArray(Xaxis)

                Dim rot_mx(11) As Double
                Dim resp As Integer

                ufs.Trns.CreateRotationMatrix(comp_origin, comp_xaxis, 90, _
                   rot_mx, resp)

                ufs.Trns.TransformObjects(rot_mx, csys_id, 1, 1, 0, 2, _
                    Nothing, Nothing, resp)
                ufs.Csys.AskCsysInfo(csys_id(0), matrix_id, comp_origin)
                Dim comp_orientation(8) As Double

                ufs.Csys.AskMatrixValues(matrix_id, comp_orientation)

                ufs.Assem.RepositionInstance( _
                    ufs.Assem.AskInstOfPartOcc(comp.Tag), _
                    comp_origin, comp_orientation)
            End If
        Loop While comp IsNot Nothing

    End Sub

    Function SelectAComponent(ByVal prompt As String) As Assemblies.Component

        Dim ui As UI = GetUI()
        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_component_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
        Dim obj As NXObject = Nothing
        Dim cursor As Point3d = Nothing

        ui.SelectionManager.SelectObject(prompt, "Select a component", _
            Selection.SelectionScope.WorkPart, _
            Selection.SelectionAction.ClearAndEnableSpecific, _
            False, False, mask, obj, cursor)

        Return obj

    End Function

    Sub displayConehead(ByVal origin As Point3d, ByVal direction As Vector3d)

        Dim loc() As Double = {origin.X, origin.Y, origin.Z}
        Dim dir() As Double = {direction.X, direction.Y, direction.Z}

        ufs.Disp.Conehead(UFConstants.UF_DISP_ALL_ACTIVE_VIEWS, loc, dir, 0)

    End Sub

    Function convertPoint3dToDoubleArray(ByVal pt As Point3d) As Double()
        Dim da As Double() = {pt.X, pt.Y, pt.Z}
        Return da
    End Function

    Function convertVector3dToDoubleArray(ByVal pt As Vector3d) As Double()
        Dim da As Double() = {pt.X, pt.Y, pt.Z}
        Return da
    End Function

    Function convertMatrix3x3ToDoubleArray(ByVal mat As Matrix3x3) As Double()

        Dim mtx() As Double = {mat.Xx, mat.Xy, mat.Xz, mat.Yx, mat.Yy, _
            mat.Yz, mat.Zx, mat.Zy, mat.Zz}

        Return mtx

    End Function

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

End Module

Image of the file.PNG

Re: Rotation about a axis using NX VBA

Siemens Phenom Siemens Phenom
Siemens Phenom

Sorry, but I can't help you because I can't make any sense out of the following three sentences:

 

The problem is that the component i am interested has its X axis same as centre axis. I want the code to rotate it about its centre axis . But the code doesnt work rather rotates it with neiher global axis nor the component axis

山田
yamada

Re: Rotation about a axis using NX VBA

Pioneer
Pioneer

Hi Yamada

Thanks for your reply

 

If you could look at the image below , i would like to rotate the cylinder by the axis created.

I want the code to modified as such.

Centre Axis.PNG