You can use macro command itself to create simple self-modify or toggle functionality:
You can use macro command itself to create simple self-modify or toggle functionality:
Example: swapping two macros to implement toggle:
Example: swapping two macros to implement toggle:
PC> macro toggle_debug_on
```python
Enter macro using indented lines, end with empty line
PC> macro toggle_debug_on
..> !self.p.loud = 1
Enter macro using indented lines, end with empty line
..> !print "Diagnostic information ON"
..> !self.p.loud = 1
..> macro toggle_debug toggle_debug_off
..> !print "Diagnostic information ON"
..>
..> macro toggle_debug toggle_debug_off
Macro 'toggle_debug_on' defined
..>
PC> macro toggle_debug_off
Macro 'toggle_debug_on' defined
Enter macro using indented lines, end with empty line
PC> macro toggle_debug_off
..> !self.p.loud = 0
Enter macro using indented lines, end with empty line
..> !print "Diagnostic information OFF"
..> !self.p.loud = 0
..> macro toggle_debug toggle_debug_on
..> !print "Diagnostic information OFF"
..>
..> macro toggle_debug toggle_debug_on
Macro 'toggle_debug_off' defined
..>
PC> macro toggle_debug toggle_debug_on
Macro 'toggle_debug_off' defined
Macro 'toggle_debug' defined
PC> macro toggle_debug toggle_debug_on
Macro 'toggle_debug' defined
```
Now, each time we invoke "toggle_debug" macro, it toggles debug information on and off:
Now, each time we invoke "toggle_debug" macro, it toggles debug information on and off:
PC> toggle_debug
```python
Diagnostic information ON
PC> toggle_debug
Diagnostic information ON
PC> toggle_debug
Diagnostic information OFF
PC> toggle_debug
Diagnostic information OFF
```
When python code (using ! symbol) is used in macros, it is even possible to use blocks/conditionals/loops.
When python code (using ! symbol) is used in macros, it is even possible to use blocks/conditionals/loops.
It is okay to mix python code with pronsole commands, just keep the python indentation.
It is okay to mix python code with pronsole commands, just keep the python indentation.
For example, following macro toggles the diagnostic information similarily to the previous example:
For example, following macro toggles the diagnostic information similarily to the previous example:
!if self.p.loud:
```python
!self.p.loud = 0
!if self.p.loud:
!print "Diagnostic information OFF"
!self.p.loud = 0
!else:
!print "Diagnostic information OFF"
!self.p.loud = 1
!else:
!print "Diagnostic information ON"
!self.p.loud = 1
!print "Diagnostic information ON"
```
Macro parameters are available in '!'-escaped python code as locally defined list variable: arg[0] arg[1] ... arg[N]
Macro parameters are available in '!'-escaped python code as locally defined list variable: arg[0] arg[1] ... arg[N]
...
@@ -369,20 +389,24 @@ Therefore it is best to use pronsole commands, which easily contain majority of
...
@@ -369,20 +389,24 @@ Therefore it is best to use pronsole commands, which easily contain majority of
Some useful python-mode-only variables:
Some useful python-mode-only variables:
!self.settings - contains all settings, e.g.
```python
port (!self.settings.port), baudrate, xy_feedrate, e_feedrate, slicecommand, final_command, build_dimensions
!self.settings - contains all settings, e.g.
You can set them also via pronsole command "set", but you can query the values only via python code.
port (!self.settings.port), baudrate, xy_feedrate, e_feedrate, slicecommand, final_command, build_dimensions
!self.p - printcore object (see USING PRINTCORE section for using printcore object)
You can set them also via pronsole command "set", but you can query the values only via python code.
!self.cur_button - if macro was invoked via custom button, the number of the custom button, e.g. for usage in "button" command
!self.p - printcore object (see USING PRINTCORE section for using printcore object)
!self.gwindow - wx graphical interface object for pronterface (highly risky to use because the GUI implementation details may change a lot between versions)
!self.cur_button - if macro was invoked via custom button, the number of the custom button, e.g. for usage in "button" command
!self.gwindow - wx graphical interface object for pronterface (highly risky to use because the GUI implementation details may change a lot between versions)