Startup macro

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Startup macro

Postby Delco » Thu Feb 06, 2025 11:35 am

Are there any gurus who could write a macro for startup .
I would like it to start with a jog rate of 50% ,in continues jog mode , a feedrate of 1000mm/min , and then clear reset , and then to pop up a dialog box (v2.115 messages) to ask to home y/n ? then to home system .

I would be much appreciative to work out how to do this.
Delco
 
Posts: 388
Joined: Tue Apr 02, 2019 4:23 am

Re: Startup macro

Postby cncdrive » Thu Feb 06, 2025 1:01 pm

Answer of ChatGTP :)

Code: Select all
// Set Jog Rate to 50%
exec.Setfield(50, 225); // 225 = Jog Rate field in UCCNC

// Enable Continuous Jog Mode
exec.Setfield(1, 226); // 226 = Continuous jog mode enable field

// Clear Reset before setting feedrate
exec.ClearReset();

// Set Feedrate to 1000 mm/min
exec.Code("F1000");

// Show pop-up message asking to home the system
int response = exec.Question("Do you want to home the system?", "Homing Confirmation");

// If the user selects "Yes", trigger the homing button
if (response == 1)
{
    exec.ButtonExecute(105); // 105 = "Home all" button in UCCNC
}
cncdrive
Site Admin
 
Posts: 5054
Joined: Tue Aug 12, 2014 11:17 pm

Re: Startup macro

Postby Delco » Fri Feb 07, 2025 6:43 am

Thank you , last time I tied chatgtp it didnt know about uccnc coding , will give that another try :)
Delco
 
Posts: 388
Joined: Tue Apr 02, 2019 4:23 am

Re: Startup macro

Postby Delco » Fri Feb 07, 2025 10:13 am

Well tested that and it did not work , I placed that macro into M9998 to run on startup and nothing.

If I put
string jogpercent = "60";
AS3jog.Setfieldtext(jogpercent, 913); // Set Jog Percent
AS3jog.Validatefield(913);

from another profile into M9998 that works - Im more confused than when I started ?
Delco
 
Posts: 388
Joined: Tue Apr 02, 2019 4:23 am

Re: Startup macro

Postby cncdrive » Fri Feb 07, 2025 10:09 pm

I think it probably does not work because you placed it into M9998 , but the startup macro number is M99998,
so you have to place to the M99998.txt macro file instead.

You can check if the UCCNC is compiling the macro simply with placing a syntax error into the macro, just write some random text into the file and then you will get a M99998 macro cannot run etc. message on the UCCNC startup.
cncdrive
Site Admin
 
Posts: 5054
Joined: Tue Aug 12, 2014 11:17 pm

Re: Startup macro

Postby Delco » Sat Feb 08, 2025 5:18 am

cncdrive wrote:I think it probably does not work because you placed it into M9998 , but the startup macro number is M99998,
so you have to place to the M99998.txt macro file instead.

You can check if the UCCNC is compiling the macro simply with placing a syntax error into the macro, just write some random text into the file and then you will get a M99998 macro cannot run etc. message on the UCCNC startup.


It was placed into the M99998.txt file , if I put the code as you supplied I get systax error .

If I put
// Set Jog Rate

string jogpercent = "52";
AS3jog.Setfieldtext(jogpercent, 913);
AS3jog.Validatefield(913);

I find it troubling that the developer of uccnc cant supply the correct code to do this ? but relied on chat gtp ?????????????
That works but if I put the supplied code in it just has syntax errors

// Set Jog Rate to 50%
exec.Setfield(50, 225); // 225 = Jog Rate field in UCCNC

// Enable Continuous Jog Mode
exec.Setfield(1, 226); // 226 = Continuous jog mode enable field

// Clear Reset before setting feedrate
exec.ClearReset();

// Set Feedrate to 1000 mm/min
exec.Code("F1000");

// Show pop-up message asking to home the system
int response = exec.Question("Do you want to home the system?", "Homing Confirmation");

// If the user selects "Yes", trigger the homing button
if (response == 1)
{
exec.ButtonExecute(105); // 105 = "Home all" button in UCCNC
}




I have tried Chatgtp and it gives me a dozen options but none work as it doesnt really understand uccnc any more than I do - it understands c+ but it needs to understand ucccnc properly but it does not.
Delco
 
Posts: 388
Joined: Tue Apr 02, 2019 4:23 am

Re: Startup macro

Postby cncdrive » Sat Feb 08, 2025 7:46 am

Yes, it seems ChatGTP is not pro in UCCNC yet, but here is the corrected code (corrected by me):
However I found it cool that he understands the logic, so hopefully he will learn more about UCCNC and will code professionally soon. :)

Code: Select all
// Set Jog Rate to 50%
AS3jog.Setfield(50, 913); // 225 = Jog Rate field in UCCNC

// Enable Continuous Jog Mode
exec.Callbutton(161); // 226 = Continuous jog mode select

// Clear Reset off before setting feedrate
exec.Callbutton(513);

// Set Feedrate to 1000 mm/min
exec.Code("F1000");

// Show pop-up message asking to home the system
string message = "Do you want to Home the system?";
string title = "Homing question";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(message, title, buttons);
if (result == DialogResult.Yes)
{
    exec.Callbutton(113); // 113 = "Home all" button in UCCNC
}
cncdrive
Site Admin
 
Posts: 5054
Joined: Tue Aug 12, 2014 11:17 pm

Re: Startup macro

Postby Delco » Sat Feb 08, 2025 11:33 pm

Thank you that appears to ll work fine now.

I think it would further the software to have a repository of example macros fully commented so those of us that dont understand coding can learn by example.

It would be nice to have such things as possible M99998.txt options alos a variety of M6 macros applicable to each type of tool rack , be it carousel , linear , etc.
What would be better is having a integrated solution ie , a page on uccnc screenset where you could select the type of tool rack , approach directions , feedrate for operation , tool releae and grab pins/port etc

Much like centroid have done https://youtu.be/ubGuQ4TON-M?si=EYjmhZsjypdGfHrM
Delco
 
Posts: 388
Joined: Tue Apr 02, 2019 4:23 am

Re: Startup macro

Postby Delco » Sun Feb 09, 2025 6:36 am

cncdrive wrote:Yes, it seems ChatGTP is not pro in UCCNC yet, but here is the corrected code (corrected by me):
However I found it cool that he understands the logic, so hopefully he will learn more about UCCNC and will code professionally soon. :)

Code: Select all
// Set Jog Rate to 50%
AS3jog.Setfield(50, 913); // 225 = Jog Rate field in UCCNC

// Enable Continuous Jog Mode
exec.Callbutton(161); // 226 = Continuous jog mode select

// Clear Reset off before setting feedrate
exec.Callbutton(513);

// Set Feedrate to 1000 mm/min
exec.Code("F1000");

// Show pop-up message asking to home the system
string message = "Do you want to Home the system?";
string title = "Homing question";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(message, title, buttons);
if (result == DialogResult.Yes)
{
    exec.Callbutton(113); // 113 = "Home all" button in UCCNC
}


I did some further testing and the reset now works as done the homing question - have not tested it out of demo mode yet.

But the following code I cannot understand

// Set Jog Rate to 50%
AS3jog.Setfield(50, 913); // 225 = Jog Rate field in UCCNC ( I dont understand why 913 is used as you say 255 is the jog feed rate field ? )

// Enable Continuous Jog Mode
exec.Callbutton(161); // 226 = Continuous jog mode select (I dont understand why 161 is used as you say 226 is the continuous jog select ? )


Very hard to work out how to code when it is documented like that - what hope do us mere mortals have ?

I used deepseek to comment this code and it now all works
Code: Select all
 // Set Jog Rate
        AS3jog.Setfield(56, 913); // 913 = Jog Rate field in UCCNC

        // Enable  Jog Mode
        exec.Callbutton(162); // 162 = Continuous jog mode select
              // 161 = Step Mode

   // Enable step rate
   exec.Callbutton(166); // 166=1mm , 165=0.1mm , 164=0.01mm

        // Clear Reset off before setting feedrate
        exec.Callbutton(513);

        // Set Feedrate to 1000 mm/min
        exec.Code("F1200");

        // Show pop-up message asking to home the system
        string message = "Do you want to Home the system?";
        string title = "Homing question";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result = MessageBox.Show(message, title, buttons);
        if (result == DialogResult.Yes)
        {
            exec.Callbutton(113); // 113 = "Home all" button in UCCNC
        }


The only part is I now would like to use the latest message box in v1.2117 - deepseek doesnt know about that yet ?
Delco
 
Posts: 388
Joined: Tue Apr 02, 2019 4:23 am

Re: Startup macro

Postby cncdrive » Sun Feb 09, 2025 3:48 pm

The errors you pointed out is because ChatGTP did not know the proper numbers of the fields and buttons.
I corrected them manually after you pointed out the issues.

Yes, Deepseek is also nice.
I was thinking to use an AI model on our server and tech him about UCCNC, was wondering if it could support UCCNC macro and plugin programming.
According to CharGTP it is possible to do it, I mean to teach the bot about things with converting PDFs to vector documents and then showing the bot the links via php or HTML code.
cncdrive
Site Admin
 
Posts: 5054
Joined: Tue Aug 12, 2014 11:17 pm


Return to Macros

Who is online

Users browsing this forum: No registered users and 8 guests