Python Tips and Tricks

From SysCAD Documentation
Jump to navigation Jump to search

Working with Python files in a project

It is often useful to keep Python scripts (.py files) in the Project folder or a subdirectory such as the Archive or Reports folders. The python script can then access data from reports directly without having to specify a full path to the appropriate directory. Also, when a new version of the project is saved, we can arrange for the Python file to be saved along with the new version, so that the script will still run without having to re-specify the directory.

A useful trick you learn in training is to create a new Excel document in the Reports folder via the New option in Right Click context menu. You can do the same thing with a Python script but you need to edit the Registry. (I usually remove some of the clutter from the dropdown as well, when was the last time anyone used a .rtf file?) Add a ShellNew key to [HKEY_CLASSES_ROOT\.py] with a NullFile value:

Pyfile02.png

You can then create new Python files directly in any of the project folders

Pyfile01.png

Copying Python scripts along with the Project

To make sure that the Python script is copied with the project, open the Excel report dialog and Add a report. Select All Files (otherwise you only see Excel documents) and browse to find the Python file (Here in Archive):

Pyfile03.png

The .py file is now included in the Report dialog, and will be copied when the Project is saved.


Pyfile04.png