Macro not being run when called from config.g
-
Hello,
I'm trying to setup a macro to set my tool offsets so I don't have to always run my config file (which resets heaters to off, etc).
I've tried putting my macro in both the Macros and System folder and called them each from the config.g, nothing.
My callout in config.g:
M98 P"config-tool-offsets.g" ; load in tool offsets
config-tool-offsets.g code:
; MACRO FOR TOOL OFFSETS echo "TOOL OFFSETS ESTABLISHED" ;TOOL 0 (T0) G10 P0 X8 Y45 Z-8.55 ; T0 ; TOOL 1 (T1) G10 P1 X19 Y44 Z-14.3 ; T1 ; TOOL 2 (T2) ;G10 P2 X-9 Y39 Z-5 ; T2 ; TOOL 3 (T3) ;G10 P3 X-9 Y39 Z-5 ; T3
I do not see the echo statement I have, and checking the tool offsets by using
G10 P0
I get back X0.000 Y0.000 Z0.000. There are no other G10 commands after the macro callout (there are ones before that set them all to zeros (not sure if needed in config.g to establish a tool or if I can get rid of em).
I can use
M98 P"config-tool-offsets.g"
in the console and it runs perfectly.Any help would be appreciated, ideally the file is located in the Macros folder so I can run it by clicking it if desired.
-
Alright so I found the issue, a variable in my config didn't have the prefix "global" to it and that seemed to trip up the config.
Now I need to figure out how to not get the error that the variable has already been established if I run the config file without restarting the main board. Another post may be coming soon.
-
@Merlin246 said in Macro not being run when called from config.g:
Now I need to figure out how to not get the error that the variable has already been established if I run the config file without restarting the main board.
You need to check for the existence
if exists(global.myGlobal) set global.myGlobal = 1234 ; it exists, so reset value else global myGlobal = 1234 ; it doesn't exist so create it
-
@OwenD said in Macro not being run when called from config.g:
@Merlin246 said in Macro not being run when called from config.g:
Now I need to figure out how to not get the error that the variable has already been established if I run the config file without restarting the main board.
You need to check for the existence
Or create it in config.g so it always exists (whenever the machine is running) and only modify its value in the macro(s) that use it.Edit: no sorry, this doesn't address that case.
-
@achrn said in Macro not being run when called from config.g:
Or create it in config.g so it always exists
No, this doesn't catch the case the OP describes specifically:
Now I need to figure out how to not get the error that the variable has already been established if I run the config file without restarting the main board.
So, @OwenD is perfectly right with his answer.
-
@infiniteloop I think it does.
The macro then contains code that sets the variable, and not any code that creates the variable.
The variable will always exist whenever the macro runs, and the macro just sets a value, over-writing any existing value.
-
@achrn said in Macro not being run when called from config.g:
I think it does.
Sure, I define all my globals in the config. But the OP want's to cover a special case:
run the config file without restarting the main board
Admittedly, I have no idea why to do so, but @OwenD's code snippet covers that.
-
@infiniteloop said in Macro not being run when called from config.g:
@achrn said in Macro not being run when called from config.g:
I think it does.
Sure, I define all my globals in the config. But the OP want's to cover a special case:
run the config file without restarting the main board
Admittedly, I have no idea why to do so, but @OwenD's code snippet covers that.
Ahh, yes, you're right. Sorry.
I had missed that (possibly because I don't see why you'd want to do that). -
@achrn No need to be sorry. BTW, after thinking about it, there’s a real use case when you specify filament directories: there, you can provide multiple (partial) config.g files.