Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Script to Rename Operation Comments to Add Tool Number?


Jobnt
 Share

Recommended Posts

Is there a script that will iterate through Operations and add the Tool Number to the end of the Comment? 

So going from this:

  1. Rough Profile
  2. Finish Profile
  3. Deburr

To this:

  1. Rough Profile T1
  2. Finish Profile T2
  3. Deburr T3
Link to comment
Share on other sites

Is this for working "inside Mastercam" and seeing the operations, or do you want this in the NC Code output? Because that, would be easy to add to the Operation comment string output.

Or are you trying to "find operations which use a particular tool" in the Mastercam Operation Tree? If yes > use "Operation Selection" from the Right-Click menu. You can opt to "use on all operations", or "only on selected operations". (So, if you select say, an operations group, or multiple, because you only want to search in your "OP1" groups, you can do that.) You can filter by tool number, and when you press "ok", the dialog will close and Mastercam will have those operations "selected".

Link to comment
Share on other sites

I want it in the Operation's Manager, inside Mastercam.

When I program a part with multiple holds I do all of 1 hold, then the next hold, then I organize the operations based on tool numbers/rotations to optimize the program before posting. I've had really bad results using Sort by Tools so I try to stay away from that. 

Link to comment
Share on other sites
25 minutes ago, Jobnt said:

I want it in the Operation's Manager, inside Mastercam.

When I program a part with multiple holds I do all of 1 hold, then the next hold, then I organize the operations based on tool numbers/rotations to optimize the program before posting. I've had really bad results using Sort by Tools so I try to stay away from that. 

I do this with Operation Groups, and Sub-Groups, in the Ops Manager. Easy to track rotations/tools, when grouping the Operations. Then I can name my groups to convey information back to me, while programming and/or posting.

This sounds fairly trivial to do with a script of some sort, but there would be no way to do this "dynamically". If you changed a tool, from T3, to T8, then you run into a situation where the comment doesn't update. Do you want the script to be able to read if there is an existing "T3" appended, and be able to modify that to the current tool number? Now you are talking a script that requires more coding.

  • Thanks 1
Link to comment
Share on other sites
20 minutes ago, Colin Gilchrist said:

Do you want the script to be able to read if there is an existing "T3" appended, and be able to modify that to the current tool number? Now you are talking a script that requires more coding.

I had considered that a bit ago and you're right, that could cause a bit of an issue so it would be better to have it look at the last string and make sure it's not a T#. 

I opened the Sort function and it's considerably different than I remember so there may be a solution there. Will play with it a bit when I get time. 

Link to comment
Share on other sites

He's chasing tail in Cuba right now. Will hit him up when he gets back. 

I remember him saying something about VBScript going byebye in Mastercam. I wonder if now might be a good time to toss out the old and busted and learn teh new hotness. 

  • Haha 3
Link to comment
Share on other sites

I just looked at documentation and it shouldn’t be difficult to make a NETscript:

Get 'operations' array using SearchManager.GetOperations Method

Iterate each operation in 'operations' array :

- to get its 'tool' object using Operation.OperationTool Property then its number using Tool.Number Property

- modify comment operation with T+number with Operation.Name Property

 

I know NETscripting is limited regarding toolpath type so I don't know if this would work with any toolpath though... Then a CHook would only be able to do it.

I will try on monday if I have free time.

 

  • Thanks 1
Link to comment
Share on other sites
On 7/6/2023 at 6:35 PM, Jobnt said:

He's chasing tail in Cuba right now. Will hit him up when he gets back. 

I remember him saying something about VBScript going byebye in Mastercam. I wonder if now might be a good time to toss out the old and busted and learn teh new hotness. 

New hotness - you talkin 'bout tail chasin in Cuba? :lol:

 

On 7/6/2023 at 7:15 PM, #Rekd™ said:

Oh to be young and foolish again!!!!! :D

Old n foolish is where it's at!

Link to comment
Share on other sites
10 hours ago, Newbeeee™ said:

New hotness - you talkin 'bout tail chasin in Cuba? :lol:

 

Old n foolish is where it's at!

Way to tell everyone I'm in cuba guys

🤣

If you are just after tool info, and even if u can't get the operation object you can always dump the nci and parse that for whatever info you need,

Here I am giving away all my secrets, I demonstrate some nci parsing in an old topic here somewhere using .net , although it is c++/cli, it's easy to translate to c#

  • Thanks 1
Link to comment
Share on other sites

@Jobnt NET script seems to work.

I joined .csx file at the end of my post. You can export it with Mastercam script editor to add it to your QAT/Ribbon if you need it.

        // settings
		string prefix = "- T"; // String to add with tool number
		bool used = false;  // True will only modify selected toopath

		// Get all operations from toolpath manager
		Operation[] toolpaths = SearchManager.GetOperations(used);
		
		// Iterate operations
		foreach (Operation op in toolpaths)
				{
				try 
					{
					// Get tool number
					int toolNumber = op.OperationTool.Number;
					// Get operation comment					
					string comment = op.Name;
					// Look for an already added tool number comment and remove it
					int index = op.Name.LastIndexOf(prefix);
					if (index > 0)
							{
							comment = op.Name.Substring(0,index).TrimEnd();
							}
					// Modify comment
					op.Name = comment + " - T" + toolNumber;	
					op.Commit(false);
					}
				catch
					{
					}	
				}

AddToolNumberToolpathComment.csx

Link to comment
Share on other sites
7 hours ago, David Colin said:

@Jobnt NET script seems to work.

I joined .csx file at the end of my post. You can export it with Mastercam script editor to add it to your QAT/Ribbon if you need it.

        // settings
		string prefix = "- T"; // String to add with tool number
		bool used = false;  // True will only modify selected toopath

		// Get all operations from toolpath manager
		Operation[] toolpaths = SearchManager.GetOperations(used);
		
		// Iterate operations
		foreach (Operation op in toolpaths)
				{
				try 
					{
					// Get tool number
					int toolNumber = op.OperationTool.Number;
					// Get operation comment					
					string comment = op.Name;
					// Look for an already added tool number comment and remove it
					int index = op.Name.LastIndexOf(prefix);
					if (index > 0)
							{
							comment = op.Name.Substring(0,index).TrimEnd();
							}
					// Modify comment
					op.Name = comment + " - T" + toolNumber;	
					op.Commit(false);
					}
				catch
					{
					}	
				}

AddToolNumberToolpathComment.csx 2 kB · 1 download

🔥

6 hours ago, So not a Guru said:

I still rock the foolish part.🤪

It's funny cause I'm older to people in their 20's but young to people 40+ , hey my birthdays coming up, now where's my drink !🌴

  • Haha 1
Link to comment
Share on other sites
8 hours ago, David Colin said:

@Jobnt NET script seems to work.

I joined .csx file at the end of my post. You can export it with Mastercam script editor to add it to your QAT/Ribbon if you need it.

 

This is prolly going to sound really stupid (because it sounded stupid in my head), how do I run this? I've only ever run VBS and CHooks. Never NetHooks. :lol:

Link to comment
Share on other sites

@Jobnt You talked about script so i made it that way^^ 

In your ribbon (Home tab) you should find a command to launch NETscript editor. It looks like a notepad, just open file i sent then click execute. Editor can be used to export to a .dll file and .ft file if you want to execute this script with one click from your QAT/RMB/Ribbon.

Actually, this is a net-script which is replacing VBS now. If you struggle with it and feel more confortable with a .dll/.ft I will make them.

Link to comment
Share on other sites
25 minutes ago, David Colin said:

@Jobnt You talked about script so i made it that way^^ 

In your ribbon (Home tab) you should find a command to launch NETscript editor. It looks like a notepad, just open file i sent then click execute. Editor can be used to export to a .dll file and .ft file if you want to execute this script with one click from your QAT/RMB/Ribbon.

Actually, this is a net-script which is replacing VBS now. If you struggle with it and feel more confortable with a .dll/.ft I will make them.

I'm ok with scripts, just never used the NET type. Lots of VBS though. 

I don't see the NETscript editor, just the VBS editor. I'm in 2020. I looked in All Commands and couldn't find it. 

Link to comment
Share on other sites
9 minutes ago, Jobnt said:

I'm ok with scripts, just never used the NET type. Lots of VBS though. 

I don't see the NETscript editor, just the VBS editor. I'm in 2020. I looked in All Commands and couldn't find it. 

Sorry i thought you were in 2023. NET-scripting wasn't probably available in 2020. I will compile it in a Nethook then.

  • Thanks 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...