Das Wissen aller Anwender nutzen

Im Allplan Connect Forum tauschen sich Anwender aus, geben wertvolle Tipps oder beraten sich bei ganz konkreten Aufgabenstellungen − auch international.
Und damit wirklich keine Frage unbeantwortet bleibt, unterstützen die Mitarbeiter des Technischen Supports ebenfalls aktiv das Forum.

Es erwarten Sie:

  • Foren-Vielfalt aus CAD Architektur, CAD Ingenieurbau uvm.
  • Tipps von User für User
  • international: Deutsch, Englisch, Italienisch, Französisch und Tschechisch

Melden Sie sich jetzt an und diskutieren Sie mit!

Zur Registrierung

PythonParts-Update 1: using Visual Studio Code

Schlagworte:
  • Allplan
  • PythonParts
  • Script

Hello,

we recommend using Visual Studio Code as editor and debugging tool for PythonParts in Allplan-2021. Visual Studio Code is a lightweight but powerful source code editor and can be installed from

https://code.visualstudio.com/

Before the installation of Visual Studio Code, it's necessary to install Python 3.8.8 (64-bit) from

https://www.python.org/downloads/release/python-388/

After the installation of Visual Studio Code it is useful to install the following extensions:

- Python: Python extension
- Pylance: feature-rich language support for Python
- Python Indent
- Studio Icons

This can be executed by

- starting Visual Studio Code
- clicking the "Extensions" button
- typing the name of the extensions in the input field
- selecting the extension from the list

The preparation of the PythonParts editing with Visual Studio Code can be done by executing the PythonPart “CreateVisualStudioCodeWorkspace” in Allplan (located in the directory …\etc\Examples\PythonParts\ToolsAndStartExamples). This PythonPart creates the file “PythonParts_VsCode.code-workspace” in the …\etc directory. By clicking this file Visual Studio Code will be started.

For preparing the PythonPart debugging with Visual Studio Code the following steps are necessary (if the files currently not installed):

- download PTVSD 4.3.2 from https://pypi.python.org/pypi/ptvsd.
- unzip the file ptvsd-4.3.2.zip and copy the ptvsd folder under the Allplan Python folder …\prg\Python\ptvsd

A new debug session can start by the following steps

- executing the PythonPart “StartPythonDebug” in Allplan (located in the drectory …\etc\Examples\PythonParts\ToolsAndStartExamples)
- clicking the button “Run and Debug” in Visual Studio Code
- selecting “Attach to Allplan” in the “RUN AND DEBUG” selection control
- clicking “Start Debugging”

Best regards
Horst

Anhänge (1)

Typ: image/png
193-mal heruntergeladen
Größe: 5,64 KiB

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Zitiert von: minisci_kuk
Hi
I would like to use Visual Studio Code to debug PythonParts (Allplan 2023).
Normally VS Code uses the Powershell in the Terminal.

For security reasons the Powershell is disabled on my office PC.

I currently use the Windows cmd in the Terminal.

Do you think this could be a problem?
Best regards
Francesco

You don't need PowerShell to debug Allplan PythonParts. In fact, you are not using the Windows terminal to debug a PythonPart. Allplan has its own terminal: the trace window. You can activate it, regardless if you are developing PythonParts or you are just curious what is going behind the scenes, in Allplan by pressing Ctrl+F3.

Debugging in VS-Code is done using the debug console (the default shortcut in VS-Code for it is Ctrl+Shift+Y). After attaching the VS-Code to Allplan process, you will be able to see there exactly the same information, as in the Allplan trace window. You can also, when the script is paused by the debugger, input python code there by hand and it will be directly executed in Allplan. PowerShell has nothing to do with it.

Best regards,
Bart

1 - 10 (19)

Thanks for the updated description! Looks like a good starting point.

Can you support me, how to solve ModuleNotFoundError?

Despite, VC Code doesn’t show any errors and for example "Go to Definition” opens the module, executing HelloWorld.py throw a ModuleNotFoundError:
No module named 'NemAll_Python_Geometry'

Anhänge (1)

Typ: image/png
146-mal heruntergeladen
Größe: 48,91 KiB

Problem with connection to the debugger
This is the error massage when click on “Start Debugging”

Anhänge (1)

Typ: image/png
108-mal heruntergeladen
Größe: 47,53 KiB

Hello,

have you executed the first step from my description?

A new debug session can start by the following steps

- executing the PythonPart “StartPythonDebug” in Allplan (located in the drectory …\etc\Examples\PythonParts\ToolsAndStartExamples)

Best regards
Horst

Thanks Horst,

Here is the error message from the trace window when executing StartPythonDebug.

File "C:\ProgramData\Nemetschek\Allplan\2021\Etc\PythonPartsFramework\GeneralScripts\BuildingElementInput.py", line 741, in create_element
preview_ele_list = self.build_ele_script.create_element(self.build_ele_list[0],
File "C:\ProgramData\Nemetschek\Allplan\2021\Etc\PythonPartsScripts\ToolsAndStartExamples\StartPythonDebug.py", line 41, in create_element
AllplanUtility.EnablePythonDebug()
AttributeError: module 'ptvsd' has no attribute 'enable_attach'

Best,
Simeon

Hello Simeon,

have you installed PTVSD 4.3.2 from https://pypi.python.org/pypi/ptvsd ?

Best regards
Horst

Hi Horst,

This part is not clear.
I guess I have to copy the ptvsd-4.3.2\src\ptvsd folder in order to have \prg\Python\ptvsd
In this case there is no error in the trace window when executing “StartPythonDebug”.
“Attach to Allplan” configuration exist in VS Code, but the error is same.
If someday I figure out how to do it. I will create a few a minute video tutorial showing the the whole process?

Best regards,
Simeon

Anhänge (3)

Typ: image/png
57-mal heruntergeladen
Größe: 47,53 KiB
Typ: image/png
61-mal heruntergeladen
Größe: 78,23 KiB
Typ: text/plain
1156-mal heruntergeladen
Größe: 3,05 KiB

I don't even go through the debugging phase.

I followed the steps as you explained, but it doesn't seem to work.

Anhänge (2)

Typ: image/png
84-mal heruntergeladen
Größe: 13,45 KiB
Typ: image/png
75-mal heruntergeladen
Größe: 127,77 KiB

Hello,

which Allplan version do you use?

Please show me the output from the Allplan trace window. There we can find some Python error messages.

Best regards
Horst

Zitiert von: Horst_Hohmann
Hello,
which Allplan version do you use?
Please show me the output from the Allplan trace window. There we can find some Python error messages.
Best regards

Horst

I am using the latest updated version 21-1-1 and the trace window is attached below.

Anhänge (1)

Typ: image/png
119-mal heruntergeladen
Größe: 41,70 KiB
1 - 10 (19)