Initialising GisLink in SISpy
To access Cadcorp SIS from Python, import the SISpy module (sis) and initialise the GisLink object. In the Python file:
import sis
if __name__ == "__main__":
s = sis.GisLink()
GisLink methods can now be accessed from the 's' variable. All GisLink methods are case-sensitive.
LoadSwd loads an SWD file allowing you to access a pre-configured map from Python. It accepts a single argument, 'filename': the file location of the SWD to load.
Filenames in Python require double backslashes.
reportSwdFileName = "C:\\data\\MyMap.swd" s.LoadSwd(reportSwdFileName)
Integrating external libraries with SISpy is easy. Python's extensive standard library provides many useful options out of the box.
For example we can timestamp the PDF filename using the time module:
from time import strftime,gmtime
time = strftime("%d-%m-%Y @Time-%H-%M-%S", gmtime())
ExportPdf accepts three arguments: filename, paperFormat and additional parameters. Additional configuration of these and all other API commands can be found in the online documentation.
The PDF filename will consist of the SWD file and the timestamp composed above.
pdfFilename = "C:\\Reports\\" + swdName + "-" + time + ".pdf"
paperFormat = "A4*"
parameters = ""
s.ExportPdf(pdfFilename, paperFormat, parameters)
The full script so far with additional formatting for readability:
import sis from time import strftime,gmtime import os.path # Configuration variables: # SWD File to Report reportSwdFileName = "C:\\data\\MyMap.swd" # Get SWD Name swdName = os.path.splitext(os.path.basename(reportSwdFileName))[0]
# Create timestamp using standard library (non-SIS)
time = strftime("%d-%m-%Y @Time-%H-%M-%S", gmtime())
# ExportPdf parameters
pdfOutputDirectory = "C:\\Reports"
pdfName = "\\" + swdName + "-" + time + ".pdf"
pdfFilename = pdfOutputDirectory + pdfName
paperFormat = "A4*" parameters = ""
if __name__ == "__main__":
s = sis.GisLink() s.LoadSwd(reportSwdFileName) s.ExportPdf(pdfFilename, paperFormat, parameters)