This blog post is the first part of  3 part series on NX Journaling

The aim of this blog post is to select a part.

 

Before writing codes for journals, it’s easier to create a journal and then look at its code.

In NX 10.0, start recording a journal from tools -> journal

Do the operations that you want to repeat, and stop the recording of the journal from tools -> journal

Look at the code created from the operations at tools -> journal -> edit

The code might look like this: (Visual basic code)

' NX 10.0.0.24
' Journal created by Achyuthuni on Sun Jul 08 14:29:00 2018 India Standard Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: File->Show Dimensions
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Show Dimensions")

Dim extrude1 As NXOpen.Features.Extrude = CType(workPart.Features.FindObject("EXTRUDE(2)"), NXOpen.Features.Extrude)

extrude1.ShowDimensions()

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

This article helps in understanding more about understanding what each line of the code does, do read it if the above lines of code boggles you.

Our aim now is to modify this code to let user select the part that he requires, and to display its name in a popup window.

A listing window is a window like a popup which we are using to display dimensions.

getSelectedObject is a function that gets the selected object. This example aslo demonstrates how to write functions in VB.

Once the part is selected, its name and type are selected in the Listing window.

' NX 10.0.0.24 
' Journal created by Achyuthuni on Sun Jul 08 14:29:00 2018 India Standard Time 
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

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 mySelectedObject As NXObject

lw.Open
   mySelectedObject = getSelectedObject
   'these are the selections
   lw.WriteLine("Object Tag: " & mySelectedObject.Tag)
   lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
   lw.WriteLine("")
lw.Close

End Sub

Public Function getSelectedObject() as NXObject
   Dim returnSelectedObject As NXObject ' Ut: War daov rMIcrosoft COllection
   SelectAnObject("Please select an object", returnSelectedObject)
   Return returnSelectedObject
End Function

Function SelectAnObject(prompt As String, _
   ByRef selObj As NXObject) As Selection.Response

   Dim theUI As UI = UI.GetUI
   Dim cursor As Point3d
   Dim typeArray() As Selection.SelectionType = _
                      { Selection.SelectionType.All, _
                        Selection.SelectionType.Faces, _
                        Selection.SelectionType.Edges, _
                        Selection.SelectionType.Features }

    Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
                                     prompt, "Selection", _
                                     Selection.SelectionScope.AnyInAssembly, _
                                     False, typeArray, selobj, 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

End Module

The above code can also be found at https://github.com/HarshaAsh/NXBasics

12 Replies to “Selecting a part in NX Journaling”

  1. I precisely had to appreciate you once again. I do not know the things that I would have carried out without these concepts discussed by you relating to such topic. It became a very intimidating condition in my circumstances, but viewing a professional way you resolved it made me to weep with delight. I am happier for this support and thus trust you find out what an amazing job you are always getting into teaching most people thru your web page. Most probably you have never met any of us.

  2. My spouse and i felt fulfilled when Ervin could do his analysis from the ideas he acquired out of your web site. It is now and again perplexing to simply choose to be giving freely concepts that many other folks may have been selling. And we consider we have got the website owner to appreciate for this. The most important illustrations you made, the straightforward site navigation, the relationships you make it easier to foster – it’s got mostly overwhelming, and it’s really facilitating our son and the family feel that this idea is thrilling, which is really important. Thank you for the whole thing!

  3. My spouse and i have been absolutely peaceful that Albert could round up his researching because of the ideas he had in your blog. It is now and again perplexing just to continually be releasing solutions that many many people have been selling. And now we recognize we need the website owner to thank because of that. The type of explanations you’ve made, the easy website menu, the relationships your site help instill – it’s most excellent, and it’s really helping our son and our family understand that content is satisfying, and that’s particularly mandatory. Thanks for the whole thing!

  4. Thank you so much for giving everyone an extremely memorable possiblity to check tips from this web site. It’s always so useful and jam-packed with a lot of fun for me personally and my office friends to visit your web site at least 3 times in 7 days to read through the fresh secrets you have got. And of course, I’m always happy considering the impressive strategies you give. Certain 3 points in this article are in fact the best we have ever had.

  5. I and also my buddies were examining the best helpful tips from your web site and then instantly got a terrible suspicion I never expressed respect to the web blog owner for those techniques. These boys became as a consequence stimulated to read them and now have simply been loving them. Many thanks for being indeed accommodating and for considering this form of outstanding subject areas most people are really eager to learn about. My honest regret for not expressing appreciation to you sooner.

  6. Thank you a lot for giving everyone an extraordinarily brilliant opportunity to check tips from this website. It’s always so terrific and as well , stuffed with a great time for me personally and my office acquaintances to search your website nearly thrice weekly to learn the newest guides you have got. And of course, I am just usually fascinated with your fantastic techniques served by you. Certain 1 facts in this article are undeniably the very best we have all ever had.

  7. I am only commenting to make you be aware of what a superb encounter my wife’s girl gained reading through yuor web blog. She noticed numerous things, which include how it is like to possess a marvelous helping character to have other folks effortlessly learn about specified specialized matters. You truly did more than my expectations. Thanks for imparting such warm and helpful, healthy, revealing and also unique tips on that topic to Sandra.

  8. Thanks so much for providing individuals with a very terrific possiblity to read from here. It really is so awesome and also packed with amusement for me and my office colleagues to search the blog at a minimum three times in 7 days to see the newest tips you have got. Not to mention, I’m also at all times happy with all the excellent tips and hints served by you. Some two facts in this article are absolutely the most efficient I have ever had.

  9. I together with my friends were found to be analyzing the excellent techniques from your web site and then instantly developed an awful suspicion I had not thanked the blog owner for them. All the women had been absolutely warmed to see all of them and have now honestly been making the most of those things. I appreciate you for simply being well thoughtful and for opting for these kinds of extraordinary tips most people are really eager to understand about. Our sincere apologies for not expressing gratitude to you sooner.

Leave a Reply

Your email address will not be published.