Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How to obtain u, v, w information from an axis 1

Status
Not open for further replies.

PSI-CAD

Computer
Feb 13, 2009
997
Hi,

How to obtain u, v, w information from all axis in a part with NX12

maybe with an nxopen application

Thanks in advance


Regards
Didier Psaltopoulos
 
Replies continue below

Recommended for you

Is this in regards to CAM or CAD?
Can you provide more information (perhaps an example) of what you are looking for?

I know what U and V are with regards to surfacing; but I've never heard of U, V, and W being used for an axis. Perhaps it would be similar to the i,j,k direction for a vector?

www.nxjournaling.com
 
Do you have a datum axis?
If so, the information -> object command will report the base point and direction (normalized vector) of the axis w.r.t. the absolute csys and the current WCS.

www.nxjournaling.com
 
Thanks a lot Cowski

In fact I was looking in analyse or mesure because I would like to have those informations in Excel. Is it possible or do we need an NXopen application ?
Anyway, It's better than nothing

Regards
Didier Psaltopoulos
 
Some NX automation (a journal or application) could certainly export that info to Excel or copy it to the clipboard so you can paste it easily wherever you need it.

www.nxjournaling.com
 
I have a journal that lets you select points and copies the coordinates to the clipboard so you can paste them into another application as needed. Below is a quick modification of that journal; this one lets you select a datum axis and copies the direction (w.r.t. absolute) to the clipboard. Hopefully it is helpful or can at least serve as a starting point for your own code.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF

Module vector_dir_to_clipboard

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


    Sub Main()

        lw.Open()

        Dim myDatumAxis As DatumAxis
        If SelectDatumAxis("select datum axis", myDatumAxis) = Selection.Response.Cancel Then
            Return
        End If

        Dim ptDir As New Point3d(myDatumAxis.Direction.X, myDatumAxis.Direction.Y, myDatumAxis.Direction.Z)
        ptDir.X += theSession.Parts.Work.WCS.Origin.X
        ptDir.Y += theSession.Parts.Work.WCS.Origin.Y
        ptDir.Z += theSession.Parts.Work.WCS.Origin.Z

        Dim newPt As Point3d
        newPt = Abs2WCS(ptDir)

        'lw.WriteLine("absolute dir:")
        'lw.WriteLine(myDatumAxis.Direction.ToString)
        'lw.WriteLine("")

        'lw.WriteLine("WCS dir:")
        'lw.WriteLine(newPt.ToString)

        Clipboard.SetText(myDatumAxis.Direction.ToString)

        lw.Close()
    End Sub

    Function WCS2Abs(ByVal inPt As Point3d) As Point3d
        Dim pt1(2), pt2(2) As Double

        pt1(0) = inPt.X
        pt1(1) = inPt.Y
        pt1(2) = inPt.Z

        theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt1, UFConstants.UF_CSYS_ROOT_COORDS, pt2)

        WCS2Abs.X = pt2(0)
        WCS2Abs.Y = pt2(1)
        WCS2Abs.Z = pt2(2)

    End Function

    Function Abs2WCS(ByVal inPt As Point3d) As Point3d
        Dim pt1(2), pt2(2) As Double

        pt1(0) = inPt.X
        pt1(1) = inPt.Y
        pt1(2) = inPt.Z

        theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)

        Abs2WCS.X = pt2(0)
        Abs2WCS.Y = pt2(1)
        Abs2WCS.Z = pt2(2)

    End Function

    Function SelectDatumAxis(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a datum axis"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_datum_axis_type
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, 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

    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
 
Thanks a lot Cowski,

Just on issue: I need to run the programm with a component work part in an assembly

And I tried to modify to analyse all datum axis without any selection but not success

What the syntax to get i, j, k information

code said:
For Each feat In theSession.Parts.Work.Features
If feat.GetType.ToString = "NXOpen.Features.DatumAxisFeature" Then
lw.WriteLine(feat.GetType.ToString)
lw.WriteLine("i=" & feat.direction.x)
lw.WriteLine("j=" & feat.direction.y)
lw.WriteLine("k=" & feat.direction.z)
End If
Next


Thanks in advance

Regards
Didier Psaltopoulos
 
The code below should allow you to select a datum axis from a component of the displayed assembly. Also, the X, Y, and Z values will each be on a separate line when pasting the values to a text file.

If you have a reference to a datum axis feature, you'll need to get the actual datum axis object from it; the datum axis feature has a .DatumAxis property that will return the datum axis object.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF

Module vector_dir_to_clipboard

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


    Sub Main()

        lw.Open()

        Dim myDatumAxis As DatumAxis
        If SelectDatumAxis("select datum axis", myDatumAxis) = Selection.Response.Cancel Then
            Return
        End If

        Dim ptDir As New Point3d(myDatumAxis.Direction.X, myDatumAxis.Direction.Y, myDatumAxis.Direction.Z)
        ptDir.X += theSession.Parts.Display.WCS.Origin.X
        ptDir.Y += theSession.Parts.Display.WCS.Origin.Y
        ptDir.Z += theSession.Parts.Display.WCS.Origin.Z

        Dim newPt As Point3d
        newPt = Abs2WCS(ptDir)

        'lw.WriteLine("absolute dir:")
        'lw.WriteLine(myDatumAxis.Direction.ToString)
        'lw.WriteLine("")

        'lw.WriteLine("WCS dir:")
        'lw.WriteLine(newPt.ToString)

        'Clipboard.SetText(myDatumAxis.Direction.ToString)

        Dim myStringBuilder As New Text.StringBuilder
        myStringBuilder.AppendLine(myDatumAxis.Direction.X.ToString)
        myStringBuilder.AppendLine(myDatumAxis.Direction.Y.ToString)
        myStringBuilder.AppendLine(myDatumAxis.Direction.Z.ToString)
        'myStringBuilder.AppendLine()


        Clipboard.SetText(myStringBuilder.ToString)


        lw.Close()
    End Sub

    Function WCS2Abs(ByVal inPt As Point3d) As Point3d
        Dim pt1(2), pt2(2) As Double

        pt1(0) = inPt.X
        pt1(1) = inPt.Y
        pt1(2) = inPt.Z

        theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt1, UFConstants.UF_CSYS_ROOT_COORDS, pt2)

        WCS2Abs.X = pt2(0)
        WCS2Abs.Y = pt2(1)
        WCS2Abs.Z = pt2(2)

    End Function

    Function Abs2WCS(ByVal inPt As Point3d) As Point3d
        Dim pt1(2), pt2(2) As Double

        pt1(0) = inPt.X
        pt1(1) = inPt.Y
        pt1(2) = inPt.Z

        theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)

        Abs2WCS.X = pt2(0)
        Abs2WCS.Y = pt2(1)
        Abs2WCS.Z = pt2(2)

    End Function

    Function SelectDatumAxis(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a datum axis"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_datum_axis_type
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, 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

    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
 
Hi Cowski

Ok for the selection in work part from an assembly.

Could just explain me how to get the datum axis object from datum axis feature ?

Thanks in advance

Regards
Didier Psaltopoulos
 
The datum axis feature object has a .DatumAxis property that will return the actual datum axis object. Where my code looks like this:
Code:
myStringBuilder.AppendLine(myDatumAxis.Direction.X.ToString)

Yours would look something like:
Code:
myStringBuilder.AppendLine(myDatumAxisFeature.DatumAxis.Direction.X.ToString)

Substitute your variable name in place of "myDatumAxisFeature".

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

Part and Inventory Search

Sponsor