Macro Parameter Letters
-
This is a style question, but the answer may involve a feature I'm unaware of.
If I want to call a macro with a pair of coordinates, I can do something like:
M98 P"MacroFile" X{var.XCoord} Y{var.YCoord}
Then in the macro, I just access them using param.X and param.Y.
If I have ranges of coordinates, as in defining a bed area, I'm not aware of any way except choosing arbitrary letters:
M98 P"MacroFile" X{var.XMin} A{var.XMax} Y{var.YMin} B{var.YMax}
I could concatenate min and max as strings with a colon between them, but I know of no way to separate them again inside the macro.
What's the best way to handle this?
-
@donstauffer I did think of a way to "cheat": Multiply the Max value by 1,000 and add them together. But that's not all that much more readable than arbitrary letters. When arrays become available, if they can be passed as macro parameters, that might be somewhat better, although again, you'd have to know the "magic numbers" for what subscripts mean what. In either case you could define a variable inside the macro and assign to it, this giving a good name to each at the beginning of the macro. But overall, none of this is particularly syntactically "sugary."
-
@donstauffer RRF doesn't yet support array-valued user variables and parameters. We may add this feature in RRF 3.5.
-
I've recently run into the same issue (trying to pass used bed area from slicer to my mesh macro) and settled with the arbitrary letters as well.
Really looking forward to user array support. -
@diamondback Yes, arrays as parameters will be wonderful. I've written enough mini-compilers to know how hard the implementation of arrays will be though.
For arbitrary letters, I wonder if it might be useful to establish some kind of convention for how to do common things like bed area. Say, use ABCD and dereference parameters into variables at the beginning of the macro:
var XMin = param.A
var XMax = param.B
var YMin = param.C
var YMax = param.DThis has the disadvantage that if we're used to this usage those letters wouldn't be available for concepts that begin with them. But I don't know how to predict that. An alternative would be for X, Y & Z to be maximums and M, N and O. This choice has the disadvantage of using letters which can't be used in custom G-code or M-code commands, but starting with "M" is easily remembered as "Minimum". Or maybe, A, B and C would be better.
Or, maybe:
var XMax = floor(param.X / 1000)
var XMin = param.X - var.XMax * 1000
var YMax = floor(param.Y / 1000)
var YMin = param.Y - var.YMax * 1000is a little more obscure but only uses X and Y. The call would look like:
M98 P"MacroFile" X{var.XMin + var.XMax * 1000} Y{var.YMin + var.YMax * 1000)
Or, maybe in preparation for retrofitting when array parameters become available, use variable names X0, X1, Y0 and Y1 (will array subscripts be zero based or 1 based?)
I'm open to anything that makes sense to the most people.
-