-
Jul 27th, 2024, 10:21 AM
#1
Thread Starter
New Member
CNC CAM software C# coding question
I'm running a CAM software package that uses VB macro coding to activate tasks.
I need to create a macro that will rename a tool loaded in my spindle. For example, if I had Tool #1 (T1) in the spindle when I shut the machine down, but the CAM software says I don't have a tool loaded on restart, I'd want to change the stated T0 on screen to T1. I'd like to press the button on my UCCNC screen and have it ask me what tool number I want to use for the renaming.
I have the following code someone generously created for me that generates the input box. However this is for a tool change, and not a tool renaming.
Code:
string val = exec.TextQuestion("Enter loaded tool number.");
string toolch = "M6 T" + val;
exec.Code(toolch);
which executes a tool change.
************************************************** ************************************************** **************
Here is VB code where I can manually enter T61 T(#) in the manual input line in UCCNC and specify T1 to get the loaded tool renamed to T1. This works fine but I'd like to attach this to a macro so I only have to push a screen button and then enter the tool number.
Code:
int newTool = exec.Getnewtool();
if (newTool < 0)
{
return;
}
else
{
exec.Setcurrenttool(newTool);
}
************************************************** ************************************************
I've tried combing the two command sequences in numerous ways similar to what I've pasted below. None have worked though. All have given me a code error message in UCCNC.
Code:
string val = exec.TextQuestion("Enter loaded tool number.");
string Setcurrenttool(newTool); = "M61 T" + val;
exec.Setcurrenttool(newTool);
Could someone help me out here?
Thanks,
BH
Last edited by dday9; Jul 29th, 2024 at 08:16 AM.
-
Jul 27th, 2024, 10:49 AM
#2
Re: CNC CAM software VB coding question
Originally Posted by BH Davis
I'm running a CAM software package that uses VB macro coding to activate tasks.
That code isn't any flavor of Basic or Visual Basic. VB doesn't use semicolon delimiters, and it doesn't use braces to surround code blocks. It could be JavaScript I suppose, no idea.
-
Jul 27th, 2024, 11:15 AM
#3
Thread Starter
New Member
Re: CNC CAM software VB coding question
Originally Posted by OptionBase1
That code isn't any flavor of Basic or Visual Basic. VB doesn't use semicolon delimiters, and it doesn't use braces to surround code blocks. It could be JavaScript I suppose, no idea.
Okay.........thanks. My mistake. I appreciate your letting me know.
BH
-
Jul 27th, 2024, 11:40 AM
#4
Thread Starter
New Member
Re: CNC CAM software VB coding question
And just did some more digging online and found out this is C# programming. I will continue along that vein.
Again thanks,
BH
-
Jul 27th, 2024, 11:44 AM
#5
Re: CNC CAM software VB coding question
Sounds good. I'll ask that the mods move this thread to the C# forum. Please don't create a new thread there or it will cause them extra work.
-
Jul 27th, 2024, 12:44 PM
#6
Thread Starter
New Member
Re: CNC CAM software VB coding question
Originally Posted by OptionBase1
Sounds good. I'll ask that the mods move this thread to the C# forum. Please don't create a new thread there or it will cause them extra work.
Thanks again.
BH
-
Jul 29th, 2024, 08:17 AM
#7
Re: CNC CAM software C# coding question
Moved from VB6 and earlier. Updated the title to include C#. Updated the post to include [CODE][/CODE] tags.
-
Jul 29th, 2024, 09:00 AM
#8
Re: CNC CAM software C# coding question
Never encountered this software before, so no idea about the specifics.
The code you posted has an extra ; in it, try changing it to
Code:
string val = exec.TextQuestion("Enter loaded tool number.");
string Setcurrenttool(newTool) = "M61 T" + val;
exec.Setcurrenttool(newTool);
and see if that helps.
Also what error is it giving on your current attempts to make this change?
-
Jul 29th, 2024, 09:09 AM
#9
Thread Starter
New Member
Re: CNC CAM software C# coding question
Thank you. I hadn't noticed the extra semi-colon.
I fixed that but still get the same error message: "Script error: macro has errors"
However I have found some code that works:
double val = exec.Question("Enter loaded tool number.");
exec.Setcurrenttool(Convert.ToInt32(val));
Thanks everyone for looking into this. I should be all set now.
BH
Originally Posted by PlausiblyDamp
Never encountered this software before, so no idea about the specifics.
The code you posted has an extra ; in it, try changing it to
Code:
string val = exec.TextQuestion("Enter loaded tool number.");
string Setcurrenttool(newTool) = "M61 T" + val;
exec.Setcurrenttool(newTool);
and see if that helps.
Also what error is it giving on your current attempts to make this change?
-
Jul 29th, 2024, 10:51 AM
#10
Re: CNC CAM software C# coding question
sigh...
Code:
string val = exec.TextQuestion("Enter loaded tool number.");
string Setcurrenttool(newTool) = "M61 T" + val; <-- this here is the problem... it's not doing what you think it is doing.. don't do this.
string newTool = "M61 T" + val;
exec.Setcurrenttool(newTool); <-- NOW you can pass in newTool
-tg
-
Jul 29th, 2024, 11:03 AM
#11
Re: CNC CAM software C# coding question
Originally Posted by techgnome
sigh...
Code:
string val = exec.TextQuestion("Enter loaded tool number.");
string Setcurrenttool(newTool) = "M61 T" + val; <-- this here is the problem... it's not doing what you think it is doing.. don't do this.
string newTool = "M61 T" + val;
exec.Setcurrenttool(newTool); <-- NOW you can pass in newTool
-tg
Oops, didn't even spot what the code was attempting to do!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|