Skip to content

Getting started

Get Python

The required Python version is already installed together with Allplan. The standard Python installation of Allplan contains all parts of the Python framework that are required to run the PythonParts supplied by Allplan. You can find it in the Allplan program directory under ...\Prg\Python.

The Python version used by Allplan 2024 is 3.11.4

Note

Since Python package is already delivered with Allplan, you don't need to install it separately. If you however want to install it in your environment, make sure you have the appropriate version. The download of the version 3.11.4 can be done from here

Include the Tools and Examples in Library

There are many useful PythonPart tools and examples included in the Allplan installation. They are located in the folders:

  • ...\etc\Examples\PythonParts for the .pyp files
  • ...\etc\PythonPartsExampleScripts for the .py files

The easiest way to start using them is to include them in Allplan's Library Palette. To do that, add the path of the .pyp files to the External folder.

Include Examples in the external path

The examples a divided into following folders:

Folder Description
BasisExamples contains examples from Allplan BasisElements library
ContentExamples contains complex PythonPart examples
GeometryExamples contains examples from the Allplan Geometry library
InteractorExamples contains examples from the Allplan IFW_Input library
PaletteExamples contains examples demonstrating the palette functionalities
ReinforcementExamples contains examples with special reinforcement functionalities
StructuralFramingExamples contains examples with special structural framing functionalities
ToolsAndStartExamples contains helpful start examples

Install the right IDE

You can edit your Python code with a normal text editor but for a better effinciency we strongly reccomend using a proper Integrated Development Environment, or IDE. Those will help you by the development by checking and debugging your code. There are many IDEs available but in this tutorial we are going to focus on the two most common ones

Visual Studio Code is a lightweight but powerful source code editor from Microsoft.

Note

Please install Python 3.11.4 before installing Visual Studio Code

We reccomend following extensions to be installed for the development of PythonParts:

  • Python: extension for code formating, refactoring, unit test and more
  • Pylance: a performant, feature-rich language server for Python
  • Python Indent: for correct Python intendation
  • Pylint: tool for linting your python code
  • Studio Icons

To install the extensions please perform following steps in VS Code:

  1. click the Extensions button or hit Ctrl+Shift+X
  2. type the name of the extensions in the input field
  3. select the extension from the list
  4. click the Install button

Create the workspace

A workspace for developing PythonParts with Visual Studio Code can be created quickly by running the PythonPart CreateVisualStudioCodeWorkspace in Allplan, which is located in the Allplan directory …\etc\Examples\PythonParts\ToolsAndStartExamples.

This PythonPart creates the file PythonParts_VsCode.code-workspace directly in the Allplan …\etc folder. Opening this workspace with VS Code should result with this:

VisualStudio Code Workspace

Visual Studio is an IDE also launched by Microsoft delivered in many different versions, some available as freeware. For developing PythonParts scripts at least the Community version is required.

Info

To allow the Python development, it is necessary to select Python-Development during the installation process.

Create the workspace

In the Allplan ..\etc folder there are three .pyproj files which can be used as starting point for PythonParts development:

  • PythonPartsExamples.pyproj with the example pyp files
  • PythonPartsFramework.pyproj with the py files of the PythonParts framework
  • PythonParts.pyproj with the py files of the examples and content

Enable Intellisense

To make the Allplan Python API functions available in the Intellisense, the Search Paths in the loaded Python projects must be adapted to the Allplan Prg folder. After the path selection it should look like this:

Visual Studio Workspace

Tip

From the two above mentioned IDEs we reccomend using Visual Studio Code for developing PythonParts

Lint your code

Lint is a type of software that checks for errors in code, tries to enforce a coding standard and looks for code smells or type errors. It can recommend suggestions about how particular blocks can be refactored and can offer you details about the code's complexity. The tool that does that in Python is Pylint . We strongly recommend using this tool for the PythonPart script development.

Set-up in VS Code

To start using Pylint add the Pylint extension to Visual Studio Code, as described in the previous chapter. After the extension is installed, go to the extension's settings and add the following argument in the Args section:

--rcfile=xxx\PythonPartsFramework\pylintrc <!--(1)!-->
  1. Replace the xxx with your etc-path!

Pylint Arguments

Info

The file pylintrc is a configuration file for Pylint. Pylint checks for many things and some of them are more, and some less important for the development of PythonParts. For that reason we provide this configuration as a reference point. You can include this configuration under the Workspace, so that it applies on your PythonPart project only. Include it under User to apply it on all of your projects, if you develop only PythonParts in VS Code.

We also provide an extension for Pylint, called PythonPartPylintExtension. It checks the implementation of the PythonPart script, e.g. warns against using deprecated functions or suggests the correct return value types. The PythonPart framework underlies constant development, so to keep up with them we strongly recommend using this tool. It is included in the PythonPart framework under ..\Etc\PythonPartsFramework\TestHelper\.

Failure

If the following message is shown in the Problems window

PythonPart Pylint extension

it probably means, that the path containing PythonPartPylintExtension.py is not included in the VS-Code workspace configuration. Try to generate the workspace again using CreateVisualStudioCodeWorkspace PythonPart included in the ToolsAndStartExamples. Alternatively, make sure that the entry highlighted below is included in the Workspace configuration:

"python.analysis.extraPaths": [
    "C:\\Program Files\\Allplan\\Allplan\\2023\\Prg",
    "C:\\ProgramData\\Nemetschek\\Allplan\\2023\\Etc\\PythonPartsFramework\\GeneralScripts",
    "C:\\ProgramData\\Nemetschek\\Allplan\\2023\\Etc\\PythonPartsFramework\\TestHelper",
    "C:\\ProgramData\\Nemetschek\\Allplan\\2023\\Etc\\PythonPartsFramework",
    "C:\\ProgramData\\Nemetschek\\Allplan\\2023\\Etc\\VisualScripts\\TestUtil",
    "C:\\ProgramData\\Nemetschek\\Allplan\\2023\\Etc\\VisualScripts",
],

Installing an additional Python package

If additional Python packages are required for your PythonPart to work, they should be installed in the following directory:

  • ...\etc\PythonParts-site-packages\

The installation can also be done with the PythonPart InstallPythonPackage, which is located in:

  • ...\etc\Examples\PythonParts\ToolsAndStartExamples

Install python package