Foro de Soporte Allplan

PythonParts-Update 1: using Visual Studio Code

Etiquetas:
  • 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

Adjuntos (1)

Type: image/png
Descargado 193 veces
Size: 5,64 KiB

Show most helpful answer Hide most helpful answer

Cita de: 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

11 - 19 (19)

Hello, I have similar problem, have you fixed your problem?

Hello,

maybe this helps you:

https://github.com/microsoft/ptvsd/issues/1591

Best regards
Horst

Cita de: tsvetanov
Problem with connection to the debugger

This is the error massage when click on “Start Debugging”

You have to active StarPythonDebug --> click OK button then Allplan would stop running. Dont worry !

Next step is running the file PythonParts_VsCode.code-workspace with Visual Studio Code program. Make sure that ptvsd-4.3.2 was in the folder install /Python.

In Visual Studio Code, press open the " Run and Debug " (Ctrl + Shift + D) --> Attach to Allplan (workspace) --> run it .

The "AllplanUtility.EnablePythonDebug()" function in the StarPythonDebug.py file does not work. Therefore DEBUG is not activated. Also there is no file "PythonParts_VsCode.code-workspace".

Adjuntos (1)

Type: image/png
Descargado 52 veces
Size: 174,11 KiB

This is a sh**show.

I kindly remind you that we are paying customers for a software "worth" a small car. People get more usefull help in any non commercial software than here.

The ridiculous small userbase of this in theory powerfull system should make your alarm bells ring.

It`s 6 years old now, basic things still have issues, the integration is technically poor and the documentation is, again, even worse than in small open source or community projects and full of errors.
Seriously, who looks at the doc page and says "yes, thats good, we can publish that"

Jesus Christ. And the money we pay here is used by Nemetschek to attack the US market instead of get the shit done here.Hello?

YOU changed it again without any plausible reason. I was one of the few persons who got the debug running in 2019/2020 + visual studio.

Make it work again! "Make it work" does NOT mean "yeah probably read some github" *shrug* or posting the same stupid answer for years now.Read what the people say.

And yes, Im angry and I wont excuse myself!
Ty for the attention!

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

Cita de: 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

Hi Bart,

thank you very much for your answer.

I am left with one doubt (among many!): to debug the code via VS Code (with Allplan attached) is it strictly necessary to have Pylint installed?

Best regards,

Francesco

Hello Francesco,

Yes, you need the debugpy to debug your code. You can install it with the Install Python Package tool or download the .zip package manually and install it.
I don't know, which version are you using currently. But from approx. 2023-1 you should install the site-packages in
...\Etc\PythonParts-site-packages\
The old location:
...\Prg\Python\lib\site-packages\
Will still work, but you might missing the admin rights to copy anything there.

Best regards,

11 - 19 (19)