Internal viariables

If you have a question about the software please ask it here.

Internal viariables

Postby terastios » Sat Jul 23, 2022 1:01 pm

Hello
I am going to use some internal variables for parametric programing
Is there any way to put a textfield input on the screen to point at the variables?

Code: Select all
#1=300
#2=500
#3=3
#4=0
#5=0
#10=0

M7
M98 P1 L10
M9
M30

O1
#4=#10
#10=#2+#4
G01 X#1 C#10 F10000
#4=#10
#10=#4+#3
G01 C#10 F500
M99



on the code above before running I would like to see the content
or even better to be able to change the numbers of variable #1 and #2
terastios
 
Posts: 7
Joined: Sun Jan 19, 2020 1:11 pm
Location: Greece

Re: Internal viariables

Postby terastios » Sun Jul 24, 2022 6:27 pm

I found a workaround with a macro

Code: Select all
string strVar1;
string strVar2;
string strVar3;
 
 
 
 if (AS3.Getbuttonstate(144)) // if machine is in reset no point in trying to update the variables
   {
     
   }
   else //MACHINE NOT IN RESET / E-STOP, UPDATE VALUES
   {
   
   if (!exec.IsMoving())  // no point updating on the fly as the frontend does not actually know where the machine tool actually is because of the comms buffer, and macroloop timing.  These values are not updated in macroB during motion either.
      {
       
       
        strVar1 = AS3.Getfield(5001);
        exec.Setvar(Convert.ToDouble(strVar1), 1 );
        strVar2 = AS3.Getfield(5002);
        exec.Setvar(Convert.ToDouble(strVar2), 2 );
        strVar3 = AS3.Getfield(5003);
        exec.Setvar(Convert.ToDouble(strVar3), 3 );
      
      MessageBox.Show(exec.mainform,"Lenth: " + strVar1 + Environment.NewLine +
                             "Turns: " + strVar2 + Environment.NewLine +
                             "Steps: " + strVar3
                  );
      
     }
   }

The starting code was taken from a post in here
https://www.forum.cncdrive.com/viewtopic.php?f=15&t=1735

I made 3 fields , I insert the values and then I run the macro
but I am still interested if it is possible a field to point right to the variable
terastios
 
Posts: 7
Joined: Sun Jan 19, 2020 1:11 pm
Location: Greece

Re: Internal viariables

Postby ger21 » Mon Jul 25, 2022 10:51 am

Make the macro a macro loop that runs all the time.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Internal viariables

Postby terastios » Mon Jul 25, 2022 5:22 pm

ger21 wrote:Make the macro a macro loop that runs all the time.


Thanks for the input
Is there any documentation how to make a pop up window to input the variables?
or even an example that has something similar that I can read to understand?
I took a quick look in the forum but I didn't find anything
terastios
 
Posts: 7
Joined: Sun Jan 19, 2020 1:11 pm
Location: Greece

Re: Internal viariables

Postby eabrust » Tue Jul 26, 2022 12:22 am

terastios wrote:
Thanks for the input
Is there any documentation how to make a pop up window to input the variables?
or even an example that has something similar that I can read to understand?
I took a quick look in the forum but I didn't find anything



Hi terastios,

I do my macros in VB, and I've had luck w/ the following to load a variable from an input box prompt.

The following would be a numbered macro file that I call from a specific GCode file at the file start, so that I am prompted for a 'diameter' before the GCode runs, and it is loaded into var #1.

Code: Select all
#VB


dim newvar as double
dim newinput as string




newinput = microsoft.visualbasic.inputbox("value", "Enter new value", var1) ' I believe you will call microsoft.visualbasic.inputbox in C# also

if newinput <> "" then

try
   newvar = convert.todouble(newinput)
catch  'Something went wrong, exit
   'exit/bail out!

   exec.code("m5")
   exec.code("m0")
   exec.code("M30")
   exit sub
end try

   messagebox.show(newvar) ' Verify the value w/ a report back.

else  'Nothing entered, quit!
   'exit/bail out!

   exec.code("m5")
   exec.code("m0")
   exec.code("M30")
   exit sub

end if

exec.setvar( newvar, 1)




hope it helps a little. This reference verifies to use the VB input box for C# use: https://stackoverflow.com/questions/97097/what-is-the-c-sharp-version-of-vb-nets-inputdialog

regards
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 357
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA

Re: Internal viariables

Postby terastios » Tue Jul 26, 2022 1:36 pm

eabrust wrote:

Hi terastios,

I do my macros in VB, and I've had luck w/ the following to load a variable from an input box prompt.

The following would be a numbered macro file that I call from a specific GCode file at the file start, so that I am prompted for a 'diameter' before the GCode runs, and it is loaded into var #1.

Code: Select all
#VB


dim newvar as double
dim newinput as string




newinput = microsoft.visualbasic.inputbox("value", "Enter new value", var1) ' I believe you will call microsoft.visualbasic.inputbox in C# also

if newinput <> "" then

try
   newvar = convert.todouble(newinput)
catch  'Something went wrong, exit
   'exit/bail out!

   exec.code("m5")
   exec.code("m0")
   exec.code("M30")
   exit sub
end try

   messagebox.show(newvar) ' Verify the value w/ a report back.

else  'Nothing entered, quit!
   'exit/bail out!

   exec.code("m5")
   exec.code("m0")
   exec.code("M30")
   exit sub

end if

exec.setvar( newvar, 1)




hope it helps a little. This reference verifies to use the VB input box for C# use: https://stackoverflow.com/questions/97097/what-is-the-c-sharp-version-of-vb-nets-inputdialog

regards
Eric



Thank you very much
This is helpful
I am going to run some tests with your code as a starting point
:D :D
terastios
 
Posts: 7
Joined: Sun Jan 19, 2020 1:11 pm
Location: Greece

Re: Internal viariables

Postby terastios » Tue Jul 26, 2022 2:10 pm

Hi eabrust

This worked fine for me
the only change i made is in this line

Code: Select all
newinput = microsoft.visualbasic.inputbox("value", "Enter new value", var1) ' I believe you will call microsoft.visualbasic.inputbox in C# also


to
Code: Select all
newinput = microsoft.visualbasic.inputbox("value", "Enter new value",  exec.Getvar(1)) ' I believe you will call microsoft.visualbasic.inputbox in C# also


var1 was not acceptable and the macro couldnt run
terastios
 
Posts: 7
Joined: Sun Jan 19, 2020 1:11 pm
Location: Greece

Re: Internal viariables

Postby eabrust » Tue Jul 26, 2022 11:44 pm

Hi terastios

glad it worked for you and you found my paste error.

I trimmed down a larger macro file for you, and forgot to paste in (or rather accidentally deleted) the variable initialization line, which was just:
Code: Select all
dim var1 as double = exec.getvar(1)


good luck and have fun!
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 357
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA


Return to Ask a question from support here

Who is online

Users browsing this forum: Google [Bot] and 20 guests