Submitted by cmonticchio on Wed, 12/06/2017 - 08:53
Forums:
I am trying to create a journal that will output the lengths of 28 lines in a sketch. My ideal would be that it creates a text file with the data but I could work with just the summary measure window.
I tried to record one a few times but the Measure / Length function does not work...
Any help would be greatly appreciated.
re: sketch line length
The code below should get you started; it looks at all the sketches in the current work part and reports the name and length of every line it finds.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
lw.Open()
For Each tempSketch As Sketch In theSession.Parts.Work.Sketches
lw.WriteLine("sketch: " & tempSketch.Name)
Dim sketchEnts() As NXObject = tempSketch.GetAllGeometry
For Each tempObj As NXObject In sketchEnts
If TypeOf (tempObj) Is Line Then
Dim tempLine As Line = tempObj
lw.WriteLine("line name: " & tempLine.Name)
lw.WriteLine("line length: " & tempLine.GetLength.ToString)
End If
Next
lw.WriteLine("")
Next
lw.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 Module
WOW you guys are quick! Thank
WOW you guys are quick! Thank you for the support.
After trying it I realize I get a mish mosh of data. So I renamed the lines EEAngle1 - 7, DEAngle1 - 7, EEWrap1 - 7, and DEWrap1 - 7.
Is there a way to have the output list the data in this form:
EEAngle1 =
EEAngle2 =
EEAngle3 =
etc...
DEWrap6 =
DEWrap7 =
Chris
CAM
re: sketch lines
One way to handle this would be to add the line objects to a list then sort the list based on the .Name property. The article linked below shows how to sort a list of NX objects based on a property:
http://nxjournaling.com/content/sort-list-nx-objects
Would it be easier to output
Would it be easier to output the length of each line in the previous code?
CAM
re: sketch lines
Once you have a sorted list, you can process the list in order to report the line names, lengths, and any other property you are interested in.
Ok, how can I create a list
Ok, how can I create a list of objects?
CAM
re: create list
The "sort sheet names" section of the linked article shows how to add all the drawing sheets to a list object. Adding the line objects from sketches will be very similar. The code posted previously will immediately report the line name and length when a line is found. Instead of writing the info, add the line to the list. Once you have processed all the lines, you can sort the list and report the findings.
Adding the lines to a list would look something like (the "for each" loop is modified from what was previously posted):
Dim sketchLines as new list(of Line)
.
.
.
For Each tempObj As NXObject In sketchEnts
If TypeOf (tempObj) Is Line Then
sketchLines.Add(tempObj)
End If
Next
Is there a command to 'Save
Is there a command to 'Save As' for the information window?
CAM
re: information window save-as
If you want to save the text written to the information window, change the output device type before that information is sent. See the "listing window overview" section of the article:
http://nxjournaling.com/content/write-text-file
UF_UI_save_listing_window
There is also UF_UI_save_listing_window. This lets you specify a filename, so it is essentially a "Save As" function.