[Frage] Creat PythonParts .py & .pyp

Schlagworte:

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

11 - 12 (12)

The Filling script works, but the one from "Allplan Learn Now" does not.
The Py and the pyp are located in the project.

That's the trace report:

Traceback (most recent call last):
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\CreateLibraryPreview.py", line 68, in create_library_preview
BuildingElementService().read_data_from_pyp(file_name, str_table, True, material_str_table)
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\BuildingElementService.py", line 96, in read_data_from_pyp
build_ele, build_ele_ctrl_props, sub_elements_file = xml_ele.read_element_parameter(file_name, str_table, material_str_table)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\BuildingElementXML.py", line 543, in read_element_parameter
self.doc_ele = XmlElementTreeUtil.parse(path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ProgramData\Nemetschek\Allplan\2024\Etc\PythonPartsFramework\GeneralScripts\XMLReader\XmlElementTreeUtil.py", line 31, in parse
return ElementTree.parse(file_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Allplan\Allplan 2024\Prg\Python\Lib\xml\etree\ElementTree.py", line 1219, in parse
tree.parse(source, parser)
File "C:\Program Files\Allplan\Allplan 2024\Prg\Python\Lib\xml\etree\ElementTree.py", line 581, in parse
self._root = parser._parse_whole(source)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
xml.etree.ElementTree.ParseError: mismatched tag: line 7, column 6

Hi,

This error occurs, when a tag in PYP file is not properly closed. E.g. like the <Name> tag below

<Parameter>
    <Name>Length<Name>
    <Text>Length</Text>
    <Value>6000</Value>
    <ValueType>Length</ValueType>
</Parameter>

More specifically, the problem you have is in the line 7, in the column 6 of the PYP file.

I checked all the PYP files from LearnNow, and no one has this problem. Please check again the file you are trying to run for mismatched tags.

Best,
Bart

11 - 12 (12)