Hello,
I am new to journaling and I have been finding this website very informative. I have found a journal online that will display points and their location on the coordinate system. This is close to what I need, however I need the points relative to the world coordinate system and not the absolute coordinate system. I also need to display some identifying information about the point, such as the Point - ID in a point set. I have provided the existing code if anybody is willing to help modify the code.
To get the information I need I would select the points and then go to menu Information --> Object... . This gets the job done but it is very slow to display the information when dealing with 1000+ points. If someone could also help me write a journal that calls Information --> Object... and then instead of listing the data on the screen it prompts you to save the data that would be very appreciated.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module PointsInformation
' Explicit Activation
' This entry point is used to activate the application explicitly
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim response2 As Selection.Response = Nothing
Dim pnt2() As Double = {0.0, 0.0, 0.0}
Dim selectedObjects() As NXObject
theSession.ListingWindow.Open
Start1:
Start2:
response2 = select_a_Point(selectedObjects)
If response2 = Selection.Response.Back Then GoTo Start1 ' Select a new face
If response2 = Selection.Response.Cancel Then GoTo End1
Dim info As String = "Number of selected objects = "
info = String.Concat(info, selectedObjects.Length)
theSession.ListingWindow.WriteLine(info)
Dim sda As Point
For Each sda In selectedObjects
ufs.Curve.AskPointData(sda.Tag, pnt2)
theSession.ListingWindow.WriteLine("X," & pnt2(0).ToString("N14") & " Y," & pnt2(1).ToString("N14") & " Z,"& pnt2(2).ToString("N14"))
Next
GoTo Start2 ' Continue selecting points for current face
End1:
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'----Other unload options-------
'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
Function select_a_Point(ByRef selectedObjects As NXObject())
Dim ui As UI = ui.GetUI()
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_point_type
.Subtype = UFConstants.UF_point_subtype
.SolidBodySubtype = 0
End With
Try
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObjects("Select Points", "Select Points", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, selectedObjects)
If resp = Selection.Response.Cancel Or _
resp = Selection.Response.Back Then
Return Selection.Response.Cancel
Else
Dim info As String = "Number of selected objects = "
info = String.Concat(info, selectedObjects.Length)
System.Diagnostics.Trace.WriteLine(info)
Return Selection.Response.Ok
End If
Catch e As Exception
System.Diagnostics.Trace.WriteLine("Problems selecting objects.")
System.Diagnostics.Trace.WriteLine(e.ToString)
End Try
End Function
End Module
Thank you very much for the support!
link to code
here is where i got the code: http://files.engineering.com/getfile.aspx?folder=8c51eb5f-4071-447b-ad73...
re: map point
The MapPoint function will convert point coordinates between local and global coordinate systems.
global to local:
'Date: 11/18/2010
'Subject: Sample NX Open .NET Visual Basic routine : map point from absolute to wcs
'
'Note: GTAC provides programming examples for illustration only, and
'assumes that you are familiar with the programming language being
'demonstrated and the tools used to create and debug procedures. GTAC
'support professionals can help explain the functionality of a particular
'procedure, but we will not modify these examples to provide added
'functionality or construct procedures to meet your specific needs.
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
ufs.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
Local to global:
'Date: 06/14/2011
'Subject: Sample NX Open .NET Visual Basic routine : map point from WCS to absolute
'
'Note: GTAC provides programming examples for illustration only, and
'assumes that you are familiar with the programming language being
'demonstrated and the tools used to create and debug procedures. GTAC
'support professionals can help explain the functionality of a particular
'procedure, but we will not modify these examples to provide added
'functionality or construct procedures to meet your specific needs.
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
ufs.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
Thank you very much for the
Thank you very much for the help. If the points are from a Point Set do you know how I could also grab the Point - ID number as well?
I can get the Point - ID from Information --> Object... but displaying the text as it writes out the data for 1000+ points takes too long.
re: point ID
What do you plan on doing with the point ID? I don't see a good way to return the ID of a given point or return a point given an ID number...
re: object ID
While poking around the GTAC solution center, I found some code that will report the ID of the selected object. Perhaps this will simplify your code.
Code written by Amy Webster of GTAC fame.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Dim s As Session = Nothing
Dim ufs As UFSession = Nothing
Dim lw As ListingWindow = Nothing
Sub Main
s = Session.GetSession()
lw = s.ListingWindow
ufs = NXOpen.UF.UFSession.GetUFSession()
Dim object1 As NXObject = SelectAnObject("Report Object ID")
Dim handle As String = Nothing
Dim fileData As String = Nothing
Dim ID as UInteger = 0
Dim version as UInteger = 0
Do While object1 isnot nothing
handle = ufs.Tag.AskHandleOfTag(object1.Tag)
ufs.Tag.DecomposeHandle(handle, fileData, ID, version)
ECHO("ID = " & ID)
object1 = SelectAnObject("Report Object ID")
Loop
End Sub
Function SelectAnObject(ByVal prompt As String) As NXObject
Dim selobj As NXObject = Nothing
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All, _
Selection.SelectionType.Faces, _
Selection.SelectionType.Edges}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
prompt, "Select an object", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj, cursor)
Return selobj
End Function
Sub Echo(ByVal output As String)
lw.Open()
lw.WriteLine(output)
ufs.UF.PrintSyslog(output & vbCrLf, False)
End Sub
End Module
re: point ID
I plan on using the point ID to organize the points gathered from within the Point Set and relative to other Point Sets.
Do you know if it's possible to use a journal to perform Information --> Object... but instead of displaying to the window it just saves it directly to a file?
re: point info
If your journal is creating the points, you might find it easier to use the tag, or assign your own name or attribute to each point.
Here is some code that will allow you to select points and write out the information into your "MyDocuments" folder.
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim thePoint As Point
While SelectPoint("Select a point", thePoint) <> Selection.Response.Cancel
lw.Open()
Dim outputFile As String = IO.Path.Combine(myDocs, thePoint.Tag.ToString & ".txt")
lw.SelectDevice(ListingWindow.DeviceType.File, outputFile)
Dim thePoints(0) As Point
thePoints(0) = thePoint
theSession.Information.DisplayObjectsDetails(thePoints)
lw.Close()
'flush file buffer by changing listing window device
lw.SelectDevice(ListingWindow.DeviceType.Window, "")
End While
End Sub
Function SelectPoint(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a point"
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_point_type
.Subtype = UFConstants.UF_point_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(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
End Function
End Module
Object Information to String Array?
Instead of writing to a file,
Is is possible to write this "Object Information" to a String Array?
Carlo Tony Daristotile
re: write to string array
Unfortunately, the ListingWindow object controls the output and you get 2 choices: window or file. Perhaps with some clever, low-level coding you could intercept the info and write it to an array instead of the window or file. Probably the easier route would be to write the info to a file, then read that file into a string array. Not the most direct method, but fairly easy to accomplish.
re: point info
Thank you for that code. That's almost exactly what I am looking for. I don't have access to NX right now to mess with but would it be difficult to alter the code to where you can select all the points at once and then write the info to a single file?
re: point info
This version allows you to select multiple point objects and writes the information window to a single file.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim thePoints() As NXObject
lw.Open()
If SelectPoints("Select points", thePoints) = Selection.Response.Cancel Then
Return
End If
Dim outputFile As String = IO.Path.Combine(myDocs, "point_info.txt")
If IO.File.Exists(outputFile) Then
Try
IO.File.Delete(outputFile)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error deleting file")
End Try
End If
lw.SelectDevice(ListingWindow.DeviceType.File, outputFile)
theSession.Information.DisplayObjectsDetails(thePoints)
lw.Close()
'flush file buffer by changing listing window device
lw.SelectDevice(ListingWindow.DeviceType.Window, "")
MsgBox("Output written to " & outputFile)
End Sub
Function SelectPoints(ByVal prompt As String, byRef selObj() as NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select points"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_point_type
.Subtype = UFConstants.UF_point_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj)
If resp = Selection.Response.Ok 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
End Function
End Module
re: point info
Thank you very much. That journal does exactly what I needed.
Is it possible to with the Parent File?
Is it possible to with the Parent File?
Or does this work only for the subcomponents?
Thanks
Carlo Tony Daristotile
re: work part
There is a line of code in the SelectPoint function that limits selection to the work part:
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
To allow selection anywhere in the assembly, change the above line to:
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly