[Question] [PythonParts] ScriptObject PythonPart and MultiSelection [Solved]

Tags:
  • PythonParts
  • ScriptObject
  • MultiSelection

Hi,

Working on a PythonPart ScriptObject, I can easily obtain from the selection of an element (with wall filter):
- the attributes of the selected element
- geometry (dimensions, rotation, etc.)
- create a new object.

Now I'd like to be able to mass execute my script by launching the PythonPart, select several elements and create an independent PythonPart object for each wall.

I tried MultiElementSelectInteractor and a loop such as

for element in self.selection_result.sel_elements:
...
return CreateElementResult(...)

But it created only one object

Where am I wrong ?

Best
Christophe

Show solution Hide solution

Hi,

Thanks for your answer, as it's not possible to create some independants PythonParts, I will integrate

multi_placement

instead in my code.

Best Regards

Hi Chrisptophe,

I think the core of the problem is in the ... of your code snippet - i don't know what happens there, so I will assume.

Assuming, that create_element_from_wall is the function that does exactly, what you described (reads attributes of the selected element, it's geometry etc) and returns a new element (it does not create it yet, in the sense of writing in the database), e.g. something like:

def create_element_from_wall(selected_wall: BaseElementAdapter) -> ModelElement3D:
    # reading attributes, geometry, etc...
    return ModelElement3D(...)  # return the element you are talking about

Then your loop should look like:
elements_to_create = []
for element in self.selection_result_sel_elements:
    new_element = create_element_from_wall(element)
    elements_to_create.append(new_element)
    
return CreateElementResult(elements_to_create)  # return the result

It's all about creating a list of elements you want to create and then returning it. In ScriptObject, PythonParts framework will take care of it and create all of them in the DF at once. Creating them one-by-one would be way to costly.

Best,
Bart

Hi,

Thanks for your answer, as it's not possible to create some independants PythonParts, I will integrate

multi_placement

instead in my code.

Best Regards