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

[Frage] Creat PythonParts .py & .pyp

Schlagworte:
  • Python

Hello, I am trying to program a PythonPart in Allplan 2024 but I am already struggling with the .pyp file not being able to find the path to the .py file. I have tried many things... How does this work?!? I have done it exactly as described in the API.

I created a subfolder under PRJ named _Masterarbeit_PhytonPartsScripts and used the following path in the PYP:

<Script>
<Name>\prj\_Masterarbeit_PythonPartsScripts\Fitting.py</Name>
<Title>Filling</Title>
<Version>1.0</Version>
</Script>

Then I created a folder named PhytonPartsScripts in the PRJ directory of the project and used the path:

<Script>
<Name>\prj\MasterarbeitPythonPartsScripts\Fitting.py</Name>
<Title>Filling</Title>
<Version>1.0</Version>
</Script>
As a test, I simply copied the script from Filling from Basiselements, renamed it, and changed the path, but I am not getting anywhere. I would appreciate any help as this is for my Master's thesis.

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Hello!

Oh, I think there is some misunderstanding happened. The string _project_ on this documentation page is only a placeholder. You have to replace it with the actual project name.

But from the beginning. Here are the paths, where you can place your .py file, so that the PythonParts framework can find it:

  • C:\Data\Allplan\2024\Prj\___name_of_the_current_project___\PythonPartsScripts
  • C:\Data\Allplan\2024\Std\PythonPartsScripts

There are more, but these two are recommended in the version 2024.

Now, the path you provide in the .pyp file must be relative to this paths. For example, if in the .pyp file you provide a path like:

<Name>PathTo\YourPythonPart.py</Name>

Note, that there is no leading backslash!

Then the PythonParts framework will look for the .py file YourPythonPart.py in the following locations:

  • C:\Data\Allplan\2024\Prj\___name_of_the_current_project___\PythonPartsScripts\PathTo\YourPythonPart.py
  • C:\Data\Allplan\2024\Std\PythonPartsScripts\PathTo\YourPythonPart.py

If it doesn't find them there, you get the error "Script ... not found"

Best,
Bart

1 - 10 (12)

Hello,

One path is:
\prj\_Masterarbeit_PythonPartsScripts\Fitting.py

The other one is:
\prj\MasterarbeitPythonPartsScripts\Fitting.py

Maybe, it is due to this...


It doesn't work; the .pyp file cannot find the path to the Python script. How should I proceed?

allplan_python.out:

String table error:

Filename \\nb-la-032\nemdaten\allplan\prj\masterarbeit.prj\library\pythonparts\fitting_deu.xml does not exist

Why is he searching for "fitting_deu.xml"?

Anhänge (2)

Typ: image/png
21-mal heruntergeladen
Größe: 12,88 KiB
Typ: image/png
22-mal heruntergeladen
Größe: 13,81 KiB

Hello!

Oh, I think there is some misunderstanding happened. The string _project_ on this documentation page is only a placeholder. You have to replace it with the actual project name.

But from the beginning. Here are the paths, where you can place your .py file, so that the PythonParts framework can find it:

  • C:\Data\Allplan\2024\Prj\___name_of_the_current_project___\PythonPartsScripts
  • C:\Data\Allplan\2024\Std\PythonPartsScripts

There are more, but these two are recommended in the version 2024.

Now, the path you provide in the .pyp file must be relative to this paths. For example, if in the .pyp file you provide a path like:

<Name>PathTo\YourPythonPart.py</Name>

Note, that there is no leading backslash!

Then the PythonParts framework will look for the .py file YourPythonPart.py in the following locations:

  • C:\Data\Allplan\2024\Prj\___name_of_the_current_project___\PythonPartsScripts\PathTo\YourPythonPart.py
  • C:\Data\Allplan\2024\Std\PythonPartsScripts\PathTo\YourPythonPart.py

If it doesn't find them there, you get the error "Script ... not found"

Best,
Bart

Hi,

I followed your recommendations. The error message in Allplan is gone, but the PythonPart doesn't start. Since I just copied the "Filling" script exactly as it is, it should work, but unfortunately, nothing happens. I read the `allplan_python.out` file and got the following error message:

=======================================================================================================

String table error:

Filename \\nb-la-032\nemdaten\allplan\prj\masterarbeit.prj\library\pythonparts\fitting_deu.xml does not exist

=======================================================================================================

Traceback (most recent call last):
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\BuildingElementInput.py", line 164, in start_input
self.build_ele_service.read_data_from_pyp(file_name, self.str_table_service.str_table, False, \
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\BuildingElementService.py", line 148, in read_data_from_pyp
build_ele_script = BuildingElementUtil.import_building_element_script(build_ele, False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\BuildingElementUtil.py", line 77, in import_building_element_script
script = __import__(script_name, fromlist = script_name[islash + 1:])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Allplan\Allplan 2024\Prg\Python\Lib\site-packages\reloader.py", line 199, in _import
base = _baseimport(name, globals, locals, fromlist, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1138, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1078, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1516, in find_spec
File "<frozen importlib._bootstrap_external>", line 1279, in __init__
File "<frozen importlib._bootstrap_external>", line 1295, in _get_parent_path
KeyError: ''

What could be the problem?

I also tried it as shown in the video on "Allplan Learn Now", but unfortunately it didn't work either. It doesn't find the PY script. I am working on a laptop that I check out from the company network; could this be a problem? Also, since the Allplan update to 2024, my local projects on my PC are shown as network folders. Could it possibly be a permissions issue?

Hi!
Have you copied the Filling.py from our examples into a new location? This script imports BitmapAreaExample class from the BitmapArea.py script with a relative import. So when you copy just Filling.py, without Bitmap.py and __init__.py, it wont work.

But anyway, I just noticed, the import wasn't even necessary. I changed the script slightly and deleted the relative import. Find the modified py file (with extension changed to .txt) and the corresponding pyp file attached. Let me know, if it worked.

Best,
Bart

Anhänge (2)

Typ: text/xml
246-mal heruntergeladen
Größe: 9,65 KiB
Typ: text/plain
266-mal heruntergeladen
Größe: 9,29 KiB

Hi Bart,

yes, I copied the Py file from the example folder. I have also copied the Bitmap.py and __init__.py files, but it still doesn't work.
I have now also included the .txt code, but unfortunately it still doesn't work. Should I contact Allplan Support? Thanks for your help.

Hi,

Use the attached Filling.txt instead of the one you have copied (of course change the extension from .txt back to .py). To be sure, restart Allplan before running it.

Best,
Bart

The Filling is working now, thank you very much!
But the "ALLPLAN START NOW - PYTHONPARTS" isnt..

What do you mean? The course it self stopped working or the scripts attached to it doesn't work?

1 - 10 (12)