Key components
A PythonPart, in the sense of an ALLPLAN extension, consists of two essential components:
-
PYP file
It represents the PythonPart in ALLPLAN and (in most cases) defines the layout of the palette.
-
PY file
The script with the business logic of the PythonPart, written in python. It contains functions required by the interface
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. For the user to be able to define their values, the framework takes care of creating a palette with input controls (e.g. input fields, combo boxes, buttons, etc.). You can say, that the palette layout is determined by the parameters.
PYP file is used to start a PythonPart from ALLPLAN UI. It must be located in certain directories in order to be shown as an item in the ALLPLAN Library - part of ALLPLAN UI for managing various content (PythonParts is one type of content).
Info
PythonPart can also be started by drag-and-dropping the PYP file into ALLPLAN UI.
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 very example looks like:
<?xml version =”1.0” encoding =”utf-8”?>
<Element
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://pythonparts.allplan.com/2026/schemas/PythonPart.xsd"> <!--(1)! -->
<Script>
<Name>MyPythonParts\MyPythonPart.py</Name> <!--(2)! -->
<Title>My PythonPart</Title>
<Version>1.0</Version>
</Script>
<Page>
... <!--(3)! -->
</Page>
</Element>
- Specify the schema in the parent node to get autocompletion hints. Also, the XML structure is validated as you type.
-
Path to the PY file relative to PythonPartsScripts directory. There are three: one in prj, one in std and one in usr directory. Python will look in all of them to find your PY file. In exactly this order.
-
Your palette can have multiple pages, but at leas one. A page contains input parameters We cover them in this article
Info
The example above contains just the essentials. The complete structure of a PYP file is defined in an XML schema document (XSD) hosted here. Refer to it to get the overview of all the required and optional tags together with their explanations.
Optional components
PY and PYP files are the bare minimum. Beside them, 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, we recommend to structure ot as a python package, like this:
📁 std/
└── 📁 PythonPartsScripts/
└── 📁 MyPythonParts/
└── 📁 MyPythonPart/
├── 📄 __init__.py
├── 📄 FirstModule.py
├── 📄 SecondModule.py
└── 📄 ...
If you do this, the __init__.py
can contain the required functions, like:
from .FirstModule import MyInteractor #(1)!
...
def check_allplan_version(_build_ele, version) -> bool:
return float(version) >= 2025.0
create_interactor(...) -> MyInteractor:
return MyInteractor(...)
- You can now use relative import to import your modules!
The PYP-file can point to MyPythonPart.py
although this file actually does not exists.
But because there is a folder with this name containing __init__.py
, python treates
the folder as a module. Cool, right?