Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Macro(UG) to rename each Operation with its Tool name 2

Status
Not open for further replies.

rishirajmech

Mechanical
Apr 29, 2015
7
0
0
GB
Hello Team,

Can anyone please suggest the macro which will run through all operation list and rename it with Tool Name.

Please suggest

Thanks
Rishi
 
Replies continue below

Recommended for you

If you search this forum for remame operation tool you will some previous samples.

Basically, you need to cycle through each operation in the Operation Navigator, get the name of its tool parent, and then rename the operation.

There are some samples of cycling through operations and renaming in your installation.
Go to UGOPEN\SampleNXOpenApplications\.NET\CAM and look for programs with "CycleAll" in the name.

Mark Rief
NX CAM Customer Success
Siemens PLM Software
 
An amazing assemblage of anachronisms:
VBA -- is not used much these days, and has never been used in Siemens products
Macro -- an older (and deprecated) way of recording user actions, superseded by journals
UG -- no longer exists; it has been called NX for the last decade or so
 
Thanks Mark for your reply,

I am able to loop through each operation....only problem I having is with getting the Tool name.

Few lines of codes will be of great help as how to get the tool name when its looping through each operation.

Many Thanks
 
Once you have the operation you should be able to:
Code:
NCGroup theTool = myOp.GetParent(CAMSetup.View.MACHINE_TOOL);
String toolName = theTool.name();

Graham Inchley, Systems Developer, Sandvik Coromant. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Rishi,
Feel free to post your final program when you get it all working.
I am always looking for more good examples.

Mark Rief
NX CAM Customer Success
Siemens PLM Software
 
Hello Graham,

Thanks for your response,

I tried to put your code but its showing some messages which I have attached. Please suggest

MACHINE_TOOL IS NOT A MEMBER OF 'NXOpen.CAM.CAMSetup.View'.
'name is not a member of String
Character is not valid

Thanks
Rishi
 
Have you tested in visual studio or anything, Could you please post your full code

GANESH KOTHAKOTA
CAD/CAM LEAD
NX8.5, Vericut7.3.1
TECHMAHINDRA Inc
 
You haven't stated what language you are using, my example code was Java.
If you look in the documentation for NXOpen.CAM.CAMSetup.View you'll find that the machine member is called MachineTool in C#, VB and C++.
Ganesh is right though, post some of you own code and it'll be much easier for us to help.

Graham Inchley, Systems Developer, Sandvik Coromant. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Hello Team,

Sorry for late response...

Here my code which I am using for looping through each operation

Dim counter As Integer = 101
For Each Op As String In Opnames
theUfSession.Ui.SetStatus("Renaming Operation:" & OP)
Dim operation As CAM.Operation
operation = CType(WorkPart.CAMSetup.CAMOperationCollection.FindObject(Op), CAM.Operation)
operation.SetName(Tool Name & counter) ' Tool Name ( Here I need the Machine tool name to be added)
counter += 1
Next

Many Thanks for all your help..
 
So your code should look like this I think:
Code:
Dim counter As Integer = 101
For Each Op As String In Opnames
   theUfSession.Ui.SetStatus("Renaming Operation:" & OP)
   Dim operation As CAM.Operation
   operation = CType(WorkPart.CAMSetup.CAMOperationCollection.FindObject(Op), CAM.Operation)
   [b][COLOR=#CC0000]Dim toolName As String
   toolName = operation.GetParent(CAMSetup.View.MachineTool)[/color][/b]
   operation.SetName([b][COLOR=#CC0000]toolName[/color][/b] & counter)
   counter += 1
Next

Graham Inchley, Systems Developer, Sandvik Coromant. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Hi Graham,
Thanks for quick reply...I tried to put your code in between but its shows the below message for below line

toolName = operation.GetParent(CAMSetup.View.MachineTool)
Error message - Value of type NXOpen.CAM.NCGroup cannot be coverted to string

Please suggest.

Thanks
Rishi

 
Oops, my bad! GetParent() returns the tool group object, so you need to get its name. It should look like this:
Code:
Dim counter As Integer = 101
For Each Op As String In Opnames
   theUfSession.Ui.SetStatus("Renaming Operation:" & OP)
   Dim operation As CAM.Operation
   operation = CType(WorkPart.CAMSetup.CAMOperationCollection.FindObject(Op), CAM.Operation)
   Dim toolGroup As NCGroup
   Dim toolName As String
   toolGroup = operation.GetParent(CAMSetup.View.MachineTool)
   toolName = toolGroup.Name
   operation.SetName(toolName & counter)
   counter += 1
Next

Graham Inchley, Systems Developer, Sandvik Coromant. HP EliteBook 8760w, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP4 64bit
Testing: NX9.0.2.5
 
Status
Not open for further replies.
Back
Top