Skip to end of metadata
Go to start of metadata

Using Python scripts in arKItect

arKItect has support for scripting in Python (version 2.7). Python programs are stored in the attributes of type "Program". Such attribute must contain either simple script, or exactly one definition of a global function with one parameter, for example:

or

In the above example, function run is defined. When the script in the attribute is executed, this function receives a pointer (of type CArkiObjPtr) to the object it belongs to. Please note that importing functions from other modules also creates function definition, which can cause problems. In the script attributes, either import whole modules, or import functions inside

One script can contain only one function, but you can define inner functions inside it:

Functions, defined in the different attributes are not visible to each other.

What can you do with scripts ?

Almost any action available through the user interface is available through scripts. You can work with data, project, types and treeviews. Anyway, what you can really do relies on what you are allowed to do. For example, if you access a project in read only, any API to modify the project won't work. If you use arKItect Developer, all the modifications of the types or filters won't work, etc.

Using external libraries

If the script is too big to be conveniently used inside attribute, its code can be moved to the external Python library (file with *.py extension). This file later can be imported, using import directive. Such library should be placed to one of the folders ArkiScripts or PythonLib, or any other folder, present in the Python module search path.

Example:

Note: Because Python scripts in arKItect must contain only one function declaration, the syntax from library import function or from library import  is not supported outside of function declaration.

Using libraries from Python installation

By default, arKItect comes with whole Python standard library and several additional libraries, including PyWin32 and PyQt. If Python 2.7 is installed on the computer, then any installed library can also be used in arKItect.

Available APIs

 

  • No labels