Page 1 of 1

Internal viariables

PostPosted: Sat Jul 23, 2022 1:01 pm
by terastios
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

Re: Internal viariables

PostPosted: Sun Jul 24, 2022 6:27 pm
by terastios
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

Re: Internal viariables

PostPosted: Mon Jul 25, 2022 10:51 am
by ger21
Make the macro a macro loop that runs all the time.

Re: Internal viariables

PostPosted: Mon Jul 25, 2022 5:22 pm
by terastios
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

Re: Internal viariables

PostPosted: Tue Jul 26, 2022 12:22 am
by eabrust
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

Re: Internal viariables

PostPosted: Tue Jul 26, 2022 1:36 pm
by terastios
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

Re: Internal viariables

PostPosted: Tue Jul 26, 2022 2:10 pm
by terastios
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

Re: Internal viariables

PostPosted: Tue Jul 26, 2022 11:44 pm
by eabrust
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