Key components
A PythonPart, in the sense of an ALLPLAN extension, consists of two essential components:
-
PYP file
It represents the PythonPart in ALLPLAN.
-
PY file
The python script with the logic of the PythonPart.
PYP file
The PYP file represents the PythonPart in ALLPLAN. It contains some basic meta-data, like title or version, as well as the reference to the second essential component: the python script.
It may (and in most cases will) contain the parameters of the PythonPart, that are shown to the user on the property palette.
This file is also used to start a PythonPart in ALLPLAN. Typically it is accessed from the ALLPLAN Library, and therefore must be located in certain directories. It can also be started by drag-and-drop.
File structure
The PYP file has an XML-tree structure with <Element>
being the parent tag. It must contain <Script>
tag, others are optional. An example content of a PYP file is shown below, together with
the explanation of each tag. If a tag is optional, the value shown is the default one.
<?xml version =”1.0” encoding =”utf-8”?>
<Element>
<LanguageFile>MyPythonParts</LanguageFile>
<Script>
<Name>MyPythonParts\MyPythonPart.py</Name>
<Title>My PythonPart</Title>
<TextId>1001</TextId>
<Version>1.0</Version>
<DataColumnWidth>150</DataColumnWidth>
<ReadLastInput>False</ReadLastInput>
<Interactor>False</Interactor>
<GeometryExpand>False</GeometryExpand>
<ShowFavoriteButtons>True</ShowFavoriteButtons>
</Script>
<Page>
… <!--(1)! -->
</Page>
</Element>
- The input parameters of the PythonPart are defined here. This topic is extensive, so we describe it in a separate article
Tag | Required | Default | Description |
---|---|---|---|
<LanguageFile> |
optional | None |
Path to the file with the string resources for the localization. Relative to PYP file. If not defined, the PythonPart framework will look for a file with the same name, as the PYP file e.g., MyPythonPart_deu for german string resources. You can override this, if you want to use just one language file for multiple PythonParts. |
<Name> |
required | None |
Path to the .py file with the script, relative to the PythonPartsScripts directory. Sub folders can be used and must be separated by \ . |
<Title> |
required | None |
The title of the PythonPart that is displayed in the property palette. |
<TextId> |
optional | None |
ID of the localized string of the <Title> . |
<Version> |
required | None |
Version number of the PythonPart. Accessible in the script through the BuildingElement.version property. |
<DataColumnWidth> |
optional | 150 | Initial width of the data column (the right one) in the property palette of the PythonPart. |
<ReadLastInput> |
optional | False | If set to True, the parameters of the PythonPart are initialized with the values from the last run. |
<Interactor> |
optional | False | If set to True, the framework will start the PythonPart as an Interactor, thus the script must fulfill the interactor contract. Otherwise, the Standard PythonPart contract must be fulfilled. |
<GeometryExpand> |
optional | False | If set to True, a geometry expansion will be used. In this case, the function expand_create_element must be implemented in the script. This feature is soft-deprecated! |
<ShowFavoriteButtons> |
optional | True | If set to False, the favorite icons will be hidden. Useful in case of an interactor, in which the handling of favorites is not implemented. |
Optional components
Beside the PY and PYP files, which are mandatory for a PythonPart to work, you may want to include some optional files.
-
Thumbnail
For a PythonPart to appear in the ALLPLAN Library with a custom thumbnail, provide a PNG file in the same directory, as of the PYP file.
-
String resources
To localize your Python part, provide an XML file with translated strings.
File locations
Choose the right location for saving your PythonPart files, depending on who should have access to it:
Location | Accessible by |
---|---|
...\std\ | everyone in the work group |
...\usr\__USER_NAME__\ | specific user only |
...\prj\__PROJECT_NAME__\ | all involved in specific project (not recommended) |
Warning
Do not use the ...\etc\ directory to store any of your files as it is the property of ALLPLAN and its content can be deleted or moved during an update!
Save the files in one of the above mentioned locations, according to the structure shown below:
📁 std\ OR usr\ OR prj\
├── 📁 Library\
| └── 📁 MyPythonParts\
| ├── 📄 MyPythonPart.pyp <!--(1)!-->
| ├── 🖼️ MyPythonPart.png
| ├── 📄 MyPythonPart_cze.xml <!--(4)!-->
| └── 📄 MyPythonPart_deu.xml
└── 📁 PythonPartsScripts\ <!--(2)!-->
└── 📁 MyPythonParts\ <!--(3)!-->
└── 📄 MyPythonPart.py
- To make your PythonPart visible in ALLPLAN Library, save the PYP file in the Library directory.
- If the PythonPartsScripts directory does not exist, create it.
-
We recommend to use the same directory structure inside the Library as in the PythonPartsScripts. In this case:
- Library\MyPythonParts\MyPythonPart.pyp
- PythonPartsScripts\MyPythonParts\MyPythonPart.py
-
Files with string resources for localizing your PythonPart. Learn more here
Tip
If your PythonPart script is large and you want to split it into several python modules, you can structure them as a regular python package, for example like this:
📁 std/
└── 📁 PythonPartsScripts/
└── 📁 MyPythonParts/
└── 📁 MyPythonPart/
├── 📄 __init__.py
├── 📄 FirstModule.py
├── 📄 SecondModule.py
└── 📄 ...
If you decide to do this, your __init__.py
file must contain functions and classes required by
the PythonPart contract, such as create_interactor()
. This may look like this:
from .FirstModule import MyInteractor #(1)!
...
def check_allplan_version(_build_ele, version) -> bool:
return float(version) >= 2025.0
create_interactor(...) -> MyInteractor:
return MyInteractor(...)
- In this case, remember to use relative import to import your modules!
However, in your PYP-file, the <Name>
tag must still point to: