Which should I use - NX Open GRIP, Python, VB, etc.... ?
Which should I use - NX Open GRIP, Python, VB, etc.... ?
(OP)
I am in the need of some kind of script (and thus scripting language) to execute my project but I am a bit overwhelmed by the amount of coding languages NX supports and I don't know where to start. Currently, I am simply trying to write a script that extracts coordinates of a set of points in my part file and exports them to a text file/Excel. I'm trying to extract the coordinates of a wing outline at 8 pre-defined sections along the wing. I've attached a picture and circled some of these points to give you an idea of what I am talking about. I'm familiar with MATLAB and I'm not afraid to learn a new code language but my problem is that I have no idea what scripting language/tool to use! Apparently, NX has its own unique language/interface, GRIP, but also supports scripts written in Python, C++, and VB (maybe even more)? And then I've also heard that Knowledge Fusion may come in use. Is there some kind of convenient language I could use that has commands built in that tie to features within in NX and thus already are set up to request the proper inputs and so forth? If I could at least get a rundown of what my options are then maybe I could begin to pick a method!
P.S. I realize I could manually extract the coordinates rather fast but this process I need to accomplish is only the start of what my project entails. Eventually, I need to be able to feed airfoil coordinates in, create a surface between them, populate ribs (type, # of lightening holes, thickness, material type) within the wing, populate spars within the wing, and more--all with script. I'm basically attempting to build a very detailed parametric wing structural model. Thus, I need to begin to get familiar with some kind of scripting language built into NX because I have a lot to learn/do besides coordinate extraction!
P.S. I realize I could manually extract the coordinates rather fast but this process I need to accomplish is only the start of what my project entails. Eventually, I need to be able to feed airfoil coordinates in, create a surface between them, populate ribs (type, # of lightening holes, thickness, material type) within the wing, populate spars within the wing, and more--all with script. I'm basically attempting to build a very detailed parametric wing structural model. Thus, I need to begin to get familiar with some kind of scripting language built into NX because I have a lot to learn/do besides coordinate extraction!





RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
http://www.plm.automation.siemens.com/en_us/produc...
You'll need access to the API. According to the brochure, it is an add on, but doesn't specify costing. You'll also need the software development environment. In the case of Visual Basic you'll probably need a licensed version, but check to be sure.
Java is free via Oracle, which also provides online training information. I note that Lynda.com also offers Java training and would highly recommend the company for high quality and low cost.
Some other info: http://www.neoapps.de/en/02-unigraphics-nx-program... It's a sales page that has an overview of programming.
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
VC/VC++ may be your best bet for what you want, if you already know the language. You will need a development compiler and the software from Siemens which has the routines to be called.
VB is also available, but it is newer and I don't have any experience with it.
"Wildfires are dangerous, hard to control, and economically catastrophic."
Ben Loosli
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
3DDave, those links provided the perfect summary of what all my options are. I think for now I am going to go the route of Journaling the sequence of what I want to accomplish and then augmenting that script in VB. It is really cool how the Journal feature writes the script in VB--it should be a lot easier learning VB when I can do something on NX and then see how I would/should write it in VB. I've heard now from several sources that GRIP is the easiest to manipulate but being that its no longer updated and not a universal language, it'll probably be worth it to try and learn VB. Of course, I've only begun to scratch the surface of what I need to accomplish with script so we'll see!
John, thanks for the GRIP file, I'm going to try it out now and see if I can get it to work.
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.Utilities Imports NXOpen.Features Imports NXOpenUI Imports NXOpen.UF Module PointsAlongCurve1 Dim s As Session = Session.GetSession() Dim ui As UI = UI.GetUI() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Dim workPart As Part = s.Parts.Work Sub Main() Dim curve1 As Curve = Nothing Dim prompt1 As String = "Select a curve" Dim pointset1 As PointSet = Nothing ' ask for the number of points along curve Dim pointnumber As Integer = 2 pointnumber = NXInputBox.GetInputNumber("Number of points on curve", "Enter Number", pointnumber) start1: ' a simple loop to do multiple curves curve1 = select_a_curve(prompt1) If Not curve1 Is Nothing Then CreatePointSetAlongCurve(curve1, pointnumber, pointset1) ' now collect the points Dim pnts(pointnumber - 1) As Point Dim obj1() As NXObject obj1 = pointset1.GetEntities() ' write out to listing window WriteListingFilePointInfo(obj1, pointset1) Else GoTo end1 End If GoTo start1 end1: End Sub Function select_a_curve(ByVal prompt As String) As NXObject Dim ui As UI = ui.GetUI() Dim curveType() As Selection.SelectionType = _ {Selection.SelectionType.Curves} Dim cursor As Point3d = Nothing Dim selobj As NXObject = Nothing Dim resp As Selection.Response = _ ui.SelectionManager.SelectTaggedObject("Select a curve", prompt, _ Selection.SelectionScope.AnyInAssembly, False, _ curveType, selobj, cursor) Return selobj End Function Sub CreatePointSetAlongCurve(ByVal curve1 As NXObject, ByVal pointnumber As Integer, ByRef pointset1 As PointSet) Dim nullFeatures_PointSet As Features.PointSet = Nothing Dim pointSetBuilder1 As Features.PointSetBuilder pointSetBuilder1 = workPart.Features.CreatePointSetBuilder(nullFeatures_PointSet) pointSetBuilder1.Type = Features.PointSetBuilder.Types.CurvePoints pointSetBuilder1.NumberOfPointsExpression.RightHandSide = pointnumber.ToString pointSetBuilder1.StartPercentage.RightHandSide = "0" pointSetBuilder1.EndPercentage.RightHandSide = "100" Dim curves1(0) As IBaseCurve curves1(0) = curve1 Dim curveDumbRule1 As CurveDumbRule curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1) Dim rules1(0) As SelectionIntentRule rules1(0) = curveDumbRule1 Dim nullNXObject As NXObject = Nothing Dim junk3(2) As Double Dim junk1 As Double = Nothing Dim parm1 As Double = 0.1 Dim helppoint0(2) As Double ufs.Modl.AskCurveProps(curve1.Tag, parm1, helppoint0, junk3, junk3, junk3, junk1, junk1) Dim helppoint1 As Point3d = New Point3d(helppoint0(0), helppoint0(1), helppoint0(2)) pointSetBuilder1.SingleCurveOrEdgeCollector.AddToSection(rules1, curve1, nullNXObject, nullNXObject, helppoint1, Section.Mode.Create, False) pointset1 = pointSetBuilder1.Commit() End Sub Public Sub WriteListingFilePointInfo(ByVal obj1() As NXObject, ByVal pointset1 As PointSet) Dim header1 As String = "Information Units" Dim headermm As String = " mm" Dim headerinch As String = " Inch" Dim header2 As String = "------------------------------------------------------------" Dim xstr As String = Nothing Dim ystr As String = Nothing Dim zstr As String = Nothing lw.Open() Dim PartUnits As Integer = Nothing ufs.Part.AskUnits(workPart.Tag, PartUnits) If PartUnits = UFConstants.UF_PART_ENGLISH Then lw.WriteLine(header1 & headerinch) ElseIf PartUnits = UFConstants.UF_PART_METRIC Then lw.WriteLine(header1 & headermm) End If Dim feat1 As Feature = DirectCast(pointset1, Feature) Dim name1 As String = feat1.GetFeatureName lw.WriteLine(name1 & " X Y Z") For i As Integer = 0 To obj1.Length - 1 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) lw.WriteLine("Point " & (i + 1).ToString & xstr & ystr & zstr) Next lw.WriteLine(vbCrLf) lw.WriteLine(header2) lw.WriteLine(vbCrLf) End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer '----Other unload options------- 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleFrank Swinkels
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
Had some time to work on this again today and I'm taking a crack at writing my own VB code/script (not sure what the proper terminology is) which is pasted below. First off, I did not simply copy and paste the sections of your code that I thought were applicable, but I actually thought through everything and decided/interpreted what I thought my code would need. Since this is my first VB code, I've learned a lot about basic VB formatting/functions due to your code--thank you! Anyway, the point set that I want to extract coordinates from is already defined in my NX part file and so you'll see I don't have any of your code pertaining to creating a point set. When I try to run the code from the Journal Editor, I get the following Journal execution error message: System.NullReferenceException: Object reference not set to an instance of an object. at NXJournal.Main() in C:\Users\tlemonds\AppData\Tempe\NXJournals8036\journal.vb:line21. I have two different "theories" why this may be happening. First, I am running NX on my personal laptop with the license being activated via a VPN client. The location of "\Temp\NXJournals8036" doesn't even exist on my hard drive maybe because my license is connected to VPN and maybe that is the issue. My other "theory" is that I am not defining "pointset1" correctly. As I said, I have my desired point set already defined within NX and I have titled it as "pointset1" within NX. I'm not sure if I should be calling it as a "Feature" or a "PointSet" honestly. Any help you could provide would be much appreciated!
P.S. My code probably looks pretty laughable compared to yours, not sure if I'm close or way off to getting this to work. I've sincerely put the past few hours into this and if my little bit of code looks like it came from little effort I promise that looks are deceiving! Please remember my most complex coding "experience" involves for/if/while loops and general computing in MATLAB.
VB CODE:
' 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
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
CODE -->
Option Strict Off Imports System Imports System.IO Imports NXOpen Imports NXOpen.Utilities Imports NXOpen.Features Imports NXOpenUI Imports NXOpen.UF Module PointsAlongCurveToTextFile 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 = Nothing Dim feats As FeatureCollection = workPart.Features Dim name1 As String = Nothing Dim objStreamWriter As StreamWriter objStreamWriter = New StreamWriter("C:\coords1.txt") For Each ft1 As Feature In feats name1 = ft1.GetFeatureName If name1.Contains("Point Set") Then obj1 = ft1.GetEntities() ' write out to file WriteCoords(obj1, objStreamWriter, ft1) End If Next 'Close the file. objStreamWriter.Close() End Sub Public Sub WriteCoords(ByVal obj1() As NXObject, ByVal objstreamwriter As StreamWriter, ByVal feat1 As Feature) Dim header1 As String = "Control Point Coordinates (inches)" objstreamwriter.WriteLine(header1) Dim xstr As String = Nothing Dim ystr As String = Nothing Dim zstr As String = Nothing Dim name1 As String = feat1.GetFeatureName objstreamwriter.WriteLine(name1 & " X Y Z") For i As Integer = 0 To obj1.Length - 1 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) objstreamwriter.WriteLine("Point " & (i + 1).ToString & xstr & ystr & zstr) Next End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer '----Other unload options------- 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleFrank Swinkels
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
Thank you so much! As I suspected, I was defining my point set incorrectly it would seem (among several other minor things). I follow your procedure, how you basically call the entire set of features and then with your "For Each..." section you extract only the feature that is a point set by only "calling out" the feature with "Point Set" in its name. Is there a more direct method for "calling out" a specific feature within your part file? I understand your file works fine and I appreciate it, I'm just curious for future reference as I'm truly trying to comprehend/understand how VB identifies features in NX.
Thanks again,
Tyler
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
Frank Swinkels
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
Due to some unavoidable issues with using a point set, I have been forced to instead create a set of separate points that I need to extract the geometry of. I adjusted my VB code to take/collect these points. However, it is not writing the coordinates to the text file as desired. For 16 points, this is the text file that is produced:
Control Point Coordinates (inches)
Point(5) X Y Z
Control Point1 0.000 0.000 0.000
Control Point Coordinates (inches)
Point(6) X Y Z
Control Point1 181.579 0.000 0.000
Control Point Coordinates (inches)
Point(7) X Y Z
Control Point1 39.224 70.979 6.210
Control Point Coordinates (inches)
Point(8) X Y Z
Control Point1 196.330 70.979 6.210
Control Point Coordinates (inches)
Point(9) X Y Z
Control Point1 78.449 141.958 12.420
Control Point Coordinates (inches)
Point(10) X Y Z
Control Point1 211.080 141.958 12.420
Control Point Coordinates (inches)
Point(12) X Y Z
Control Point1 118.416 227.445 13.912
Control Point Coordinates (inches)
Point(13) X Y Z
Control Point1 239.651 227.445 13.912
Control Point Coordinates (inches)
Point(14) X Y Z
Control Point1 158.382 312.932 15.404
Control Point Coordinates (inches)
Point(15) X Y Z
Control Point1 268.221 312.932 15.404
Control Point Coordinates (inches)
Point(16) X Y Z
Control Point1 198.349 398.419 16.896
Control Point Coordinates (inches)
Point(17) X Y Z
Control Point1 296.792 398.419 16.896
Control Point Coordinates (inches)
Point(18) X Y Z
Control Point1 238.315 483.906 18.388
Control Point Coordinates (inches)
Point(19) X Y Z
Control Point1 325.362 483.906 18.388
Control Point Coordinates (inches)
Point(20) X Y Z
Control Point1 277.795 568.351 19.862
Control Point Coordinates (inches)
Point(21) X Y Z
Control Point1 353.585 568.351 19.862
The problem is that I want the header ("Control Point Coordinates...") to only occur once, as well as the "X Y Z". Also, it would be nice (but not necessary) to have it write Control Point 1, 2, 3, etc... versus simply repeating "Control Point1". I understand the code enough to see why this is happening. It was initially set up to take just one object as a point set, with that object then containing multiple features. Now that I have 16 points defined separately, it takes one object as one point, and repeats the write process for all 16 points, hence the header, "X Y Z", and "Control Point1" being repeated for every point. However, I do not know enough about VB coding to fix this. I assume the fix would be to somehow specify a set of objects versus just one object and having the write procedure pertain to that set of objects versus every single object. My code to be altered is pasted below. Thank you so much, Frank, you've been very helpful! I promise I'm actually inspecting this code and trying to learn versus simply taking whatever you post.
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.Features
Imports NXOpenUI
Imports NXOpen.UF
Module PointsAlongCurveToTextFile
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 = Nothing
Dim feats As FeatureCollection = workPart.Features
Dim name1 As String = Nothing
Dim objStreamWriter As StreamWriter
objStreamWriter = New StreamWriter("C:\Users\tlemonds\Documents\Applied Project\journals\coords1.txt")
For Each ft1 As Feature In feats
name1 = ft1.GetFeatureName
If name1.Contains("Point") Then
obj1 = ft1.GetEntities()
' write out to file
WriteCoords(obj1, objStreamWriter, ft1)
End If
Next
'Close the file.
objStreamWriter.Close()
End Sub
Public Sub WriteCoords(ByVal obj1() As NXObject, ByVal objstreamwriter As StreamWriter, ByVal feat1 As Feature)
Dim header1 As String = "Control Point Coordinates (inches)"
objstreamwriter.WriteLine(header1)
Dim xstr As String = Nothing
Dim ystr As String = Nothing
Dim zstr As String = Nothing
Dim name1 As String = feat1.GetFeatureName
objstreamwriter.WriteLine(name1 & " X Y Z")
For i As Integer = 0 To obj1.Length - 1
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)
objstreamwriter.WriteLine("Control Point" & (i + 1).ToString & xstr & ystr & zstr)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'----Other unload options-------
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
Dim cnt1 as integer = 1
For Each ft1 As Feature In feats
name1 = ft1.GetFeatureName
If name1.Contains("Point") Then
obj1 = ft1.GetEntities()
' write out to file
WriteCoords(obj1, cnt1, objStreamWriter, ft1)
cnt1 += 1
End If
Next
Then change the WriteCoords sub as follows
Public Sub WriteCoords(ByVal obj1() As NXObject, ByVal cnt1 as Integer, _
ByVal objstreamwriter As StreamWriter, ByVal feat1 As Feature)
Dim header1 As String = "Control Point "
Dim header2 As String = " Coordinates (inches)"
objstreamwriter.WriteLine(header1 & cnt1.ToString & header2)
Dim xstr As String = Nothing
Dim ystr As String = Nothing
Dim zstr As String = Nothing
Dim name1 As String = feat1.GetFeatureName
objstreamwriter.WriteLine(name1 & " X Y Z")
For i As Integer = 0 To obj1.Length - 1
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)
objstreamwriter.WriteLine("Control Point" & (i + 1).ToString & xstr & ystr & zstr)
Next
End Sub
Frank Swinkels
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
Thanks for yet another response! Your recommended changes above still results in a repeat of header1 and header2 for every point. I would like for "Control Point Coordinates (inches) --- X Y Z" to occur just once at the first line of the text file. I do still want the "Control Point " and cnt1 to repeat for every point though, and you'll see that I kept that part of the code intact in my pasted VB code below. You'll see I tried adding a "middle" sub that simply opens the text file and writes my desired header to the first line of the text file. However, the WriteCoords sub just overwrites it. If you could show me a way to do a "manual" WriteLine of the first line within the WriteCoords sub or how to start the WriteLine(header2 & cnt1) command on the second line of the text file and to repeat afterwards that would be great! I've pasted what I would like my text file to look like below just to make sure we're on the same page.
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.Features
Imports NXOpenUI
Imports NXOpen.UF
Module PointsAlongCurveToTextFile
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 = Nothing
Dim feats As FeatureCollection = workPart.Features
Dim name1 As String = Nothing
Dim objStreamWriter As StreamWriter
objStreamWriter = New StreamWriter("C:\Users\tlemonds\Documents\Applied Project\journals\coords1.txt")
Dim cnt1 as Integer = 1
For Each ft1 As Feature In feats
name1 = ft1.GetFeatureName
If name1.Contains("Point") Then
obj1 = ft1.GetEntities()
' write out to file
WriteCoords(obj1, cnt1, objStreamWriter, ft1)
cnt1 += 1
End If
Next
'Close the file.
objStreamWriter.Close()
End Sub
Public Sub SetUpCoordsFile()
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("C:\Users\tlemonds\Documents\Applied Project\journals\coords1.txt", True)
file.WriteLine("Control Point Coordinates (inches) --- X Y Z")
file.Close()
End Sub
Public Sub WriteCoords(ByVal obj1() As NXObject, ByVal cnt1 as Integer, ByVal objstreamwriter As StreamWriter, ByVal feat1 As Feature)
Dim header1 As String = "Control Point Coordinates(inches)"
Dim header2 As String = "Control Point "
objStreamWriter.WriteLine(header1 & " --- X Y Z")
Dim xstr As String = Nothing
Dim ystr As String = Nothing
Dim zstr As String = Nothing
Dim name1 As String = feat1.GetFeatureName
objstreamwriter.WriteLine(header2 & cnt1)
For i As Integer = 0 To obj1.Length - 1
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)
objstreamwriter.WriteLine(xstr & ystr & zstr)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'----Other unload options-------
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
What I would like my text file to look like:
Control Point Coordinates(inches) --- X Y Z
Control Point 1
0.000 0.000 0.000
Control Point 2
181.579 0.000 0.000
Control Point 3
39.224 70.979 6.210
Control Point 4
196.330 70.979 6.210
Control Point 5
78.449 141.958 12.420
Control Point 6
211.080 141.958 12.420
Control Point 7
118.416 227.445 13.912
Control Point 8
239.651 227.445 13.912
Control Point 9
158.382 312.932 15.404
Control Point 10
268.221 312.932 15.404
Control Point 11
198.349 398.419 16.896
Control Point 12
296.792 398.419 16.896
Control Point 13
238.315 483.906 18.388
Control Point 14
325.362 483.906 18.388
Control Point 15
277.795 568.351 19.862
Control Point 16
353.585 568.351 19.862
RE: Which should I use - NX Open GRIP, Python, VB, etc.... ?
CODE -->
Option Strict Off Imports System Imports System.IO Imports NXOpen Imports NXOpen.UF Module PointDataToFile Sub Main() 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 Dim pointcollection1 As PointCollection = wp.Points Dim objStreamWriter As StreamWriter objStreamWriter = New StreamWriter("C:\coords1.txt") Dim header1 As String = "Control Point Coordinates (inches) --- X Y Z" Dim header2 As String = "Control Point " objStreamWriter.WriteLine(header1) Dim cnt1 As Integer = 1 For Each pt As Point In pointcollection1 objStreamWriter.WriteLine(header2 & cnt1.ToString) objStreamWriter.WriteLine(Math.Round(pt.Coordinates.X, 3).ToString & " " & _ Math.Round(pt.Coordinates.Y, 3).ToString & " " & _ Math.Round(pt.Coordinates.Z, 3).ToString) cnt1 += 1 Next 'Close the file. objStreamWriter.Close() End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleFrank Swinkels