Showing results for 
Search instead for 
Do you mean 
Reply

Needed: VB.net Journal to rename Program Groups and operations in NX CAM

I’m looking for a VB.net Journal that will rename the Program Groups and the associated operations in NX CAM.

 

Specifically I need it to rename the Program Group using characters from the filename, which will always be in the same format. Ex. 15010_D-001_00-0_OP4.prt Then append sequential prefix numbers to each assigned operation starting with 01_ thru 99_ If there are more than 99 operations (not likely) leave the remaining unchanged.

 

For a visual, in Pic-1 you see a default Program group name of 1234 and 15 operations. These are in the file 15010_D-001_00-0_OP4.prt. Pic-2 then shows the desired renaming format of the Group and its operations. And Pic-3 shows the Group name format when there are more than one operation.

 

So, I envision the user fire off the journal, it would then prompt for user to select the Program group to be renamed. Once selected, the journal would prompt for a letter to be input which is assigned to position 12 in the Group name [A in the example Pic-2] (If possible, the letter input prompt would only display on the first Group. If there are more groups to follow, they would be assigned the next sequential letter referenced from the group just above) The journal would then, using the first 12 characters from the filename 15010_D-001_ (which then drops the hyphen 15010_D001_), the acquired letter from user input or the next letter based on the previous group listed and the last four characters of the filename _OP4, rename the Program group [15010_D001_A_OP4} and append the sequential prefixes to the operations 01_ . . .02_. .. etc..

 

Any assistance would greatly be appreciated.

Jim Cunningham EPW, llc

19 REPLIES

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

What do you have so far?

Have you already recorded a journal of the manual process to get the needed methods and how to use them.

 

NXOpenUI.NXInputBox does have some basic input dialogs, for more complex things a BlockStyler dialog would be recommended.

 

As I see it you are renaming the program group and their containing operations.

 

The GetMembers() method will return the collection of objects contained in the program group.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

I posted this in Manufacturing, but no response there, so I'll join this thread :*)

 

I would have the user select the program group, then run the journal.

 

Have you looked at the sample that renames operations? This should give you a decent starting point. Just select several operations and jun the journal:

 

...UGOPEN\SampleNXOpenApplications\.NET\CAM\RenameOperationsOntSelection.vb

Mark Rief
Retired Siemens

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

Hi Stefan & Mark,

Thank you both for taking time to respond. Full disclosure, my understanding of the VB code and how it functions, structured etc. is very, very limited. I’ve done some scripting over the years but the VB code is way more advanced and beyond most of my current understanding. I do know that what I’m desiring the Journal ability to perform is going to require more advanced looping, equating and whatever then can be simply record and minimally tweak. Hopefully my level of understanding hasn't caused you wasted effort & time in responding.

 

So in response, all that I've attempted to do is record a Journal that changes a group name. I took Mark's advice and pre-selected the Group node first then started recording the Journal. As long as I have the node pre-selected during playback, the Journal doesn’t care what the current name is, it will rename it to what was input during the recording. That will work for the renaming of the first Group. The most that would have to be changed in the name manually would be the letter "A" to whatever the current available letter is. That's because the next available letter may be based on a group in another previous CAM setup file. If however there are multiple Groups in the current setup file I would like for the Journal to look at the previous group letter above in the list to determine the letter to now be used.

 

I also recorded one without having the node pre-selected just to compare and it’s always looking for a group name matching the name recorded.

 

Mark, I ran your suggested Journal to see what it does. It doesn’t do what I’m looking for but maybe it’s something to start / work with. I just don’t know how to proceed with it.

 

Thanks again Gentlemen

Jim 

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

[ Edited ]

Sorry Mark,

I wasn't getting email notifications of your or Stefan's  postings Popped in for a looksee an there were postings to follow up on. I adjusted the settings and now hopefully do in the future. The 'email me when someone replies' was checked.

 

For now, we'll use this thread. The other one can then be wrapped up with the solution / conclution from this one. When one, hopefully, is reached.

 

Jim

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

It might be worth looking at the "SNAP and NX Open for GRIP Enthusiasts" document (which is part of the standard NX documentation set). Section 22 talks about CAM (briefly), and there's a simple example program that shows cycling through the CAMOperationCollection. Maybe it will help.
山田
yamada

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

[ Edited ]

Try the journal below.

 

'
' Created by SharpDevelop.
' User: Stefan.Pendl
' Date: 03.03.2016
' Time: 12:59
' 
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities

Module TestRenameCamObjects
    Dim theSession    As Session   = Session.GetSession()
    Dim theUFSession  As UFSession = UFSession.GetUFSession()
    Dim theUI         As UI        = UI.GetUI()
    Dim TempPath      As String    = Environment.GetEnvironmentVariable("TMP")
    Dim UGRelease     As String    = Nothing
    Dim UGFullRelease As String    = Nothing
    
    Sub Main(Args As String())
        theSession.LogFile.WriteLine("Executing ... " & _
            System.Reflection.Assembly.GetExecutingAssembly().Location)
        
        Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
        
        UGRelease = theSession.GetEnvironmentVariableValue("UGII_VERSION")
        UGFullRelease = theSession.GetEnvironmentVariableValue("UGII_FULL_VERSION")
        
        System.Windows.Forms.Application.EnableVisualStyles()
        
        Dim MyUndoMark As Session.UndoMarkId = _
            theSession.SetUndoMark(Session.MarkVisibility.Visible, "TestRenameCamObjects")
        
        ' uncomment the following lines to check for the correct application
        Dim AppID As Integer = UFConstants.UF_APP_NONE
        theUFSession.UF.AskApplicationModule(AppID)
        If AppID <> UFConstants.UF_APP_CAM Then
            theUI.NXMessageBox.Show("Application missmatch", NXMessageBox.DialogType.Error, "No NX CAM session, Exiting!")
            Exit Sub
        End If
        
        For i As Integer = 0 To theUI.SelectionManager.GetNumSelectedObjects() - 1
            Dim theSelectedObject As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
            
            If theSession.Parts.Work.CAMSetup.IsGroup(theSelectedObject) Then
                Dim thePartName As String = IO.Path.GetFileNameWithoutExtension(theSession.Parts.Work.FullPath)
                
                Dim theIndex As String = NXOpenUI.NXInputBox.GetInputString("Enter Index")
                
                Dim theGroupName As String = Left(thePartName, 12).Replace("-", "_") & "_" & theIndex & "_" & Right(thePartName, 4)
                
                Dim theNcGroup As CAM.NCGroup = CType(theSelectedObject, CAM.NCGroup)
                
                theNcGroup.SetName(theGroupName)
                
                Dim theCounter As Integer = 0
                
                For Each theCAMObject As CAM.CAMObject In theNcGroup.GetMembers()
                    If theSession.Parts.Work.CAMSetup.IsOperation(theCAMObject) Then
                        theCAMObject.SetName(theCounter.ToString("00") & "_" & theCAMObject.Name)
                        
                        theCounter += 1
                        
                        If theCounter > 99 Then Exit For
                    End If
                Next
            End If
        Next
    End Sub
    
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return CInt(Session.LibraryUnloadOption.Immediately)
    End Function
End Module
Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

Stefan,

Wow that's pretty cool. Almost better than perfect. Just needs a few adjustments. I did make a couple on my end to line 57. Picture-1 shows the renaming using your original Journal. I needed to drop the underscore between the D & 001 and there was a double underscore before the index letter. Picture-2 shows the naming with the adjustments I made. Yay for me! which cleaned that up.

 

Now I need more help if possible, Please. First thing is I need the operation numbering to start at 01 not 00.

Then If I add an operation to a group example shown in Picture-3 Group (index) B.I need to re-run the Journal to re-number the operations which I can to a point. First issue with that is if I simply re-run the Journal and try to assign the same Index letter (B) I get an error. It needs to stay the same. So I give input C to get it to run again then the issue is that when it renames the operations it appends a second prefix to the original operations. See Picture-4 Can it be w setup to strip any existing prefixes then re-number the operations normally?

 

The last item I'd like to see but not required. Could the Journal, when renaming the second, third, fourth, etc. groups, look at the previous group (in this case when renaming what became group B the Journal looked at group A) seeing that it was A would self determine that this group needs to be B. I can live without this last request if it's alot of work.

 

I'm so greatful for your help. You're awesome.

Thank you,

JimC

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

Yamada,

Stefan provided a working Journal. But I'd like to learn and try to do more with journals. Like convert my many Macros over to Journals. So I will be referencing your suggested materials.

 

Thank You for your feedback.

JimC

Re: Needed: VB.net Journal to rename Program Groups and operations in NX CAM

[ Edited ]

JimCunningham wrote:
First thing is I need the operation numbering to start at 01 not 00.

 

Change

Dim theCounter As Integer = 0

To

Dim theCounter As Integer = 1

 

I will see what I can do for the rest Smiley Wink

Is it OK to have the index being determined fully automatic or must the first index be entered manually?

If you always start the first group with A and so on, then it is easy to avoid user input entirely.

It would also be possible to not have to select anything and all available groups and operations would be checked automatically Smiley Wink

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community