icon

Support Forum

[Frage] Pythonparts, Simple PythonPart, Lession 2

Schlagworte:
  • Simple
  • PythonParts
  • Lession
  • 2

Hello Support Forum

I've installed the Python SDK and am currently working through the "Simple PythonPart" tutorial, Lesson 2.
I'm stuck on the last step, where I'm supposed to link the length, width, and height variables from the PYP file to the PY file. Visual Studio Coder throws an error as soon as I enter the first variable, "build_ele.Length.value," instead of 3000 for the length.
The error message is "Variable not recognized." As long as I leave all the fixed values ​​in the PY file, I can use and place the Python part in Allplan.
The three dialog boxes for length, width, and height appear in the input palette, and I can change the values ​​there.
Correctly, these changes don't yet affect the cuboid dimensions.
So, the two files themselves are working correctly. Only the passing of the variable names seems to be failing.
Can anyone help me with this?
Attached are two screenshots from Microsoft Visual Coder, and the ZIP file contains the files from the USR/Local folder.
Is this information sufficient, or do you need any further details to assist you?

Thank you for your support.

Kind regards,
Remo

Anhänge (3)

Typ: image/jpeg
32-mal heruntergeladen
Größe: 136,12 KiB
Typ: image/jpeg
12-mal heruntergeladen
Größe: 94,17 KiB
Typ: application/zip
74-mal heruntergeladen
Größe: 4,11 KiB

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Hi,

build_ele is an instance of BuildingElement, which by nature is a dynamic object - the attributes are added to it dynamically based on the PYP file, and are not present in the static class definition. Type checking won't work on this kind of objects by definition. Your linter is very strict and does not even allow to save the file with "missing parameter" error.
You need to either disable the check for that particular error in that particular line or use another trick:
instead of calling

self.build_ele.Length.value
call
self.build_ele.get_existing_property("Length").value

The latter is not referring to any dynamic property and linter is fine with it.
Best,
Bart

Hi,

There is no direct link between the pyp file and the py script.
Therefore, it's possible that VS Code will issue a warning but this won't necessarily prevent the script from running correctly.

To work around this, the PythonPartTools plugin can be used, but it requires some adjustments.

Please note:
I highly recommend not using Standard PythonParts but rather ScriptObjects, which will allow you to easily add interactions with the ALLPLAN environment.

Best

Anhänge (2)

Typ: image/png
6-mal heruntergeladen
Größe: 27,39 KiB
Typ: application/zip
48-mal heruntergeladen
Größe: 1,54 KiB

Hi,

Thanks for the help. The problem stemmed from a setting in Visual Studio Code that prevented the script file from being saved.
After disabling that setting, saving worked and the Python part functions correctly.

Regards
Remo

Hi,

build_ele is an instance of BuildingElement, which by nature is a dynamic object - the attributes are added to it dynamically based on the PYP file, and are not present in the static class definition. Type checking won't work on this kind of objects by definition. Your linter is very strict and does not even allow to save the file with "missing parameter" error.
You need to either disable the check for that particular error in that particular line or use another trick:
instead of calling

self.build_ele.Length.value
call
self.build_ele.get_existing_property("Length").value

The latter is not referring to any dynamic property and linter is fine with it.
Best,
Bart