icon

Allplan Fórum

PythonPart with more than one geometry object [Vyřešeno]

Tagy:
  • PythonParts

Working on a script that uses the same structure of the base course, im trying to add a 3D Polyline to the object im creating. The Polyline is not used in other parts of the script, i just need a parametric polyline as an output, so i can turn it to a line fixture in allplan
This is how geometry is created:

def calculate_geometry(self) -> AllplanGeometry.Polyhedron3D:
return AllplanGeometry.Polyhedron3D.CreateCuboid(AllplanGeometry.AxisPlacement3D(),self.length,self.width,self.height)

def calculate_geometry_2(self):
self.pluviale_points = [AllplanGeometry.Point3D(0, 0, 0),AllplanGeometry.Point3D(1000, 1000, -1000),AllplanGeometry.Point3D(0, 0, 0)]
polyline = AllplanGeometry.Polyline3D(self.pluviale_points)
props = AllplanBaseElements.CommonProperties()
props.Color = 6
props.Layer = 1
props.Visible = True
return AllplanBasisElements.ModelElement3D(props, polyline)

def create_as_pythonpart(self, build_ele: BuildingElement) -> CreateElementResult:
"""Create the reinforced beam as a PythonPart with handles and attributes
ReturnsythonPart with handles and attributes """
model_ele_list = ModelEleList()
model_ele_list.append_geometry_3d([self.geometry_2])
model_ele_list.append_geometry_3d(self.geometry)
pyp_util = PythonPartUtil()
pyp_util.add_pythonpart_view_2d3d(model_ele_list)
pyp_util.add_attribute_list(self.attributes)
pyp_util.add_reinforcement_elements(self.reinforcement.all_reinforcement_elements)
python_part_elements = pyp_util.create_pythonpart(build_ele)
return CreateElementResult(elements = python_part_elements,
handles = self.handle_list)

At the moment my script runs but the polyline is completely ignored; before that i was able to get the polyline visible but only in the preview before placing the element, but i dont know how to got back even to that result.

Show solution Hide solution

Hi,

first, in the snippet I don't see, what is assigned to self.geometry and self.geometry_2, but I assume, you just assign what comes out of the methods calculate_geometry and calculate_geometry_2 respectively.
If that is the case, then note following

  • the calculate_geometry returns a Polyhedron3D object. This is pure geometry. No information about with which colot to draw it, on which layer, no attributes, nothing. Just vertices, edges and faces.
  • the calculate_geometry_2 returns a ModelElement3D - an actual element, that can be created in a model

What you do in create_as_pythonpart is you create a list of model elements and append the elements to it with append_geometry_3d. You should only give a pure geometry to this method. It's because what this method does, is creating a ModelElement3D container around this geometry. When you do it like:

model_ele_list.append_geometry_3d([self.geometry_2])
You put a ModelElement3D into a list and then this list again into a ModelElement3D. ALLPLAN cannot deal with this structure so it ignores it.

Here's how I would adapt it:

def calculate_geometry(self) -> AllplanGeometry.Polyhedron3D:
    return AllplanGeometry.Polyhedron3D.CreateCuboid(AllplanGeometry.AxisPlacement3D(),self.length,self.width,self.height)

def calculate_geometry_2(self) -> AllplanGeometry.Polyline3D:
    pluviale_points = [AllplanGeometry.Point3D(0, 0, 0),AllplanGeometry.Point3D(1000, 1000, -1000),AllplanGeometry.Point3D(0, 0, 0)]
    return AllplanGeometry.Polyline3D(pluviale_points)

def create_as_pythonpart(self, build_ele: BuildingElement) -> CreateElementResult:
    """Create the reinforced beam as a PythonPart with handles and attributes
    Returns PythonPart with handles and attributes """
    model_ele_list = ModelEleList()

    # append the polyhedron
    # omitting the common properties will result in current ALLPLAN settings being used
    model_ele_list.append_geometry_3d(self.calculate_geometry())
    
    # append the polyline, setting common properties explicitly
    polyline_common_props = AllplanBaseElements.CommonProperties()
    polyline_common_props.Color = 6
    polyline_common_props.Layer = 1
    polyline_common_props.Visible = True    # this is the default value anyway, not needed
    model_ele_list.append_geometry_3d(self.calculate_geometry_2(), polyline_common_props)
    
    pyp_util = PythonPartUtil()
    pyp_util.add_pythonpart_view_2d3d(model_ele_list)
    ...

Cheers,
Bart

Hi,

first, in the snippet I don't see, what is assigned to self.geometry and self.geometry_2, but I assume, you just assign what comes out of the methods calculate_geometry and calculate_geometry_2 respectively.
If that is the case, then note following

  • the calculate_geometry returns a Polyhedron3D object. This is pure geometry. No information about with which colot to draw it, on which layer, no attributes, nothing. Just vertices, edges and faces.
  • the calculate_geometry_2 returns a ModelElement3D - an actual element, that can be created in a model

What you do in create_as_pythonpart is you create a list of model elements and append the elements to it with append_geometry_3d. You should only give a pure geometry to this method. It's because what this method does, is creating a ModelElement3D container around this geometry. When you do it like:

model_ele_list.append_geometry_3d([self.geometry_2])
You put a ModelElement3D into a list and then this list again into a ModelElement3D. ALLPLAN cannot deal with this structure so it ignores it.

Here's how I would adapt it:

def calculate_geometry(self) -> AllplanGeometry.Polyhedron3D:
    return AllplanGeometry.Polyhedron3D.CreateCuboid(AllplanGeometry.AxisPlacement3D(),self.length,self.width,self.height)

def calculate_geometry_2(self) -> AllplanGeometry.Polyline3D:
    pluviale_points = [AllplanGeometry.Point3D(0, 0, 0),AllplanGeometry.Point3D(1000, 1000, -1000),AllplanGeometry.Point3D(0, 0, 0)]
    return AllplanGeometry.Polyline3D(pluviale_points)

def create_as_pythonpart(self, build_ele: BuildingElement) -> CreateElementResult:
    """Create the reinforced beam as a PythonPart with handles and attributes
    Returns PythonPart with handles and attributes """
    model_ele_list = ModelEleList()

    # append the polyhedron
    # omitting the common properties will result in current ALLPLAN settings being used
    model_ele_list.append_geometry_3d(self.calculate_geometry())
    
    # append the polyline, setting common properties explicitly
    polyline_common_props = AllplanBaseElements.CommonProperties()
    polyline_common_props.Color = 6
    polyline_common_props.Layer = 1
    polyline_common_props.Visible = True    # this is the default value anyway, not needed
    model_ele_list.append_geometry_3d(self.calculate_geometry_2(), polyline_common_props)
    
    pyp_util = PythonPartUtil()
    pyp_util.add_pythonpart_view_2d3d(model_ele_list)
    ...

Cheers,
Bart

Thank you very much, now it works as intended