Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Extract coords from point set in NX and write to text/Excel

Extract coords from point set in NX and write to text/Excel

Extract coords from point set in NX and write to text/Excel

Hey guys,

I have a pre-defined point set in my NX part file that contains 16 points and I have it titled as "pointset1" within my part file. I am attempting to write/execute a VB code that will extract the global coordinates from those 16 points and write them to a text file for convenient output to Excel. I guess the smart thing to do would be to write them directly to an Excel spreadsheet but I am (completely) new to VB and I'm not sure if that is possible and I wouldn't know where to begin! For the time being, writing to a text file seems fine. Anyway, I've taken a crack at it and pasted my VB code below. When I try to run it from the Journal editor I get the following error message: Object reference not set to an instance of an object. at NXJournal.Main() in C:\Users\tlemonds\AppData\Tempe\NXJournals8036\journal.vb:line21. This is my first attempt at writing some VB code so I wouldn't be surprised if I'm doing something very "obviously" wrong. I do suspect that I am not defining "pointset1" correctly and I'm honestly not sure if it matters that I am executing this in Journal editor or if I need to execute it via some other platform. Any guidance provided would be much appreciated!

' NX
' Journal created by tlemonds on Sat Feb 15 14:11:58 2014 US Mountain Standard Time
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.Features
Imports NXOpenUI
Imports NXOpen.UF

Module NXJournal

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

Sub Main ()
Dim obj1() As NXObject
Dim pointset1 As PointSet = pointset1
obj1 = pointset1.GetEntities()
End Sub

Public Sub WriteCoords(ByVal obj1() As NXObject, ByVal pointset1 As PointSet)
FileOpen(1, "coords1.txt", OpenMode.Output)
Dim header1 As String = "Control Point Coordinates (inches)"
Dim xstr As String = Nothing
Dim ystr As String = Nothing
Dim zstr As String = Nothing
Dim feat1 As Feature = DirectCast(pointset1, Feature)
Dim name1 As String = feat1.GetFeatureName
WriteLine(name1 & "X Y Z")
For i As Integer = 0 To 16
Dim pt As Point = DirectCast(obj1(i), Point)
xstr = FormatNumber(pt.Coordinates.X, 3, , , TriState.True).PadLeft(20)
ystr = FormatNumber(pt.Coordinates.Y, 3, , , TriState.True).PadLeft(15)
zstr = FormatNumber(pt.Coordinates.Z, 3, , , TriState.True).PadLeft(15)
WriteLine("Point " & (i+1).ToString & xstr & ystr & zstr)
End Sub
End Module

RE: Extract coords from point set in NX and write to text/Excel

Is pointset1 a custom name that you have given the feature, or does it show up in the feature navigator as Point Set (1)?


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close