Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

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

Status
Not open for further replies.

tlemonds

Aerospace
Feb 1, 2014
20
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 8.5.0.23
' 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)"
Write(header1)
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)
Next
End Sub
End Module
 
Replies continue below

Recommended for you

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

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

Part and Inventory Search

Sponsor