Debugging
PythonPart scripts can be executed with debugging enabled. This enables you to set breaking or logging points in your code, explore the variables and call stack as the code gets executed.
Info
PythonParts Framework uses debugpy for debugging. It gets installed together with the SDK. It is therefore important to complete the steps explained in the getting started article before you start.
Connecting ALLPLAN with IDE
For the first time
To start debugging mode for the first time after starting ALLPLAN, follow these steps:
-
Run the debugging tool in ALLPLAN
Install the SDK, if you haven't done yet. After doing so, in ALLPLAN go to:
Library -> Private -> AllepPlugins -> AllplanGmbH -> PythonPartSDK(1)
and run the Start Python Debug tool.- The tool will be available on the Actionbar soon
-
Start listening
Hit the button Start listening. ALLPLAN will start listening for a connection from your IDE on the port 5678. From now on, ALLPLAN is stuck and you cannot take any actions, until you connect your IDE (see next step)
-
Connect the IDE
-
Press the Run and Debug button or hit Ctrl+Shift+D
-
Select Attach to ALLPLAN from the RUN AND DEBUG combo box
I don't have the Attach to Allplan option!
If you haven't created your workspace for Visual Studio by following steps in the getting started article, or you did but still don't see the Attach to ALLPLAN option, you can add this launch configuration manually to your
.code-workspace
file. Copy-paste this snippet: -
Press the Play button or hit F5
- Select Debug and Attach to Process
- In Connection type: select Python remote
- In Connection target: input
localhost:5678
- Select the Python process from the list
-
Click Attach
-
After these steps, the IDE and ALLPLAN are connected, which is indicated in the property palette (it should look like shown on the right).
You can now close the Start Python Debug tool in ALLPLAN, start the PythonPart you actually want to debug and use all the debugging functionalities of your IDE.
For the second and consecutive time
When you are done with the debugging, disconnect the IDE from ALLPLAN. This is done in the IDE (e.g. in VS-Code by hitting Shift+F5).
To reconnect again, repeat only the third step. You don't have to start the Start Python Debug tool. Just go to your IDE and start debugging. This is because after disconnecting, ALLPLAN is still listening for the connection on the port 5678 up until you close the application entirely.