Support Forum

[Frage] Creating PythonPart with Interactor - Problem with reference point

Schlagworte:
  • Pythonpart
  • Interactor
  • Reference
  • Point

Hi,

I would like to create a PythonPart within an interactor. This works fine so far, except that I can't control the reference point of the PythonPart.
The PythonPart is created with the following code.

pyp_util.add_pythonpart_view_2d3d(self.model_ele_list)
self.model_ele_list = pyp_util.create_pythonpart(build_ele, AllplanGeo.Matrix3D(), AllplanGeo.Matrix3D())
AllplanBaseElements.CreateElements(self.doc, mat, self.model_ele_list, self.modify_uuid_list, None)
# mat = Matrix3D with Insertion Point

The insertion point of the PythonPart is adopted correctly. However, a "strange" reference point within the PythonPart is adopted. I have tried to control the reference point of the PythonPart adding PythonPartViewData in pyp_util, but this does not work. You can use PythonPartViewData to control the visibility of the layers, but the reference point is not taken over.
Has anyone had similar experiences and a solution for this problem?

Many thanks and best regards
Diego

Zitiert von: Diego_Somaini
Hi,
I would like to create a PythonPart within an interactor. This works fine so far, except that I can't control the reference point of the PythonPart.

The PythonPart is created with the following code.
pyp_util.add_pythonpart_view_2d3d(self.model_ele_list)

self.model_ele_list = pyp_util.create_pythonpart(build_ele, AllplanGeo.Matrix3D(), AllplanGeo.Matrix3D())

AllplanBaseElements.CreateElements(self.doc, mat, self.model_ele_list, self.modify_uuid_list, None)

# mat = Matrix3D with Insertion Point
The insertion point of the PythonPart is adopted correctly. However, a "strange" reference point within the PythonPart is adopted. I have tried to control the reference point of the PythonPart adding PythonPartViewData in pyp_util, but this does not work. You can use PythonPartViewData to control the visibility of the layers, but the reference point is not taken over.

Has anyone had similar experiences and a solution for this problem?
Many thanks and best regards

Diego


Hi Diego,

I think we need more information. First, what do you mean "strange reference point"? Is it located not in the lower-left corner of your geometry? If that is the case, the reasons can be pretty complex. E.g. I don't know, what is inside your model_ele_list. I ran this piece of code:

        mat = AllplanGeo.Matrix3D()
        mat.SetTranslation(AllplanGeo.Vector3D(1000, 1000, 1000))

        geo = AllplanGeo.Polyhedron3D.CreateCuboid(AllplanGeo.Point3D(), AllplanGeo.Point3D(1000, 1000, 1000))
        model_ele_list = ModelEleList()
        model_ele_list.append_geometry_3d(geo)

        pyp_util = PythonPartUtil()
        pyp_util.add_pythonpart_view_2d3d(model_ele_list)

        model_ele_list = pyp_util.create_pythonpart(build_ele, AllplanGeo.Matrix3D(), AllplanGeo.Matrix3D())

        AllplanBaseElements.CreateElements(doc, mat, model_ele_list, [], None)

And the reference point is correctly in the lower-left corner of my cube. But as you can see, there is only this simple cube in my model_ele_list. Can you maybe adapt the code step-by-step towards the moment, where you reach the effect you encounter and tell us, what was the step, that induced the problem? Or maybe you encounter the problem right away in your Allplan version (I ran this code in Allplan 2025)? Let us know.

Best,
Bart

Hi Bart

Thank you very much for your reply.
I have made a test with your code. The cube is created correctly in the PythonPart and the PythonPart is placed correctly in the model.
I chose the following dimensions for the first cube:

geo = AllplanGeo.Polyhedron3D.CreateCuboid(AllplanGeo.Point3D(), AllplanGeo.Point3D(1000, 1000, 1000))

I then modified the py file and chosed the following geometry for the cube:
geo = AllplanGeo.Polyhedron3D.CreateCuboid(AllplanGeo.Point3D(), AllplanGeo.Point3D(2000, 1000, 1000))

If the PythonPart is newly created, the new geometry is not adopted. This also applies if the old PythonPart is deleted from the model first. It seems as if the information of the first PythonPart is stored in the cache and cannot be deleted.
If the second PythonPart is created on a new drawing file, the modified geometry is adopted correctly. This means that the cache is linked to the drawing file.

In the pyp file I have inserted the code that the last entry should not be read. However, this has no influence on the result.

<Script>
    <Name>901 Diego_Test\102 Bewehrungssymbol\102_Bewehrungssymbol.py</Name>
    <Title>Bewehrung Symbol für Beschriftung</Title>
    <Version>1.0</Version>
    <Interactor>True</Interactor>
    <ReadLastInput>False</ReadLastInput>
</Script>

Is there a way to delete the cache that influences the PythonParts? I am convinced that this would solve my problem.
I use Allplan 2024.

Many thanks and best regards
Diego