icon

Support Forum

Phytonparts precast element with reinforcement [Gelöst]

Schlagworte:
  • PythonParts

Hello,
Im still working from a script that uses the same structure of the "ALLPLAN start now - PythonParts" course, to be specific the one provided in Learning materials>Script object>Lesson 1. I need to convert the beam 3D element into a precast element, like what is usually done with the allplan command "precast element" by clicking on a solid, but i dont know what the correct procedure would be, if i should create a 3D element and convert it at the end or create a precast element from the start with the same geometry.

Lösung anzeigen Lösung verbergen

Hi,

I'll just give an example for a single-layer precast element out of concrete. All values are hard coded. If you want to control them from the palette, you have to create a parameter in the PYP file of the correct type. Some of the values are predefined in catalogs, like material. So you don't want to input them freely, but rather select from values predefined in the catalog. TO achieve this, you may need a special precast parameter.

First, you need to define the PrecastLayers (in this particular case only one):

def create_precast_element_layers(self) -> list[AllplanPrecast.PrecastElement]:
    layer_prop = AllplanPrecast.PrecastLayerProperties()
    layer_prop.LayerName = "Concrete"
    layer_prop.CalculateLayerThickness = True
    layer_prop.LayerThickness = 0.0   # thickness will be calculated anyway
    layer_prop.MaterialType = 0       # 0 for concrete, 1 for insulation, 2 for bricks
    layer_prop.Material = "C30/37"    # you can replace this with a value from parameter of type ConcreteGradeCatalogReference
    layer_prop.MaterialCatAddressOffset = layer_prop.SetMaterialCatalogAddressOffset(layer_prop.MaterialType, layer_prop.Material)
    layer_prop.LayerNumber = 1
    return [AllplanPrecast.PrecastLayer(layer_prop)]

In 2026, we will offer a parameter value type, that will place the controls on the palette and create the list of layers for you. In 2025 you need to do it on your own.

Now define the PrecastElement. You have to fill up a lot of values. You can leave them to default by simply not assigning any value.

def create_precast_element(self, build_ele: BuildingElement) -> AllplanPrecast.PrecastElement:
    precast_ele_props = AllplanPrecast.PrecastElementProperties()
    precast_ele_props.Layers = self.create_precast_element_layers()
    precast_ele_props.SpanDirection = AllplanGeometry.Point3D(*build_ele.get_insert_matrix().GetVectorX().Values()) # converting vector to point
    precast_ele_props.ViewDirection = AllplanGeometry.Point3D(*build_ele.get_insert_matrix().GetVectorY().Values())
    precast_ele_props.ReferencePoint = AllplanGeometry.Point3D() # in local coordinates
    precast_ele_props.Factory = "Werk1" # you can replace this with a value from a parameter of type FactoryCatalogReference
    precast_ele_props.FactoryCatAddressOffset = precast_ele_props.SetFactoryCatalogAddressOffset(precast_ele_props.Factory)
    precast_ele_props.Norm = "EC 2"  # you can replace this with a value from a parameter of type NormCatalogReference
    precast_ele_props.NormCatAddressOffset = precast_ele_props.SetNormCatalogAddressOffset(precast_ele_props.Norm)
    precast_ele_props.ElementTypeCatGUID = precast_ele_props.SetElementTypeCatalogGUID_from_Name("MD")  # you can replace this with a value from parameter of type PrecastElementTypeCatalogReference

    precast_ele_props.ElementType = 3000    # preparation for upcoming element types
    precast_ele_props.PieceFactor = 1
    precast_ele_props.PosNr = 1
    precast_ele_props.PosNrText = "AddTxt"

    precast_ele_props.CreateLabeling = True
    precast_ele_props.LabelingTextRefPoint = 1  # label in the middle of the element
    precast_ele_props.ElemTypeAttribut = ""
    precast_ele_props.ManualDimensions = False  # set to True to overwrite the caltulated dimensions with manual values
    precast_ele_props.DimensionViewing = 0.0    # dimension in the view direction
    precast_ele_props.DimensionSpan = 0.0       # dimension in the span direction
    precast_ele_props.DimensionCross = 0.0      # dimension in the cross direction

    precast_element = AllplanPrecast.PrecastElement(precast_ele_props)
    precast_element.deletePython = False # False to be able to double-click the element and modify as a pythonpart

    return precast_element

Now you have the PrecastElement, what you need to do it to append it to the list of model elements. The same, where your PythonPart already it. The rest will be handled by the framework:

python_part_elements = pyp_util.create_pythonpart(build_ele)
python_part_elements.append(self.create_precast_element(build_ele))

return CreateElementResult(elements = python_part_elements,
                           handles  = self.handle_list)

Please note: in one script you can only create one PythonPart being a Precast element. For creating a series of independent Precast Elements you would need much more advanced logic.

The entire script is in the attachment. Didn't tested it in 2025, only in 2026. Still, I'm sure it'll work. If not, let me know.

Best,
Bart

Anhänge (1)

Typ: text/plain
24-mal heruntergeladen
Größe: 17,91 KiB

Hi,

I'll just give an example for a single-layer precast element out of concrete. All values are hard coded. If you want to control them from the palette, you have to create a parameter in the PYP file of the correct type. Some of the values are predefined in catalogs, like material. So you don't want to input them freely, but rather select from values predefined in the catalog. TO achieve this, you may need a special precast parameter.

First, you need to define the PrecastLayers (in this particular case only one):

def create_precast_element_layers(self) -> list[AllplanPrecast.PrecastElement]:
    layer_prop = AllplanPrecast.PrecastLayerProperties()
    layer_prop.LayerName = "Concrete"
    layer_prop.CalculateLayerThickness = True
    layer_prop.LayerThickness = 0.0   # thickness will be calculated anyway
    layer_prop.MaterialType = 0       # 0 for concrete, 1 for insulation, 2 for bricks
    layer_prop.Material = "C30/37"    # you can replace this with a value from parameter of type ConcreteGradeCatalogReference
    layer_prop.MaterialCatAddressOffset = layer_prop.SetMaterialCatalogAddressOffset(layer_prop.MaterialType, layer_prop.Material)
    layer_prop.LayerNumber = 1
    return [AllplanPrecast.PrecastLayer(layer_prop)]

In 2026, we will offer a parameter value type, that will place the controls on the palette and create the list of layers for you. In 2025 you need to do it on your own.

Now define the PrecastElement. You have to fill up a lot of values. You can leave them to default by simply not assigning any value.

def create_precast_element(self, build_ele: BuildingElement) -> AllplanPrecast.PrecastElement:
    precast_ele_props = AllplanPrecast.PrecastElementProperties()
    precast_ele_props.Layers = self.create_precast_element_layers()
    precast_ele_props.SpanDirection = AllplanGeometry.Point3D(*build_ele.get_insert_matrix().GetVectorX().Values()) # converting vector to point
    precast_ele_props.ViewDirection = AllplanGeometry.Point3D(*build_ele.get_insert_matrix().GetVectorY().Values())
    precast_ele_props.ReferencePoint = AllplanGeometry.Point3D() # in local coordinates
    precast_ele_props.Factory = "Werk1" # you can replace this with a value from a parameter of type FactoryCatalogReference
    precast_ele_props.FactoryCatAddressOffset = precast_ele_props.SetFactoryCatalogAddressOffset(precast_ele_props.Factory)
    precast_ele_props.Norm = "EC 2"  # you can replace this with a value from a parameter of type NormCatalogReference
    precast_ele_props.NormCatAddressOffset = precast_ele_props.SetNormCatalogAddressOffset(precast_ele_props.Norm)
    precast_ele_props.ElementTypeCatGUID = precast_ele_props.SetElementTypeCatalogGUID_from_Name("MD")  # you can replace this with a value from parameter of type PrecastElementTypeCatalogReference

    precast_ele_props.ElementType = 3000    # preparation for upcoming element types
    precast_ele_props.PieceFactor = 1
    precast_ele_props.PosNr = 1
    precast_ele_props.PosNrText = "AddTxt"

    precast_ele_props.CreateLabeling = True
    precast_ele_props.LabelingTextRefPoint = 1  # label in the middle of the element
    precast_ele_props.ElemTypeAttribut = ""
    precast_ele_props.ManualDimensions = False  # set to True to overwrite the caltulated dimensions with manual values
    precast_ele_props.DimensionViewing = 0.0    # dimension in the view direction
    precast_ele_props.DimensionSpan = 0.0       # dimension in the span direction
    precast_ele_props.DimensionCross = 0.0      # dimension in the cross direction

    precast_element = AllplanPrecast.PrecastElement(precast_ele_props)
    precast_element.deletePython = False # False to be able to double-click the element and modify as a pythonpart

    return precast_element

Now you have the PrecastElement, what you need to do it to append it to the list of model elements. The same, where your PythonPart already it. The rest will be handled by the framework:

python_part_elements = pyp_util.create_pythonpart(build_ele)
python_part_elements.append(self.create_precast_element(build_ele))

return CreateElementResult(elements = python_part_elements,
                           handles  = self.handle_list)

Please note: in one script you can only create one PythonPart being a Precast element. For creating a series of independent Precast Elements you would need much more advanced logic.

The entire script is in the attachment. Didn't tested it in 2025, only in 2026. Still, I'm sure it'll work. If not, let me know.

Best,
Bart

Anhänge (1)

Typ: text/plain
24-mal heruntergeladen
Größe: 17,91 KiB

Thank you very much, this solved my problem.

i was also wondering what would be the correct way to place both point fixtures and line fixtures in this file. I tried looking at the examples and to get the AI assistant to help, but honestly i dont fully understand the first (the AssemblyGroupPlacement to be specific) and i wasnt able to produce anything that works.