In the 15 years that I have been a mechanical engineer, I have found that many routines we do daily are repetitive. Since my earliest career days, I have been writing programs, code snippets and macros to provide accurate, quick solutions to these mundane tasks. If you have written a journal that would be useful to others, we would love for you to submit it for others to use as well. By submitting you would be granting others free use of your journal.
Please post below.
Feel free to email questions, comments, journals you'd like to share, or journal ideas to: info@nxjournaling.com
Comments
Can we post different
Can we post different journals, I have someones to upload.
I suggest to create a list between CAD/CAM/CAE journals etc.
What about UGSTYLER and UGOPEN programing?
Posting Journals
Ideally, users will post their own nx journals and share with the community as a whole. However, you will want to be careful about posting another's journal without their consent. We wouldn't want to infringe on anybody's intelectual property.
UFUNC CAM set feedrate
Hi all,
How can I do a VB macro, of this video? I have upload a partial working excel file.
http://www.youtube.com/watch?v=sQ0f1XLijiE&feature=mfu_in_order&list=UL
Thanks.
multiple photos journal
Hi all,
I want to create a journal for multiple photos geration and print them on a PDF file.
The point is that I have done some test, but the journal dosen't work correctly. Because the photos are with wireframe view or can't be printed as a pdf file.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Module NXJournal
Public theSession As Session = Session.GetSession()
Public openSession = UFSession.GetUFSession()
Public workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Public sFilename As String
Public imageFile As String
Public image_format As UFDisp.ImageFormat = UFDisp.ImageFormat.Png
Public background_color As UFDisp.BackgroundColor = UFDisp.BackgroundColor.Original
Sub Main()
'Get File name
sFilename = workPart.FullPath
sFilename = Replace(sFilename, "<", "")
sFilename = Replace(sFilename, ">", "")
If Right(sFilename.ToLower, 4) = ".prt" Then sFilename = Left(sFilename, sFilename.Length - 4)
'If layout VBLAYOUT exists then delete it first
On Error GoTo CreateLay
Dim objects1(0) As NXObject
Dim layout99 As Layout = CType(workPart.Layouts.FindObject("VBLAYOUT"), Layout)
objects1(0) = layout99
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)
Dim id1 As Session.UndoMarkId
id1 = theSession.NewestVisibleUndoMark
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(id1)
CreateLay:
'Create a 4-view layout
Dim layoutDefinition1 As LayoutDefinition
workPart.Layouts.NewLayoutDefinition(LayoutDefinition.ArrangementType.L4, layoutDefinition1)
Dim modelingView0 As ModelingView = CType(workPart.ModelingViews.FindObject("TOP"), ModelingView)
layoutDefinition1.SetView(0, 0, modelingView0)
Dim modelingView1 As ModelingView = CType(workPart.ModelingViews.FindObject("FRONT"), ModelingView)
layoutDefinition1.SetView(1, 0, modelingView1)
Dim modelingView2 As ModelingView = CType(workPart.ModelingViews.FindObject("TFR-ISO"), ModelingView)
layoutDefinition1.SetView(0, 1, modelingView2)
Dim modelingView3 As ModelingView = CType(workPart.ModelingViews.FindObject("RIGHT"), ModelingView)
layoutDefinition1.SetView(1, 1, modelingView3)
Dim layout1 As Layout
layout1 = workPart.Layouts.Create("VBLAYOUT", layoutDefinition1, True)
layoutDefinition1.Dispose()
imageFile = sFilename & "-Layout" & ".png"
openSession.Disp.CreateImage(imageFile, image_format, background_color)
'Add PDF printer code here
// ----------------------------------------------
// Menu: File->Export->PDF...
// ----------------------------------------------
String displayPart_Path = theSession.Parts.Display.FullPath;
String displayPart_Name = displayPart_Path.Replace(".prt", ".pdf");
theSession.ListingWindow.Open();
theSession.ListingWindow.WriteLine(displayPart_Name);
theSession.ListingWindow.WriteLine("Path is: "+displayPart_Path);
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");
PrintPDFBuilder printPDFBuilder1;
printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder();
printPDFBuilder1.Scale = 1.0;
printPDFBuilder1.Action = NXOpen.PrintPDFBuilder.ActionOption.New;
printPDFBuilder1.Colors = NXOpen.PrintPDFBuilder.Color.BlackOnWhite;
printPDFBuilder1.Widths = NXOpen.PrintPDFBuilder.Width.StandardWidths;
printPDFBuilder1.Size = NXOpen.PrintPDFBuilder.SizeOption.ScaleFactor;
printPDFBuilder1.Units = NXOpen.PrintPDFBuilder.UnitsOption.English;
printPDFBuilder1.XDimension = 8.5;
printPDFBuilder1.YDimension = 11.0;
printPDFBuilder1.RasterImages = true;
printPDFBuilder1.ImageResolution = NXOpen.PrintPDFBuilder.ImageResolutionOption.Draft;
theSession.SetUndoMarkName(markId1, "Export PDF");
NXOpen.Session.UndoMarkId markId2;
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export PDF");
printPDFBuilder1.Watermark = "";
NXObject[] sheets1 = new NXObject[1];
NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.CurrentDrawingSheet;
sheets1[0] = drawingSheet1;
printPDFBuilder1.SourceBuilder.SetSheets(sheets1);
printPDFBuilder1.Filename = displayPart_Name;
NXObject nXObject1;
nXObject1 = printPDFBuilder1.Commit();
theSession.DeleteUndoMark(markId2, null);
printPDFBuilder1.Destroy();
// ----------------------------------------------
// Menu: Tools->Journal->Stop
// ----------------------------------------------
}
End Sub
End Module
multiple photos journal v2
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Module NXJournal
Public theSession As Session = Session.GetSession()
Public openSession = UFSession.GetUFSession()
Public workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Public sFilename As String
Public imageFile As String
Public image_format As UFDisp.ImageFormat = UFDisp.ImageFormat.Png
Public background_color As UFDisp.BackgroundColor = UFDisp.BackgroundColor.Original
Sub Main()
'Get File name
sFilename = workPart.FullPath
sFilename = Replace(sFilename, "<", "")
sFilename = Replace(sFilename, ">", "")
If Right(sFilename.ToLower, 4) = ".prt" Then sFilename = Left(sFilename, sFilename.Length - 4)
'Export
workPart.ModelingViews.WorkView.Fit()
workPart.ModelingViews.WorkView.Orient(View.Canned.Top, View.ScaleAdjustment.Fit)
ExportImage("TOP")
workPart.ModelingViews.WorkView.Fit()
workPart.ModelingViews.WorkView.Orient(View.Canned.Front, View.ScaleAdjustment.Fit)
ExportImage("FRONT")
workPart.ModelingViews.WorkView.Fit()
workPart.ModelingViews.WorkView.Orient(View.Canned.Left, View.ScaleAdjustment.Fit)
ExportImage("LEFT")
workPart.ModelingViews.WorkView.Fit()
workPart.ModelingViews.WorkView.Orient(View.Canned.Right, View.ScaleAdjustment.Fit)
ExportImage("RIGHT")
workPart.ModelingViews.WorkView.Fit()
workPart.ModelingViews.WorkView.Orient(View.Canned.Isometric, View.ScaleAdjustment.Fit)
ExportImage("ISO")
End Sub
Public Function ExportImage(ByVal aanzicht As String)
On Error Resume Next
imageFile = sFilename & "-" & aanzicht & ".png"
openSession.Disp.CreateImage(imageFile, image_format, background_color)
' ----------------------------------------------
' Menu: Archive->Print...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")
Dim printBuilder1 As PrintBuilder
printBuilder1 = workPart.PlotManager.CreatePrintBuilder()
printBuilder1.Copies = 1
printBuilder1.ThinWidth = 1.0
printBuilder1.NormalWidth = 2.0
printBuilder1.ThickWidth = 3.0
printBuilder1.RasterImages = True
theSession.SetUndoMarkName(markId1, "Print diálogo")
printBuilder1.Output = PrintBuilder.OutputOption.Shaded
printBuilder1.WhiteBackground = True
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Print")
Dim sheets1(0) As NXObject
Dim nullNXObject As NXObject = Nothing
sheets1(0) = nullNXObject
printBuilder1.SourceBuilder.SetSheets(sheets1)
printBuilder1.PrinterText = "Bullzip PDF Printer"
printBuilder1.Orientation = PrintBuilder.OrientationOption.Landscape
printBuilder1.Paper = PrintBuilder.PaperSize.A3
Dim paper1 As PrintBuilder.PaperSize
paper1 = printBuilder1.Paper
Dim nXObject1 As NXObject
nXObject1 = printBuilder1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markId1, "Print")
printBuilder1.Destroy()
theSession.DeleteUndoMark(markId1, Nothing)
End Function
End Module
NX Journal
What is the use of journal?
When should it be used and how?
Could someone send a simple application of it?
Thanks
why journal
A journal allows you to programmatically control NX. You can use it to add new functionality to NX, or automate your processes.
For instance, if you need to export all the solid bodies from layer 1 to a datestamped file in a certain folder of your network drive, you could go to file -> export, select the bodies, name the file, and press OK. If this is something you will be doing on a daily basis, you might want to create a journal so that it will be done at the click of a button.
Exporting files is just a simple example. If your company creates custom widgets, you can design a custom application to help you with that. Perhaps a custom form will allow the user to input some design parameters, then the program will perform some calculations and create new files as necessary.
If you want an example, look at the creating QC number example on this site. Open a drawing that has several dimensions on it then run the journal. As you select the dimensions it will place an identifying number next to the dimension and associate it, then increment the number for the next dimension you pick. This is useful for referring to dimensions on a quality control report.
opening last revision of part automatically
Is it possible to open a part as its last revision?
latest version
Are you using native NX or some PDM/PLM such as Teamcenter?
Are we talking about opening a piece part or loading the latest version of a component when you open an assembly file?
Find and Replace word in NX
I am having code to find and replace word in NX. But it is havinbg some limitations. It works only for Notes. But I want to change it to Lables and dimensions. Thanks for the reply.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Utilities
Imports NXOpen.Annotations
Module ChangeNoteWord
Dim s As Session = Session.GetSession()
Dim dp As Part = s.Parts.Display
Dim nc As NoteCollection = dp.Notes
Sub Main()
Dim notetext1 As String = "existing word"
notetext1 = NXInputBox.GetInputString("Change Note", "Note word to be changed", notetext1)
Dim notetext2 As String = "new word"
notetext2 = NXInputBox.GetInputString("Change Note", "New note word", notetext2)
Dim notestring() As String
Dim nolines As Integer = 0
Dim found1 As Boolean = False
Dim m1 As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "M1")
For Each a_note As Note In nc
notestring = a_note.GetText()
nolines = notestring.Length
For i As Integer = 0 To nolines - 1
found1 = notestring(i).Contains(notetext1)
If found1 = True Then
notestring(i) = notestring(i).Replace(notetext1, notetext2)
End If
Next
a_note.SetText(notestring)
Next
s.UpdateManager.DoUpdate(m1)
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
Stay Hungry
Stay Foolish
SourceCode for UserForm from VB2010Exp
Hello NX Journaling. I have a question about how to compile a UserForm made in VisualBasic 2010 ExpEd to be use as a journal in NX. I know that I can write the code for every object in the form but is there is a faster way to do that?
Regards.
re user form
Visual studio (any version) can be set up to work closely with NX. If you install NX after visual studio, the NX install should take care of it for you. If you installed visual studio after NX, search the NX help file programmer's reference for the term "wizard setup". When set correctly, VS will offer the option of "NX Open VB Wizard" when starting a new project.
When using this wizard, VS will fill in some common code for you depending on your choices. After starting a project, you can add a user form to your project (by default it is named Form1). You can then use the visual editor to add controls, change properties, and resize elements. Double clicking the form will show the code listing associated with the form; add your code here for handling form events, user input and such.
At this point there will be 3 important files in your project folder:
Create a new text file then copy and paste the contents of each of these three files into the new file. Name the file and change the extension to .vb. Switch to NX and try out your new journal.
Thanks for your answer, I
Thanks for your answer, I will try this as soon as possible.
BestRegards.
re user form
It works great!!! Thanks for your help!!!
MAPLE LEAF
'NXJournaling
'a journal that creates fractal leaf using the CreateLine method and recursion
'Carlo Daristotile 2013-FEB
Option Strict Off
Imports System
Imports System.Math
Imports NXOpen
Module Module1
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim deg_to_rad As Double = Math.PI / 180
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJournaling.com")
Dim depth As Integer = 9
Dim ptStart As Point3d = New Point3d(0, 0, 0)
Dim ptEnd As Point3d = New Point3d(10, 10, 0)
DrawTree(ptStart, ptEnd, depth)
End Sub
Sub DrawTree(ByVal startPoint As Point3d, ByVal endPoint As Point3d, ByVal depth As Integer)
If depth = 0 Then
Exit Sub
End If
'find End Points of 3 lines , one straight, one left, one right
Dim ptEndS As Point3d
Dim ptEndL As Point3d
Dim ptEndR As Point3d
'find End Point of straight line
ptEndS.X = endPoint.X + (endPoint.X - startPoint.X)*0.5
ptEndS.Y = endPoint.Y + (endPoint.Y - startPoint.Y)*0.5
ptEndS.Z = endPoint.Z + (endPoint.Z - startPoint.Z)*0.5
'find End Point of right line
ptEndL.X = endPoint.X - (endPoint.X - startPoint.X)*0.45
ptEndL.Y = endPoint.Y + (endPoint.Y - startPoint.Y)*0.45
ptEndL.Z = endPoint.Z + 0
'find End Point of left line
ptEndR.X = endPoint.X + (endPoint.X - startPoint.X)*0.45
ptEndR.Y = endPoint.Y - (endPoint.Y - startPoint.Y)*0.45
ptEndR.Z = endPoint.Z + 0
'draw 3 lines , one straight, one left, one right
workPart.Curves.CreateLine(endPoint , ptEndS )
workPart.Curves.CreateLine(endPoint , ptEndL )
workPart.Curves.CreateLine(endPoint , ptEndR )
'make 3 new lines , one straight, one left, one right, for each line just made
DrawTree(endPoint , ptEndS , depth-1)
DrawTree(endPoint , ptEndL , depth-1)
DrawTree(endPoint , ptEndR , depth-1)
End Sub
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
Point and component labeling
My company needs a journal that will list the name of a component, and then give the XYZ coordinates of a point in the component and finally put the results on a drawing sheet. We make electrodes for our EDM process in UG, but then we need to give the burn locations to our operators so they can manually load them in the machine. We use a standard part from MoldWizard, but we do not see the need to buy the electrode design package to do what a journal file can do. Does anyone have or know of one?
We design in NX 7.5. on Windows platforms.
Hi,
Hi,
I need to create associative points(x,y,z) by reading the ms exel file,
(The points are specified in the pdf file. i need to copy and paste the points from pdf to XL file.) if i run the journal the Associative points should be creted based on the Xl data.
please help.
Thanks,
Suresh G
re: Excel points
Is this an external Excel file, or the one associated to the part (Tools -> Spreadsheet)?
What exactly do you mean by "associative points"? You can read the Excel file and create either dumb points or point features, but I don't think there is a way to make the point objects associative to the Excel file...
Dimension Breaking in NX
Hi, we used to break the intersecting dimensions by using Gap option in NX. Is there any way to automate this by selecting two dimensions and and the intersetion point?
Stay Hungry
Stay Foolish
Point Selection
Folks
I have a question to put to you all, below are 'two' routines that are both to be used to select (single) points,
from a point I would like to obtain the Point Tag Value and Point Name . The selection methods are different as
I want to see what limitations each method might have and how they behave.
my question is why is the 'Tag returned value' different in each case , as I selected the same point each time
I ran both journals, I was expecting to get the same values in both cases , but did not.
Also the JournalIdentifier is different in both cases & the Name Property from the 'Selection by Type' doesnt return anything...
Is it possible to use the 'selection with mask' routine but return/obtain through further code, the correct Tag
value from the 'selection with Type' method ?
The value from the 'selection with Type' method is correct and is recognised by other code when executed,
the 'selection with Mask' Tag value is not valid and not recognised when referenced with other code .........
Any help or comments would be great...
Best Regards
Simon
-----------------------------------------------------------
Point selection with Mask
-----------------------------------------------------------
ListingWindow Output:
You selected 1 object(s)
Object Tag : 54884
Object Type : NXOpen.Features.PointFeature
Object JournalIdentifier : POINT(1300)
Object Name : POINT(1300)
-----------------------------------------------------------
Option Strict Off
Imports System
Imports NXOpen
'
Module NXJournal
Sub Main()
'
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelectedObjects As NXObject()
'
lw.Open()
'
If SelectObjects("Hey, select Points", mySelectedObjects) = Selection.Response.Ok Then
'
lw.WriteLine("You selected " & mySelectedObjects.Length & " object(s)")
lw.WriteLine("")
'
For Each mySelObj As NXObject In mySelectedObjects
'
If mySelObj.GetType.ToString = "NXOpen.Features.PointFeature" Then
'
Dim PointSelected As String
PointSelected = mySelObj.JournalIdentifier
'
Dim pointFeature1 As Features.PointFeature = CType(workPart.Features.FindObject(PointSelected), _
Features.PointFeature)
Dim Pointname As String
Pointname = pointFeature1.GetFeatureName.ToString
Pointname = UCase(Pointname)
'
lw.WriteLine("Object Tag : " & mySelObj.Tag)
lw.WriteLine("Object Type : " & mySelObj.GetType.ToString)
lw.WriteLine("Object JournalIdentifier : " & mySelObj.JournalIdentifier)
lw.WriteLine("Object Name : " & Pointname)
'
End If
'
Next
'
End If
'
lw.Close()
'
End Sub
'
Function SelectObjects(ByVal prompt As String, ByRef selObj As NXObject()) As Selection.Response
'
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.Features}
'
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, False, typeArray, selobj)
'
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
'
End Function
End Module
-----------------------------------------------------------
Point selection by Type
-----------------------------------------------------------
ListingWindow Output:
Object Tag : 32447
Object Type : NXOpen.Point
Object JournalIdentifier : HANDLE R-29061
Object Name :
Object Coordinates.X : -14.3433828392201
Object Coordinates.Y : 4.97307988411577
Object Coordinates.Z : 495.087618443057
Object General : Point 32447
-----------------------------------------------------------
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.Features
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
'
Module Module1
Sub Main()
'
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
'
Dim myPoint As Point
'
If SelectPoint("", myPoint) = Selection.Response.Cancel Then
Exit Sub
End If
'
lw.Open()
'
lw.WriteLine("")
lw.WriteLine("Object Tag : " & myPoint.Tag)
lw.WriteLine("Object Type : " & myPoint.GetType.ToString)
lw.WriteLine("Object JournalIdentifier : " & myPoint.JournalIdentifier)
lw.WriteLine("Object Name : " & myPoint.Name)
lw.WriteLine("Object Coordinates.X : " & myPoint.Coordinates.X.ToString)
lw.WriteLine("Object Coordinates.Y : " & myPoint.Coordinates.Y.ToString)
lw.WriteLine("Object Coordinates.Z : " & myPoint.Coordinates.Z.ToString)
lw.WriteLine("Object General : " & myPoint.ToString)
'
lw.Close()
'
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.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
'
With selectionMask_array(0)
.Type = UFConstants.UF_point_type
.Subtype = 0
.SolidBodySubtype = 0
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
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
'
End Module
re: Point Selection
...why is the 'Tag returned value' different in each case , as I selected the same point each time...
Actually, if you double check your output, in the first journal you selected an object of type: NXOpen.Features.PointFeature
and in the 2nd journal you selected an object of type: NXOpen.Point
The first one is the point feature (which contains a point object) and the 2nd one is the point object itself. NX automatically assigns names to features (it is what shows up in the feature tree) but not to other objects (points, curves, edges, faces, bodies, etc). This explains why the first journal reported a name, but the 2nd did not.
re:re: PointSelection
Thanks for the feed back...Simon