Using Python scripts in arKItect
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
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
- Global functions and constants
- ArkAttribute objects
- ArkAttributeType objects
- ArkChoice objects
- ArkImage objects
- ArkMatrixType objects
- ArkObj objects
- ArkObjRef objects
- ArkPhase objects
- ArkProject objects
- ArkTreeViewObj objects
- ArkVariant objects
- ArkVariantFilter objects
- ArkConnection Objects
- ArkWorkspace Objects
- ArkUser objects
- ArkGroup objects
- ArkTab objects
- ArkBusyDialog objects
- Custom View Filters