Parameter passing from within a macro
-
I have a macro that calls one of two macros and passes the parameters sent to the calling macro from the model code. It looks like this:
; for all tools ; var params="" if exists(param.L) set var.params=var.params ^ " L" ^ param.L ; if exists(param.F) set var.params=var.params ^ " F" ^ param.F ; if exists(param.C) set var.params=var.params ^ " C" ^ param.C ; if exists(param.S) set var.params=var.params ^ " S" ^ param.S ; echo "pblwiper passed params", {var.params} if (state.currentTool = 0 | state.currentTool = 1) M98 P"/macros/pblwiper_A.g" {var.params} elif (state.currentTool = 2 | state.currentTool = 3) M98 P"/macros/pblwiper_B.g" {var.params} else echo "pblwiper.g: No active tool" ; ;finis
The macros being called do not "see" that parameters being passed to them. I have verified that the parameters are correct with the included "echo" command. Is this a bug or am I doing something incorrectly?
-
I'm guessing it is because you are creating a string and using that as a parameter rather than passing an actual parameter.
What I have done and it works is to save the VALUE of the parameter and then call the new macro with an actual parameter letter using the saved value.
if exists(param.Z)
var Z_VALUE = param.ZM98 P"NEW_MACRO.G" Z{var.Z_VALUE}
Frederick
-
@fcwilt Did you do this from within a macro?
I don't know how to do this when there are 4 different parameters that may or may not be used. I do think it is worth seeing if the call with a string variable works when not inside of a macro.
Thanks for your response! -
A string will not work.
However you can pass all of the parameters to whatever macro you are calling and it will only use the ones that it knows about. The extra ones will cause no problems.
Or you can test which macro is to be called and pass only the ones it needs.
Frederick
-
@fcwilt I think I have to change the way I wrote the macro being called slightly, which is fine. The existence of one of the parameters passed to the macro controls a set of actions in the macro; the value associated with that parameter doesn't matter. This approach won't work if I can't build a conditional list of parameters.
I wonder if there is a write up of how commands are parsed that would explain why a string containing a list of parameters isn't parsed as such?
-
Perhaps it would be simpler if you relied on the actual value of the parameter rather than just the existence of a given parameter letter.
It's simple to vary the parameter value but much harder, as you are finding to vary the parameter letter.
But if you feel using just the existence of the parameter letter is best you will have to use conditional code to select from several M98 calls that use the needed parameter letters.
Picking out parameter letters from the command stream is simple - you skip over white space until you come to a letter from A to Z. You then analyze the value and execute the command.
One of the problems with the current approach to parameters can be demonstrated by the following:
M98 P"some_file_to_run.g" G123
G is a normal command letter and is treated as such. You may have wanted it to be a parameter but it won't work. M also cannot be a parameter since it is also a normal command letter.
P also cannot be parameter since P is already used in M98 to specify the name of the file.
What may be desirable is an alternate syntax that clearly indicates what is a parameter - something like M98 P"some_file_to_run.g" (A123 B456 C789) where the ( and ) clearly indicate that the letters are to be treated as parameters and not normal command letters.
With such a syntax it might be fairly simple to pass a string to be further analyzed for parameters.
This is @dc42's field of expertise. All I can do is think out loud.
Frederick
-
@fcwilt I am observing the same thing - a string for some odd reason does not work but it should - actually i am trying to do something similar.
-
@Behrouz-AKT said in Parameter passing from within a macro:
@fcwilt I am observing the same thing - a string for some odd reason does not work but it should - actually i am trying to do something similar.
Why do you think a string should be working with the current firmware?
Thanks.
Frederick