Cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Get coordinates of points from Point Set

Creator
Creator

@FrankSwinks1

Thanks for taking a look and upgrading my code! I am anxious to get back to town later this evening and give it a test run. I really appreciate it and will get back to you with results! 

Re: Get coordinates of points from Point Set

Creator
Creator

@FrankSwinks1

Hey Frank, that works great! However, it  pulls the data relative to the absolute coordinate system and I have the spline set relative to the work coordinate system. Is there a way to make the code pull data set relative to the WCS rather than the absolute? I know I can set the WCS or the datum coordinate system to the absolute, but I can't do that and still extract the spline that I need, as it is extracted in reference to the WCS only. Is it possible to set all the parts to the WCS, then set the WCS to the absolute and have the parts move with them? I know you can do that with the datum coordinate, but didnt see that option for the WCS, where the parts would follow. It would be fantastice if I could just get the coordinates of the spline in reference to the WCS though. Thoughts?

 

Re: Get coordinates of points from Point Set

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

The following link has a code snippet that will convert coordinates from absolute to WCS. It assumes you have a global variable named theUFSession which refers to the NX UFSession object.

https://solutions.industrysoftware.automation.siemens.com/view.php?dt=&rows=20&sort=desc&ds=&de=&fil...

Re: Get coordinates of points from Point Set

Creator
Creator

@cowski1
Hey, the website syas page forbiden (access to the requested resource is forbidden) and forces me to login, but then there is no way to direct me to the link you provided after logging in. Any chance you could post the snippet on here?

Re: Get coordinates of points from Point Set

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

There is a journal in this thread that uses the MapPoint function.

Re: Get coordinates of points from Point Set

@RVP

 

Here is the program altered to use wcs point values.

 

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.UF

Module PointDataToFile
    Dim s As Session = Session.GetSession()
    Dim ui As UI = UI.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim wp As Part = s.Parts.Work
    Sub Main()
        'set up code to get the nx session and defines the variables
        ' select point set feature
        Dim feat As Feature = Nothing
        Dim pointSet1 As PointSet = Nothing
        Dim thePoints(-1) As Point
        Dim response1 As Selection.Response = select_feature(feat)
        If feat.GetFeatureName.ToString.Contains("Point Set") Then
            pointSet1 = DirectCast(feat, PointSet)
            thePoints = pointSet1.GetPoints
        Else
            Exit Sub
        End If

        'Open file to write contents.
        Dim objStreamWriter As StreamWriter 'defines method to write to file

        'Specify directory to write file to.
        objStreamWriter = New StreamWriter("C:\temp3\Point_Set.txt") 'creates the file and writes to this directory

        'Write file header.
        Dim Header As String = “XYZ Coordinates of Points Defining Curve”
        objStreamWriter.WriteLine(Header)

        'Define cnt1 (counter) to start at 1.
        Dim cnt1 As Integer = 1

        'Write the xyz header line before the loop starts.
        objStreamWriter.WriteLine(“Point, X, Y, Z”)

        'Loop.
        Dim pt1 As Point3d = New Point3d
        For Each pt As Point In thePoints
            'write contents of header2 and the counter to file
            ' objStreamWriter.WriteLine(header2 & cnt1.ToString)
            'Write the xyz coordinates of points to the text file.
            GetWCSPoint3d(pt, pt1)
            objStreamWriter.WriteLine(cnt1 & “,” & Math.Round(pt1.X, 3).ToString & “,” & Math.Round(pt1.Y, 3).ToString & “,” & Math.Round(pt1.Z, 3).ToString)

            'Start the counter.
            cnt1 += 1 ' same as saying cnt1 = cnt1 + 1

        Next
        'Close the file.
        objStreamWriter.Close()
    End Sub
    Private Sub GetWCSPoint3d(ByVal thepoint As Point, ByRef pn1 As Point3d)
        Dim pnt1() As Double = {thepoint.Coordinates.X, thepoint.Coordinates.Y, thepoint.Coordinates.Z}
        Dim pnt2(2) As Double
        ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pnt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pnt2)
        pn1 = New Point3d(pnt2(0), pnt2(1), pnt2(2))
    End Sub
    Public Function select_feature(ByRef feat As Feature) As Selection.Response
        Dim selobj As NXObject = Nothing
        Dim cursor As Point3d
        Dim typeArray() As Selection.SelectionType =
         {Selection.SelectionType.Features}

        Dim resp As Selection.Response = UI.SelectionManager.SelectTaggedObject("Select feature",
           "Select feature", Selection.SelectionScope.WorkPart, False, typeArray, selobj, cursor)
        If ((resp = Selection.Response.ObjectSelected) _
                    OrElse (resp = Selection.Response.ObjectSelectedByName)) Then
            feat = CType(selobj, Feature)
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
    End Function
End Module

Frank Swinkels

 

Re: Get coordinates of points from Point Set

Creator
Creator

@FrankSwinks1

Outstanding Frank, that did the trick. I wish I was better versed in the language of VB. I very much appreciate your help with my issue and I have learned quite a bit about using journaling and the VB language. This was the first time I have attempted an object oriented language in order to create a script to interact with NX. I can see I have a lot to learn. Many thanks again!

Re: Get coordinates of points from Point Set

Creator
Creator

@cowski1

Unfortunately I was not able to get the points changed from the absolute to the WCS, but I many not have used all the functions from that script that were needed. Nevertheless, I made an attempt and have learned quite a bit about VB, as I like to know what the code is doing rather than just copy and paste. Never was a fan of the black box. @FrankSwinks1 was able to incorporate the two items I needed into the code and I have what I need now. Many thanks to the two of you for helping me with my issue. I very much appreciate your help and will definitely utilze this forum.

 

Cheers!