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
Please note that my email provider is very suspicious of .vb files and will block them (even if they reside in a .zip file). Please change the extension of journal files from ".vb" to ".txt" before sending. Thanks!
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 intellectual 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
Carlo Tony Daristotile
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
Convert 32 bit Journal to 64 bit
When I create a journal in 32 bit the same cannot be used for 64 bit. What are the necessary changes I have to make to work both in 32 & 64 bit.
Stay Hungry
Stay Foolish
re: 32 vs 64 bit
Are you compiling your journal to a .dll or .exe? If so, there should be options for the target platform.
re: 32 vs 64 bit
No I use the journal to execute some tasks. I dont want to create any .dll or .exe.
Stay Hungry
Stay Foolish
re: 32 vs 64 bit
Check to see that you have current versions of the .NET framework libraries installed. You may need to install a newer version of the framework and/or apply patches to existing versions.
Gaps in Dimensions
We are having a tool to create Gaps in dimensions. But we need few more changes.
1. We want to give a user input for Length and Height of the symbol. This user input should not be activated seperately.
2. I want to select multple dimensions
3. Move option should also highlight
Find the Image for more details.
Gap options.jpg
Find the code below.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Annotations
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
'lw.Open()
' Select the dimension
Dim dim1 As Dimension
While select_a_dimension("Select Dimension", dim1) = Selection.Response.Ok
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible,"Break Dimension")
' Select the location
Dim location As Point3d
pick_screen_position(location)
'lw.WriteLine("Dimension: " & dim1.ToString())
'lw.WriteLine("Position: X=" & location.x.ToString() & " Y=" &location.y.ToString())
' Create the symbol
ufs.Drf.SetUgdefaultSbfFile()
Dim symbol_data As UFDrf.SymbolCreateData
ufs.Drf.InitSymbolCreateData(symbol_data)
symbol_data.length = 3
symbol_data.height = 3
Dim anchor As Point = workPart.Points.CreatePoint(location)
symbol_data.anchor_tag = anchor.Tag
symbol_data.symbol_name = "GAP25"
Dim symbol_tag As Tag
ufs.Drf.PlaceSymbol(symbol_data, False, False, symbol_tag)
ufs.Drf.AddSymbolToObject(symbol_data, dim1.Tag)
End While
End Sub
Function select_a_dimension(ByVal prompt As String, ByRef obj As Dimension)
Dim ui As UI = GetUI()
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_dimension_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject(prompt, prompt, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, obj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function pick_screen_position(ByRef location As Point3d) As Selection.Response
Dim ui As UI = GetUI()
Dim resp As Selection.DialogResponse = Selection.DialogResponse.None
Dim localView As View
resp = ui.SelectionManager.SelectScreenPosition("Pick Position:",localView, location)
location.X = location.X - 0.0
location.Y = location.Y - 0.0
If resp <> Selection.DialogResponse.Back And _
resp <> Selection.DialogResponse.Cancel Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
Stay Hungry
Stay Foolish
re: Gaps in Dimensions
1. What if an input box for the symbol height (and one for the width) popped up at the beginning of the journal and the input was used for each subsequent symbol that was created? Would this be acceptable?
2. The journal currently lets you select a dimension and a location and loops until you press cancel. How do you envision selecting multiple dimensions would work? In other words, what do you want the journal to do that it doesn't currently do?
3. I don't see a move option. Exactly what would move/highlight?
re: Gaps in Dimensions
1. Your suggestion is wonderful. But I am looking something similar to Leader Line creation. It will pop up a Input box to change the Stub length. It would be much useful if we getting a option similar to this. If I can add an image it would be very easy to understand. If you need I will send through mail.
2. Your comment is true.
3. It is in Edit ------ Component ------ Move option. To move this symbol I have select this option. Is there any chance to integrate this tool also into the code?
Stay Hungry
Stay Foolish
delete text
Okay, question, so how do I get rid of this handle (HANDLE R-3139) so I can run this journal on many other files?
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
' ----------------------------------------------
' Menu: Edit->Delete...
' ----------------------------------------------
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
Dim objects1(0) As NXObject
Dim note1 As Annotations.Note = CType(workPart.FindObject("HANDLE R-3139"), Annotations.Note)
objects1(0) = note1
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)
Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
Paul Fillion
re: delete text
You will need to find and pass in the desired note object that you want deleted. Probably the easiest way is to add an interactive selection function and let the user select a note. However, the advantage of programming NX is that you can automate the selection of this note object. So the question becomes, what note object do you want to delete? How can we find it programmatically? Does it contain certain text? Does it have a certain attribute associated with it? Is it in a particular position on the sheet? Are there multiple notes that you would like to delete, if so what do they have in common? all on a certain layer, all of a certain color, etc etc?
Once you know the characteristic(s) of the note(s) you want to delete, you can iterate through the notes collection and test each one against your criteria.
delete text
The text is unique and says (PRELIMINARY). The text is always in the same location. Maybe call out a selection box or fence to delete
Paul Fillion
re: delete text
If you would like to automatically find and delete the note, the code is below.
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const noteText As String = "(PRELIMINARY)"
For Each tempNote As Annotations.Note In workPart.Notes
Dim tempText() As String = tempNote.GetText
If tempText(0) = noteText Then
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList({tempNote})
Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
End If
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module
delete text
I tried the code above and I am getting this error
Line 34: Expression expected.
When I have it in visual studio the { is highlighted as the problem I just do not know what I could replace it with
Paul Fillion
delete text got it
I got it!! This is the code that worked. Thanks so much
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const noteText As String = "PRELIMINARY"
For Each tempNote As Annotations.Note In workPart.Notes
Dim tempText() As String = tempNote.GetText
If tempText(0) = noteText Then
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(tempNote)
Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
End If
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module
Paul Fillion
oops
Seems that depending on your version, the {} syntax may or may not work. Sorry about that; glad you got it fixed up!
I am so close. The first sub
I am so close. The first sub main deletes the bad text fine but my sub import () will not start. I am not sure why, I am not getting any error codes?
Option Strict Off
Imports System
Imports NXOpen
Module delete_prelim
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const noteText As String = "PRELIMINARY"
For Each tempNote As Annotations.Note In workPart.Notes
Dim tempText() As String = tempNote.GetText
If tempText(0) = noteText Then
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(tempNote)
Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
End If
Next
lw.Close()
End Sub
'------------------------------------------------------------------------------
Sub Import ()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: File->Import->Part...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Import Part")
Dim importer1 As Importer
importer1 = workPart.ImportManager.CreatePartImporter()
Dim partImporter1 As PartImporter = CType(importer1, PartImporter)
partImporter1.FileName = "C:\UGDefault\PRELIM.prt"
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = True
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work
Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)
partImporter1.DestinationCoordinateSystem = nXMatrix1
Dim destinationPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")
Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)
partImporter1.Destroy()
' ----------------------------------------------
' Menu: View->Operation->Fit
' ----------------------------------------------
workPart.Views.WorkView.Fit()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module
Paul Fillion
re: calling the subroutine
Now that you have created a subroutine, you must call it in sub Main. Subroutines and functions are a great way to create reusable code, but they do not get executed automatically. Sub Main is called automatically by NX when your journal starts; it then acts as the 'traffic cop' which can call other subroutines/functions as necessary.
In pseudocode, it would look something like this:
Sub Main()
'initialize global variables
'get input
'call functions/subs as necessary
Import
'or alternately,
Call Import
'handle errors
'cleanup
End Sub
'------------------------------------------------------------------------------
Sub Import ()
'initialize sub level variables
'perform calculation
'call other sub/functions as necessary
'do other stuff
End Sub
Yes that worked great!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I have learned so much during this exercise ! This was a real eye opener on how to work with the Sub Main () and Sub Custom with call thank you again!!! I like creating libraries of subs and then pulling them out as needed. I was hoping to use them with your batch file processor vb.
Option Strict Off
Imports System
Imports NXOpen
Module delete_prelim
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const noteText As String = "PRELIMINARY"
For Each tempNote As Annotations.Note In workPart.Notes
Dim tempText() As String = tempNote.GetText
If tempText(0) = noteText Then
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(tempNote)
Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
End If
Next
lw.Close()
Call import()
End Sub
'------------------------------------------------------------------------------
Sub Import ()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: File->Import->Part...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Import Part")
Dim importer1 As Importer
importer1 = workPart.ImportManager.CreatePartImporter()
Dim partImporter1 As PartImporter = CType(importer1, PartImporter)
partImporter1.FileName = "C:\UGDefault\PRELIM.prt"
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = True
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work
Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)
partImporter1.DestinationCoordinateSystem = nXMatrix1
Dim destinationPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")
Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)
partImporter1.Destroy()
' ----------------------------------------------
' Menu: View->Operation->Fit
' ----------------------------------------------
workPart.Views.WorkView.Fit()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module
Paul Fillion
NXCAE Application - Move Element
Hi, this is my first application. Although the code it is not properly structured, somehow it worked. My video that demonstrate this application as below:
http://www.youtube.com/watch?v=3I0fKw2QbWE&feature=youtu.be
Code as below:
' NX 9.0.1.3
' Journal created by Tuw on Wed Apr 16 17:18:43 2014 Malay Peninsula Standard Time
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.BlockStyler
Module NXJournal
Public from_csys() As NXOpen.TaggedObject
Public to_csys() As NXOpen.TaggedObject
Public SelectedNodes() As NXOpen.CAE.FENode
Public sourceCsys As CartesianCoordinateSystem
Public endCsys As CartesianCoordinateSystem
Sub Main(ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim objectsToTransform(0) As DisplayableObject
Dim theElementTRansformation As Transform_Element_Dialog
Try
theElementTRansformation = New Transform_Element_Dialog()
' The following method shows the dialog immediately
theElementTRansformation.Show()
If theElementTRansformation.SelectedNodes.Length < 1 Then Return
ReDim objectsToTransform(theElementTRansformation.SelectedNodes.Length - 1)
Dim Idx As Integer
Idx = 0
For Each Item As NXOpen.CAE.FENode In theElementTRansformation.SelectedNodes
objectsToTransform(Idx) = CType(Item, Object)
Idx = Idx + 1
Next
Catch ex As Exception
'---- Enter your exception handling code here -----
Finally
theElementTRansformation.Dispose()
End Try
End Sub
Public Class Transform_Element_Dialog
'class members
Public from_csys() As NXOpen.TaggedObject
Public to_csys() As NXOpen.TaggedObject
Public SelectedNodes() As NXOpen.CAE.FENode
Public sourceCsys As CartesianCoordinateSystem
Public endCsys As CartesianCoordinateSystem
Private Shared theSession As Session
Private Shared theUI As UI
Private theDlxFileName As String
Private theDialog As NXOpen.BlockStyler.BlockDialog
Private Block01 As NXOpen.BlockStyler.Group ' Block type: Group
Private selectNodes0 As NXOpen.BlockStyler.SelectNode ' Block type: Select Nodes
Private Block02 As NXOpen.BlockStyler.Group ' Block type: Group
Private coord_system0 As NXOpen.BlockStyler.SpecifyCSYS ' Block type: Specify Csys
Private Block03 As NXOpen.BlockStyler.Group ' Block type: Group
Private coord_system01 As NXOpen.BlockStyler.SpecifyCSYS ' Block type: Specify Csys
#Region "Block Styler Dialog Designer generator code"
'------------------------------------------------------------------------------
'Constructor for NX Styler class
'------------------------------------------------------------------------------
Public Sub New()
Try
theSession = Session.GetSession()
theUI = UI.GetUI()
theDlxFileName = "Transform_Element.dlx"
theDialog = theUI.CreateDialog(theDlxFileName)
theDialog.AddApplyHandler(AddressOf apply_cb)
theDialog.AddOkHandler(AddressOf ok_cb)
theDialog.AddUpdateHandler(AddressOf update_cb)
theDialog.AddInitializeHandler(AddressOf initialize_cb)
theDialog.AddDialogShownHandler(AddressOf dialogShown_cb)
Catch ex As Exception
'---- Enter your exception handling code here -----
Throw ex
End Try
End Sub
#End Region
'------------------------------- DIALOG LAUNCHING ---------------------------------
'
' Before invoking this application one needs to open any part/empty part in NX
' because of the behavior of the blocks.
'
' Make sure the dlx file is in one of the following locations:
' 1.) From where NX session is launched
' 2.) $UGII_USER_DIR/application
' 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
' recommended. This variable is set to a full directory path to a file
' containing a list of root directories for all custom applications.
' e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat
'
' You can create the dialog using one of the following way:
'
' 1. Journal Replay
'
' 1) Replay this file through Tool->Journal->Play Menu.
'
' 2. USER EXIT
'
' 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
' 2) Invoke the Shared Library through File->Execute->NX Open menu.
'
'------------------------------------------------------------------------------
Public Shared Sub xxxxMain()
Dim theTransform_Element As Transform_Element_Dialog = Nothing
Try
theTransform_Element = New Transform_Element_Dialog()
' The following method shows the dialog immediately
theTransform_Element.Show()
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
Finally
If theTransform_Element IsNot Nothing Then
theTransform_Element.Dispose()
theTransform_Element = Nothing
End If
End Try
End Sub
'------------------------------------------------------------------------------
' This method specifies how a shared image is unloaded from memory
' within NX. This method gives you the capability to unload an
' internal NX Open application or user exit from NX. Specify any
' one of the three constants as a return value to determine the type
' of unload to perform:
'
'
' Immediately : unload the library as soon as the automation program has completed
' Explicitly : unload the library from the "Unload Shared Image" dialog
' AtTermination : unload the library when the NX session terminates
'
'
' NOTE: A program which associates NX Open applications with the menubar
' MUST NOT use this option since it will UNLOAD your NX Open application image
' from the menubar.
'------------------------------------------------------------------------------
Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
'Return CType(Session.LibraryUnloadOption.Explicitly, Integer)
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
' Return CType(Session.LibraryUnloadOption.AtTermination, Integer)
End Function
'------------------------------------------------------------------------------
' Following method cleanup any housekeeping chores that may be needed.
' This method is automatically called by NX.
'------------------------------------------------------------------------------
Public Shared Sub UnloadLibrary(ByVal arg As String)
Try
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'This method shows the dialog on the screen
'------------------------------------------------------------------------------
Public Sub Show()
Try
theDialog.Show()
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'Method Name: Dispose
'------------------------------------------------------------------------------
Public Sub Dispose()
If theDialog IsNot Nothing Then
theDialog.Dispose()
theDialog = Nothing
End If
End Sub
'------------------------------------------------------------------------------
'---------------------Block UI Styler Callback Functions--------------------------
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'Callback Name: initialize_cb
'------------------------------------------------------------------------------
Public Sub initialize_cb()
Try
Block01 = CType(theDialog.TopBlock.FindBlock("Block01"), NXOpen.BlockStyler.Group)
selectNodes0 = CType(theDialog.TopBlock.FindBlock("selectNodes0"), NXOpen.BlockStyler.SelectNode)
Block02 = CType(theDialog.TopBlock.FindBlock("Block02"), NXOpen.BlockStyler.Group)
coord_system0 = CType(theDialog.TopBlock.FindBlock("coord_system0"), NXOpen.BlockStyler.SpecifyCSYS)
Block03 = CType(theDialog.TopBlock.FindBlock("Block03"), NXOpen.BlockStyler.Group)
coord_system01 = CType(theDialog.TopBlock.FindBlock("coord_system01"), NXOpen.BlockStyler.SpecifyCSYS)
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'Callback Name: dialogShown_cb
'This callback is executed just before the dialog launch. Thus any value set
'here will take precedence and dialog will be launched showing that value.
'------------------------------------------------------------------------------
Public Sub dialogShown_cb()
Try
'---- Enter your callback code here -----
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'Callback Name: apply_cb
'------------------------------------------------------------------------------
Public Function apply_cb() As Integer
Dim errorCode As Integer = 0
Try
'---- Enter your callback code here -----
selectNodes0 = CType(theDialog.TopBlock.FindBlock("selectNodes0"), NXOpen.BlockStyler.SelectNode)
Dim propertyList As BlockStyler.PropertyList
propertyList = selectNodes0.GetProperties()
Dim myselectednodes As NXOpen.TaggedObject()
myselectednodes = propertyList.GetTaggedObjectVector("SelectedObjects")
Dim Lng As Integer = 0
ReDim SelectedNodes(myselectednodes.Length + 1)
For Each Item As NXOpen.TaggedObject In myselectednodes
Try
Dim Node As NXOpen.CAE.FENode = CType(Item, NXOpen.CAE.FENode)
If Node Is Nothing Then
' Error of some sort
Else
SelectedNodes(Lng) = Node
Lng = Lng + 1
End If
Catch ex As Exception
End Try
Next
'MsgBox("now lng is " + Lng.ToString)
Block02 = CType(theDialog.TopBlock.FindBlock("Block02"), NXOpen.BlockStyler.Group)
coord_system0 = CType(theDialog.TopBlock.FindBlock("coord_system0"), NXOpen.BlockStyler.SpecifyCSYS)
Block03 = CType(theDialog.TopBlock.FindBlock("Block03"), NXOpen.BlockStyler.Group)
coord_system01 = CType(theDialog.TopBlock.FindBlock("coord_system01"), NXOpen.BlockStyler.SpecifyCSYS)
Dim propertyList02 As BlockStyler.PropertyList
propertyList02 = coord_system0.GetProperties()
from_csys = propertyList02.GetTaggedObjectVector("SelectedObjects")
Dim sourceCsys As CartesianCoordinateSystem
sourceCsys = CType(from_csys(0), CoordinateSystem)
'MsgBox("Check this " + Chr(10) + sourceCsys.Origin.ToString)
Dim propertyList03 As BlockStyler.PropertyList
propertyList03 = coord_system01.GetProperties()
to_csys = propertyList03.GetTaggedObjectVector("SelectedObjects")
Dim endCsys As CartesianCoordinateSystem
endCsys = CType(to_csys(0), CoordinateSystem)
Dim workFemPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart)
Dim displayFemPart As CAE.FemPart = CType(theSession.Parts.BaseDisplay, CAE.FemPart)
' ----------------------------------------------
' Menu: Insert->Node->Create...
' ----------------------------------------------
Dim fEModel1 As CAE.FEModel = CType(workFemPart.FindObject("FEModel"), CAE.FEModel)
Dim nodeCreateBuilder1 As CAE.NodeCreateBuilder
nodeCreateBuilder1 = fEModel1.NodeElementMgr.CreateNodeCreateBuilder()
nodeCreateBuilder1.Label = 900001
nodeCreateBuilder1.X.RightHandSide = "1"
nodeCreateBuilder1.Y.RightHandSide = "0"
nodeCreateBuilder1.Z.RightHandSide = "0"
nodeCreateBuilder1.TAngle.RightHandSide = "0"
nodeCreateBuilder1.PAngle.RightHandSide = "0"
Dim unit1 As Unit
unit1 = nodeCreateBuilder1.Z.Units
Dim expression1 As Expression
expression1 = workFemPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = sourceCsys
Dim xform1 As Xform
xform1 = workFemPart.Xforms.CreateXform(cartesianCoordinateSystem1, SmartObject.UpdateOption.AfterModeling)
Dim cartesianCoordinateSystem2 As CartesianCoordinateSystem
cartesianCoordinateSystem2 = workFemPart.CoordinateSystems.CreateCoordinateSystem(xform1, SmartObject.UpdateOption.AfterModeling)
nodeCreateBuilder1.Csys = cartesianCoordinateSystem2
Dim nXObject1 As NXObject
nXObject1 = nodeCreateBuilder1.Commit()
Dim nullCoordinateSystem As CoordinateSystem = Nothing
nodeCreateBuilder1.Csys = nullCoordinateSystem
nodeCreateBuilder1.Csys = cartesianCoordinateSystem2
nodeCreateBuilder1.Destroy()
workFemPart.Expressions.Delete(expression1)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
' ----------------------------------------------
' Menu: Insert->Node->Create...
' ----------------------------------------------
Dim fEModel1a As CAE.FEModel = CType(workFemPart.FindObject("FEModel"), CAE.FEModel)
Dim nodeCreateBuilder1a As CAE.NodeCreateBuilder
nodeCreateBuilder1a = fEModel1a.NodeElementMgr.CreateNodeCreateBuilder()
nodeCreateBuilder1a.Label = 900002
nodeCreateBuilder1a.X.RightHandSide = "0"
nodeCreateBuilder1a.Y.RightHandSide = "1"
nodeCreateBuilder1a.Z.RightHandSide = "0"
nodeCreateBuilder1a.TAngle.RightHandSide = "0"
nodeCreateBuilder1a.PAngle.RightHandSide = "0"
Dim unit1a As Unit
unit1a = nodeCreateBuilder1a.Z.Units
Dim expression1a As Expression
expression1a = workFemPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim cartesianCoordinateSystem1a As CartesianCoordinateSystem = sourceCsys
Dim xform1a As Xform
xform1a = workFemPart.Xforms.CreateXform(cartesianCoordinateSystem1a, SmartObject.UpdateOption.AfterModeling)
Dim cartesianCoordinateSystem2a As CartesianCoordinateSystem
cartesianCoordinateSystem2a = workFemPart.CoordinateSystems.CreateCoordinateSystem(xform1a, SmartObject.UpdateOption.AfterModeling)
nodeCreateBuilder1a.Csys = cartesianCoordinateSystem2a
Dim nXObject1a As NXObject
nXObject1a = nodeCreateBuilder1a.Commit()
Dim nullCoordinateSystema As CoordinateSystem = Nothing
nodeCreateBuilder1a.Csys = nullCoordinateSystema
nodeCreateBuilder1a.Csys = cartesianCoordinateSystem2a
nodeCreateBuilder1a.Destroy()
workFemPart.Expressions.Delete(expression1a)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
Dim index As Integer = Lng
Dim Node900001 As CAE.FENode = CType(fEModel1.Find("Node[900001]"), CAE.FENode)
Dim Node900002 As CAE.FENode = CType(fEModel1.Find("Node[900002]"), CAE.FENode)
SelectedNodes(index) = Node900001
index = index + 1
SelectedNodes(index) = Node900002
' ----------------------------------------------
' Menu: Edit->Node->Translate...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nodeTranslateBuilder1 As CAE.NodeTranslateBuilder
nodeTranslateBuilder1 = fEModel1.NodeElementMgr.CreateNodeTranslateBuilder()
nodeTranslateBuilder1.ScaleFactor = 1.0
nodeTranslateBuilder1.NumCopy = 1
nodeTranslateBuilder1.XScaleFactor = 1.0
nodeTranslateBuilder1.YScaleFactor = 1.0
nodeTranslateBuilder1.ZScaleFactor = 1.0
nodeTranslateBuilder1.XDistance.RightHandSide = "1"
nodeTranslateBuilder1.Label = 256
nodeTranslateBuilder1.Increment = 1
nodeTranslateBuilder1.Offset = 1
nodeTranslateBuilder1.MethodOption = CAE.NodeTranslateBuilder.MethodType.AlignVectors
nodeTranslateBuilder1.XDistance.RightHandSide = "0"
nodeTranslateBuilder1.YDistance.RightHandSide = "-25"
nodeTranslateBuilder1.ZDistance.RightHandSide = "0"
nodeTranslateBuilder1.TAngle.RightHandSide = "0"
nodeTranslateBuilder1.PAngle.RightHandSide = "0"
theSession.SetUndoMarkName(markId1, "Node Translate Dialog")
Dim unit1b As Unit
unit1b = nodeTranslateBuilder1.ZDistance.Units
Dim expression1b As Expression
expression1b = workFemPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim origin1 As Point3d
origin1 = sourceCsys.Origin
'MsgBox("origin1 is " + Chr(10) + origin1.ToString)
Dim from_x As Vector3d
Dim from_y As Vector3d
'MsgBox(sourceCsys.ToString)
'Dim matrix As NXOpen.NXMatrix = sourceCsys.Orientation
sourceCsys.GetDirections(from_x, from_y)
'MsgBox("from_x is " + Chr(10) + from_x.ToString)
Dim vector1 As Vector3d = from_x
Dim direction1 As Direction
direction1 = workFemPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.AfterModeling)
nodeTranslateBuilder1.VectorSource = direction1
Dim expression2 As Expression
expression2 = workFemPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim origin2 As Point3d = endCsys.Origin
Dim to_x As Vector3d
Dim to_y As Vector3d
endCsys.GetDirections(to_x, to_y)
Dim vector2 As Vector3d = to_x
Dim direction2 As Direction
direction2 = workFemPart.Directions.CreateDirection(origin2, vector2, SmartObject.UpdateOption.AfterModeling)
nodeTranslateBuilder1.VectorTarget = direction2
Dim added1 As Boolean
added1 = nodeTranslateBuilder1.Node.Add(SelectedNodes)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Node Translate")
theSession.DeleteUndoMark(markId2, Nothing)
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Node Translate")
Dim nXObject1c As NXObject
nXObject1c = nodeTranslateBuilder1.Commit()
theSession.DeleteUndoMark(markId3, Nothing)
theSession.SetUndoMarkName(markId1, "Node Translate")
nodeTranslateBuilder1.Destroy()
workFemPart.Expressions.Delete(expression1b)
workFemPart.Expressions.Delete(expression2)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
Dim new_x_vector As Vector3d
new_x_vector.X = Node900001.Coordinates.X - endCsys.Origin.X
new_x_vector.Y = Node900001.Coordinates.Y - endCsys.Origin.Y
new_x_vector.Z = Node900001.Coordinates.Z - endCsys.Origin.Z
Dim new_y_vector As Vector3d
new_y_vector.X = Node900002.Coordinates.X - endCsys.Origin.X
new_y_vector.Y = Node900002.Coordinates.Y - endCsys.Origin.Y
new_y_vector.Z = Node900002.Coordinates.Z - endCsys.Origin.Z
'MsgBox(new_x_vector.ToString + Chr(10) + new_y_vector.ToString)
' ----------------------------------------------
' Menu: Edit->Node->Translate...
' ----------------------------------------------
Dim nodeTranslateBuilder1d As CAE.NodeTranslateBuilder
nodeTranslateBuilder1d = fEModel1.NodeElementMgr.CreateNodeTranslateBuilder()
nodeTranslateBuilder1d.ScaleFactor = 1.0
nodeTranslateBuilder1d.NumCopy = 1
nodeTranslateBuilder1d.XScaleFactor = 1.0
nodeTranslateBuilder1d.YScaleFactor = 1.0
nodeTranslateBuilder1d.ZScaleFactor = 1.0
nodeTranslateBuilder1d.XDistance.RightHandSide = "1"
nodeTranslateBuilder1d.Label = 256
nodeTranslateBuilder1d.Increment = 1
nodeTranslateBuilder1d.Offset = 1
nodeTranslateBuilder1d.MethodOption = CAE.NodeTranslateBuilder.MethodType.AlignVectors
nodeTranslateBuilder1d.XDistance.RightHandSide = "0"
nodeTranslateBuilder1d.YDistance.RightHandSide = "-25"
nodeTranslateBuilder1d.ZDistance.RightHandSide = "0"
nodeTranslateBuilder1d.TAngle.RightHandSide = "0"
nodeTranslateBuilder1d.PAngle.RightHandSide = "0"
theSession.SetUndoMarkName(markId1, "Node Translate Dialog")
Dim unit1bd As Unit
unit1bd = nodeTranslateBuilder1d.ZDistance.Units
Dim expression1bd As Expression
expression1bd = workFemPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim origin1d As Point3d
origin1d = endCsys.Origin
'MsgBox("origin1 is " + Chr(10) + origin1.ToString)
Dim from_xd As Vector3d
Dim from_yd As Vector3d
'MsgBox(sourceCsys.ToString)
'Dim matrix As NXOpen.NXMatrix = sourceCsys.Orientation
from_xd = new_x_vector
from_yd = new_y_vector
'MsgBox("from_x is " + Chr(10) + from_x.ToString)
Dim vector1d As Vector3d = from_yd
Dim direction1d As Direction
direction1d = workFemPart.Directions.CreateDirection(origin1d, vector1d, SmartObject.UpdateOption.AfterModeling)
nodeTranslateBuilder1d.VectorSource = direction1d
Dim expression2d As Expression
expression2d = workFemPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim origin2d As Point3d = endCsys.Origin
Dim to_xd As Vector3d
Dim to_yd As Vector3d
endCsys.GetDirections(to_xd, to_yd)
Dim vector2d As Vector3d = to_yd
Dim direction2d As Direction
direction2d = workFemPart.Directions.CreateDirection(origin2d, vector2d, SmartObject.UpdateOption.AfterModeling)
nodeTranslateBuilder1d.VectorTarget = direction2d
Dim added1d As Boolean
added1d = nodeTranslateBuilder1d.Node.Add(SelectedNodes)
Dim nXObject1cd As NXObject
nXObject1cd = nodeTranslateBuilder1d.Commit()
nodeTranslateBuilder1d.Destroy()
workFemPart.Expressions.Delete(expression1bd)
workFemPart.Expressions.Delete(expression2d)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
' delete reference node 900001 and 900002
Dim nodeDeleteBuilder1 As CAE.NodeDeleteBuilder
nodeDeleteBuilder1 = fEModel1.NodeElementMgr.CreateNodeDeleteBuilder()
nodeDeleteBuilder1.Node.Clear()
Dim objects1(1) As CAE.FENode
objects1(0) = Node900001
objects1(1) = Node900002
Dim added2 As Boolean
added2 = nodeDeleteBuilder1.Node.Add(objects1)
Dim nXObject1z As NXObject
nXObject1z = nodeDeleteBuilder1.Commit()
nodeDeleteBuilder1.Destroy()
Catch ex As Exception
'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function
'------------------------------------------------------------------------------
'Callback Name: update_cb
'------------------------------------------------------------------------------
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try
If block Is selectNodes0 Then
'---- Enter your code here -----
ElseIf block Is coord_system0 Then
'---- Enter your code here -----
ElseIf block Is coord_system01 Then
'---- Enter your code here -----
End If
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
update_cb = 0
End Function
'------------------------------------------------------------------------------
'Callback Name: ok_cb
'------------------------------------------------------------------------------
Public Function ok_cb() As Integer
Dim errorCode As Integer = 0
Try
'---- Enter your callback code here -----
errorCode = apply_cb()
Catch ex As Exception
'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
ok_cb = errorCode
End Function
'------------------------------------------------------------------------------
'Function Name: GetBlockProperties
'Returns the propertylist of the specified BlockID
'------------------------------------------------------------------------------
Public Function GetBlockProperties(ByVal blockID As String) As PropertyList
GetBlockProperties = Nothing
Try
GetBlockProperties = theDialog.GetBlockProperties(blockID)
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Function
End Class
End Module
Beginner of NX journalling
I am new to NX journalling. I want to create a point in sketch mode and exit the sketch mode using NX journalling. Can anyone help me out??
re: sketch journal
Try recording a journal and studying the resulting code. Post back with any specific questions.
Need NX API to access reuse library
Hello All,
I need to access reuse library through NX. are there any API's to do the same. I'm using NX8.5 with C++ VS2010. I'm not allowed ITK calls but only with NX API. Please let me know your coments.
Thanks in advance.
NX with C# .net
How to open NX9 application using C# .Net code
Get list of selected object for the LightWeightSection in NX
Hi,
I want to fetch the object list which is selected for the LightWeightSection, is there any API available?
Thanks,
Sandip
re: light weight section
If you edit the section with a LightweightSectionBuilder, you should be able to access the objects that are sectioned with code such as:
Dim sectionObjects() As DisplayableObject = theLSBuilder.ObjectsToSection.GetArray()
Donation
I want to make some donations to your site from my personal money since I use your website extensively. Thanks.
I get this error when I click paypal button on you website. Can you please resolve it?
-----------------------------------------------
Error Detected
Error Message
We were unable to decrypt the certificate id.
We were unable to decrypt the certificate id.
-----------------------------------------------
Regards
Vikas
re: thanks
Thanks for making me aware of the problem, I'm looking into it.
I'm glad that you find the website useful.
re: donate button
It appears that I made a copy & paste error in the button code in the last site update. The button should be fully operational now. Everyone should give it a try! ; )
Lock option on the views
In arrangement drawing having more than 10 sheets, it is difficult to update all the views and sheets for every minor change in 3D model. Even the change does not effect the view , it will turn to Out of date
nagalakshmi rajeswari majeti
Pages