Debugging with pdb

PythonPart scripts can be debugged with Python’s pdb debugger. To make this possible, the Allplan Trace must be set to Window.

The typical usage to break into the debugger from a running program is to insert

import pdb

pdb.set_trace()

at the location where you want to break into the debugger. You can then step through the code following this statement. The commands must be entered into the Trace window.

Example

def create_geometry(self, build_ele):
import pdb

pdb.set_trace()

length = build_ele.Length.value
width = build_ele.Width.value

line = AllplanGeo.Line2D(0, 0, 0, width/2)

The commands can be entered in the Trace window like this:

> c:\programdata\nemetschek\2021_visualscripting\2021\etc\pythonpartsscripts\basisexamples\curveelements.py(123)create_geometry()
-> length = build_ele.Length.value
(Pdb) n
> c:\programdata\nemetschek\2021_visualscripting\2021\etc\pythonpartsscripts\basisexamples\curveelements.py(124)create_geometry()
-> width = build_ele.Width.value
(Pdb) length
1000.0
(Pdb) n
> c:\programdata\nemetschek\2021_visualscripting\2021\etc\pythonpartsscripts\basisexamples\curveelements.py(128)create_geometry()
-> line = AllplanGeo.Line2D(0, 0, 0, width/2)
(Pdb) n
> c:\programdata\nemetschek\2021_visualscripting\2021\etc\pythonpartsscripts\basisexamples\curveelements.py(130)create_geometry()
-> polyline = AllplanGeo.Polyline2D()
(Pdb) line
Line2D(0, 0, 0, 1000)
(Pdb)