[Frage] Drawing elements with PythonParts

Schlagworte:
  • Allplan
  • Python
  • Floorplans
  • Walls
  • Windows

Hey guys,

I hope you're all doing well!

So, we have a wizard that contains all drawing elements like walls, doors, windows, chimneys, etc. that are already defined.

A company can provide us with the starting and ending positions of each element in the floorplan, as well as other parameters like width, height, etc ( floorplans are simple, but they have over 3000 of them )

We would like to draw all of the plans programmatically.

I managed to draw only walls with the script attached below and have no idea how to add other elements to it.

So my questions are:

How can I insert windows and doors into the walls, add chimneys, and add dimension lines to the whole drawing?

How can I reuse wizards when drawing elements with python? Perhaps save the wizard element settings to a file and then load them before drawing?

Best Regards!

Code:

import NemAll_Python_Geometry as AllplanGeo
import NemAll_Python_ArchElements as AllplanArchElements

def check_allplan_version(build_ele, version):
    """
    Check the current Allplan version

    Args:
        build_ele: the building element.
        version:   the current Allplan version

    Returns:
        True/False if version is supported by this script
    """

    # Delete unused arguments
    del build_ele
    del version

    # Support all versions
    return True

def create_element(build_ele, doc):
    """
    Creation of element (only necessary for the library preview)

    Args:
        build_ele: the building element.
        doc:       input document
    """

    del build_ele
    del doc


    wall_one_positions = [
        [[0,0],[0,5000]],
        [[0,5000],[5000,5000]],
        [[5000,5000],[5000,0]],
        [[5000,0],[0,0]]
    ]
    wall_one = draw_walls(wall_one_positions, thickness = 350)

    wall_two_positions = [
        [[6000,0],[6000,10000]],
        [[6000,10000],[20000, 10000]],
        [[20000, 10000],[20000, 0]],
        [[20000, 0],[6000,0]]
    ]
    wall_two = draw_walls(wall_two_positions, thickness = 150)


    model_ele_list = wall_one + wall_two

    return (model_ele_list, None )

def draw_walls( xy_position, thickness = 350 ):

    wall_prop = set_wall_properties(thickness)

    model_ele_list = []


    for point in xy_position:
        start_position = point[0]
        end_position = point[1]

        axis = AllplanGeo.Line2D(AllplanGeo.Point2D(start_position[0], start_position[1]),AllplanGeo.Point2D(end_position[0], end_position[1]))

        model_ele_list.append(AllplanArchElements.WallElement(wall_prop, axis))


    return model_ele_list


def set_wall_properties(thickness = 350):
    wall_prop = AllplanArchElements.WallProperties()
    wall_axis_prop = AllplanArchElements.AxisProperties()

    wall_axis_prop.Extension = -1
    wall_axis_prop.Position  = AllplanArchElements.AxisProperties.WallAxisPosition.eFree

    wall_prop.SetAxis(wall_axis_prop)

    tier_count = wall_prop.GetTierCount()

    for tier_index in range(tier_count):
        wall_tier_prop = wall_prop.GetWallTierProperties(tier_index + 1)

        wall_tier_prop.SetThickness(thickness)

    return wall_prop

Anhänge (1)

Typ: image/png
52-mal heruntergeladen
Größe: 40,63 KiB

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Zitiert von: DjordjeSto
Hey guys,
I hope you're all doing well!
So, we have a wizard that contains all drawing elements like walls, doors, windows, chimneys, etc. that are already defined.
A company can provide us with the starting and ending positions of each element in the floorplan, as well as other parameters like width, height, etc ...

Hi,

at the moment, from architectural elements you can only create walls, columns, beams and slabs using Python API. Placing doors, windows and other openings is planned to be implemented in future version (probably 2025, definitely not in 2024). Placing chimneys is not planned at the moment.

The script you provided is a good starting point. As of now, Allplan Python API does not offer functions to read the element properties (e.g., a wall) from a favorite file in order to get a Python element (like WallElement). So you would have to build such functions yourself.

I would suggest to use the CreateElementResult object as the return value of the create_elements function, as described here. You could then create your walls in the global coordinate system by specifying the Placement Point in (0,0,0) like this

from CreateElementResult import CreateElementResult

...


def create_element(build_ele, doc):

...


return CreateElementResult(elements=        model_ele_list,
                           placement_point= AllplanGeo.Point2D())

Zitiert von: DjordjeSto
Hey guys,
I hope you're all doing well!
So, we have a wizard that contains all drawing elements like walls, doors, windows, chimneys, etc. that are already defined.
A company can provide us with the starting and ending positions of each element in the floorplan, as well as other parameters like width, height, etc ...

Hi,

at the moment, from architectural elements you can only create walls, columns, beams and slabs using Python API. Placing doors, windows and other openings is planned to be implemented in future version (probably 2025, definitely not in 2024). Placing chimneys is not planned at the moment.

The script you provided is a good starting point. As of now, Allplan Python API does not offer functions to read the element properties (e.g., a wall) from a favorite file in order to get a Python element (like WallElement). So you would have to build such functions yourself.

I would suggest to use the CreateElementResult object as the return value of the create_elements function, as described here. You could then create your walls in the global coordinate system by specifying the Placement Point in (0,0,0) like this

from CreateElementResult import CreateElementResult

...


def create_element(build_ele, doc):

...


return CreateElementResult(elements=        model_ele_list,
                           placement_point= AllplanGeo.Point2D())

Hi,

Favorites *.wafanfx files are written in XML so why not parse it ?

Best

Anhänge (1)

Typ: image/jpeg
87-mal heruntergeladen
Größe: 270,41 KiB

Hey,

Thanks for your answers!

at the moment, from architectural elements you can only create walls, columns, beams and slabs using Python API. Placing doors, windows and other openings is planned to be implemented in future version (probably 2025, definitely not in 2024). Placing chimneys is not planned at the moment.

Oh, I thought that all the elements were already supported by the Python API.

Any suggestions on how I can achieve what I described above? I am pretty sure they want to stick with the architectural elements, but maybe using smart parts or something else for the openings? Any workaround will help.

I would suggest to use the CreateElementResult object as the return value of the create_elements function, as described here. You could then create your walls in the global coordinate system by specifying the Placement Point in (0,0,0) like this

Great suggestion, thanks!

Favorites *.wafanfx files are written in XML so why not parse it ?

Thanks for your suggestion. We use only one type of wall with different thicknesses, so I should probably write a function describing it, but since only walls are supported, my whole idea kind of falls apart.

Zitiert von: DjordjeSto

Oh, I thought that all the elements were already supported by the Python API.
Any suggestions on how I can achieve what I described above? I am pretty sure they want to stick with the architectural elements, but maybe using smart parts or something else for the openings? Any workaround will help.

Unfortunately not all are supported. New elements are introduced step-by-step and that will also be the case with openings in 2025.

I could imagine one workaround, which probably would not be ideal as with every workarounds but I'll try:
You can create walls, columns and slabs using API. You can also create an ordinary 3d object and apply attributes to it. So maybe create 3d objects instead of openings and then convert them to doors/windows using the Allplan built-in function create wall openings and create slab openings. Those are primarily designed to create recesses in walls based on 3D solids imported by an IFC from another model. It is not optimal, because it is a two step workflow.

Regarding the wizards: you could implement an "overtake properties" function in your PythonPart by letting the user select objects in the wizard. That would require creating an Interactor PythonPart with a selection functionality. Remember to set the EnableAssistWndClick to True

I could imagine one workaround, which probably would not be ideal as with every workarounds but I'll try:
You can create walls, columns and slabs using API. You can also create an ordinary 3d object and apply attributes to it. So maybe create 3d objects instead of openings and then convert them to doors/windows using the Allplan built-in function create wall openings and create slab openings. Those are primarily designed to create recesses in walls based on 3D solids imported by an IFC from another model. It is not optimal, because it is a two step workflow.

Hey, I appreciate your help!

The Python API does not support "create wall openings", correct?

If this is the case, users will have to cut openings after the script; therefore, manual work is still needed.

Zitiert von: DjordjeSto

The Python API does not support "create wall openings", correct?
If this is the case, users will have to cut openings after the script; therefore, manual work is still needed.

Allplan API does not support architectural openings right now, that means also this function is not supported. I just mentioned it as a possible workaround which, as you correctly noticed, will still require some manual work.