I need a little help with "nested expressions"
-
I am not sure how to name the problem, I recon this is the reason why I found no solution for my problem in the forum.
I am trying to echo some Tool information that is stored in a variable depending on the current tool.
I am using a standalone Duet6XD on RRF3.5-rc.1 in CNC-ModeT1 P0 ; select tool 1 but don't run any tool change macro files var infoT0="Drill" var infoT1="Chambfer Mill" echo "Current tool is T" ^state.currentTool^"" echo "T0 is a "^var.infoT0^"" echo "T1 is a "^var.infoT1^"" ;cho {var.infoT0,var.infoT1} echo {var.infoT(state.currentTool)} ;<- how do i get this to work?
-
@MaxGyver in 3.5 something like this (not tested):
var toolInfo={"Drill","Chamber Mill"} echo "Current tool is T" ^state.currentTool echo "T0 is a", var.toolInfo[0] echo "T1 is a", var.toolInfo[1] echo var.toolInfo[state.currentTool]
Notes:
- You don't need to follow a value with ^"" if you have already concatenated that value to a string.
- When using echo you can provide multiple values. Each one will be converted to a string. This is more efficient than concatenating all the values into a single string and echoing that, if you don't mind a space being inserted between each pair of values.
-
@dc42 Thank you, your code works, unfortunately just not for my usecase.
I have set up my post processor to dump the Toolnumber with some usefull information at the beginning of the programm:
var infoT1="Bohrer D=2 CR=0" var infoT5="Schaftfraser D=4 CR=0" var infoT22="Bohrer D=3.5 CR=0" var infoT25="Fasenfraser D=8 CR=0"
The toolnumbers are ordered depending on where they are used in the programm, so using an array will not work in this case.
My goal is to display some more discriptive information than only the toolnumber during manual toolchanges.
-
@MaxGyver you can use a conditional expression then:
var currentToolInfo=(state.currentTool=1) ? var.infoT1 : (state.currentTool=5) ? var.infoT5 : (state.currentTool=22) ? var. infoT22 : (state.currentTool=25) ? var.infoT25 : "unknown"
There is a 256 character limit on the length of GCode commands, so you might need to split that into several parts.
Alternatively, use a condition:
var currentToolInfo="unknown"; if state.currentTool=1 set var.currentToolInfo=var.infoT1 elif state.currentTool=5 set var.currentToolInfo=var.infoT5 ...
-
@dc42 Thank you! I got it working with conditions