Skip to content
Jeremy Wright edited this page Apr 30, 2017 · 3 revisions

Introduction

There are a few advanced features of this module that provide more control over how things work.

Settings

Settings.py has been placed in the root of the module's directory. Modifications can be made to this file to change some aspects of the module's operation. A restart of FreeCAD, or leaving the module and then coming back is required after making changes to Settings.py.

  • execute_on_save - Automatically execute a script every time you save. The default is False.
  • use_external_editor - Automatically reloads and executes the open script when an external change is made. This allows users to use their preferred code editor instead of the one included with this module. The default is False.
  • max_line_length - The number of characters per line that is allowed before a line length warning is given. The default is 79 to help make scripts PEP8 compliant.

Environment Variables

Environment variables are set when a script executes to give you access to the path your script is running from. This is needed because of the way the module executes scripts from a temporary file, which may render things like settings files in the script's home directory unavailable. To access these environment variables, import os and then use os.environ.get("VARIABLE_NAME").

  • MYSCRIPT_FULL_PATH - Includes the full path and filename of the script being executed.
  • MYSCRIPT_DIR - Full path excluding the filename, giving the directory the script resides in.

Here is an example of retrieving the value and using these environment variables:

import os

config = '{path:s}/config.yaml'.format(path=os.environ.get("MYSCRIPT_DIR"))
file = open(config, 'r')
print(file.read())
Clone this wiki locally