Creating and running a Python script

Python scripts allow you to automate tasks in Cadcorp SIS Desktop that would be time-consuming if carried out one task at a time.

1. Creating a Python script

Create a script file using Python's Integrated DeveLopment Environment (IDLE) script editor or similar.

Here are some basics to remember while writing python scripts:

  • A Python script file is a simple text file saved with the extension “.py”; it can be created with any text editing software.
  • Most PySIS scripts will follow the same basic layout:
# Comment the script using hash
# First import the SIS module
from cadcorp import sis
# Always put your code inside a function
def CHANGE_THIS_FUNCTION_NAME():
# Put your SIS programming commands here:
sis.Prompt("This is a test command")

Creating Buffer Zones Around UK Supermarkets

This sample script loads a .bds base map and a shape file of supermarkets. Next it creates a 1000m buffer around each supermarket and adds a label to each supermarket. Finally it saves the project as an SWD.

The information below also shows the user how to reference and pre-load Python scripts into SIS Desktop so they can be used directly.

Download the Python script and data

Download and copy the sample zip file (contains Data folder and store_analysis.py) to your local machine. We recommend you copy it to anew folder C:\Examples.

  1. Open Cadcorp SIS Desktop.
  2. Select New > Blank Map.
  3. Ensure the Python developer tab is open in the bottom of the window. Related Topics Link IconRelated Topics
  4. Select File > Options > Python and direct the "PYTHONSTARTUP* filename" to store_analysis.py.
  5. Direct the "PYTHONPATH* folders" to the folder where you have saved the script. This will load the Python script into the Cadcorp SIS engine.
  6. Restart Cadcorp SIS Desktop.
  7. Select New > Blank Map.
  8. Type in store_analysis() in the python field box.

The script has been pre-loaded into SIS Desktop. Remember to close SIS Desktop if you make any future changes to the script.