PythonParts-Update 1: using Visual Studio Code


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

Attachments (1)

img
Debug.png
Type: image/png
Downloaded 43 times
Size: 5,64 KiB
1 - 10 (10)
  • 1

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'

Attachments (1)

img
ModuleNotFoundError.png
Type: image/png
Downloaded 18 times
Size: 48,91 KiB

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

Attachments (1)

img
DebuggerProblem.png
Type: image/png
Downloaded 17 times
Size: 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

Attachments (3)

img
DebuggerProblem.png
Type: image/png
Downloaded 9 times
Size: 47,53 KiB
img
DebuggerSection.png
Type: image/png
Downloaded 10 times
Size: 78,23 KiB
Type: text/plain
Downloaded 3 times
Size: 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.

Attachments (2)

img
20210512_182927.png
Type: image/png
Downloaded 11 times
Size: 13,45 KiB
img
20210512_183120.png
Type: image/png
Downloaded 13 times
Size: 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

Quote by 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.

Attachments (1)

img
20210513_101000.png
Type: image/png
Downloaded 11 times
Size: 41,70 KiB
1 - 10 (10)
  • 1

https://campus.allplan.com/ uses cookies  -  More information

Accept