Page 1 of 1
SetSystemVariable?
Posted: Tue Feb 25, 2025 6:37 pm
by Gerral
I know how to get a user variable using GetSystemVariable.
Is there a way to Set a user variable before a job is run. I can't find a SetSystemVariable.
Thanks!
Re: SetSystemVariable?
Posted: Wed Feb 26, 2025 9:02 am
by ASPeters
Yes, CNCPipe.Job.SetSystemVariable(...) which has an overload for the string variables as well. Please note that #1-#149 are initialized to 0 before the beginning of a job and not every variable is writeable.
More information on variables can be found in the manual in section 11.2.16:
https://www.centroidcnc.com/centroid_di ... manual.pdf
Re: SetSystemVariable?
Posted: Wed Feb 26, 2025 1:46 pm
by Gerral
I'm not finding it in the documentation when trying to use SetSystemVariable.
Code: Select all
public CentroidAPI.CNCPipe.ReturnCode SetUserVariable(int variableNumber, double newValue)
{
var cncPipe = new CentroidAPI.CNCPipe.Job(m_pipe);
return cncPipe.SetSystemVariable(variableNumber, newValue);
}
Results in:
'CNCPipe.Job' does not contain a definition for 'SetSystemVariable' and no accessible extension method 'SetSystemVariable' accepting a first argument of type 'CNCPipe.Job' could be found (are you missing a using directive or an assembly reference?)
Re: SetSystemVariable?
Posted: Wed Feb 26, 2025 2:10 pm
by ASPeters
What version of software are you using? The SetSystemVariable call was added in CNC12 v5.24
Re: SetSystemVariable?
Posted: Wed Feb 26, 2025 2:14 pm
by Gerral
We're using 5.22 ... time to upgrade?
Re: SetSystemVariable?
Posted: Wed Feb 26, 2025 2:20 pm
by ASPeters
If you want the single line call, yes. If you're not interested in upgrading, you can cheese it a little with
Code: Select all
public CentroidAPI.CNCPipe.ReturnCode SetUserVariable(int variableNumber, double newValue)
{
var cncPipe = new CentroidAPI.CNCPipe.Job(m_pipe);
string command = "#" + variableNumber + " = " + newValue;
return cncPipe.RunCommand(command, "C:\\cncm", false);
}
which would have the same effect though is much slower to perform.
Re: SetSystemVariable?
Posted: Wed Feb 26, 2025 4:03 pm
by Gerral
No thank you, I'm already writing multiline "macros" to do something similar... this is too good.