Selected All objects [Gelöst]


I am trying to select all objects like node selectedallobject in visual scripting.

used this method :
sel_objects = AllplanBaseElements.ElementsSelectService.SelectAllElements(self.coord_input.GetInputViewDocument())

But Allplan crashes

Lösung anzeigen Lösung verbergen

Hi,

the problem is that you have created a new, empty document adapter:

sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(AllplanElementAdapter.DocumentAdapter())

What you do is you define a function called create_element. Allplan calls this function when he needs to (e.g. when you start the PythonPart). When it does so, it gives 2 arguments to it: build_ele (of type BuildingElement) and doc (of type DocumentAdapter).
The first one represents the data, that is input in the property palette: the parameters and their values. The latter, document adapter, stands for the whole content of the currently opened drawing file(s). Everything, what is in the currently opened drawing files, like lines, dimension lines, UVSs, but also stuff like layer definition, available steel grades... Basically everything is inside this object.

What you have done with...

sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(AllplanElementAdapter.DocumentAdapter())
...is you have created a new empty document and you tried to select elements from it. This won't work.

Instead, use the document, Allplan is giving to you as an argument of the create_element function:

def create_element(build_ele: BuildingElement,
                   doc: AllplanElementAdapter.DocumentAdapter) -> CreateElementResult:

    sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(doc)
    # now do something with the elements
    ...

Find the adapted code attached.

Best,
Bart

Anhänge (1)

Typ: application/zip
164-mal heruntergeladen
Größe: 635,00 B
11 - 11 (11)

Zitiert von: bmarciniec
Hi,
The code looks ok, but only in the case, there are solely 3D polylines in the document. There is no guarantee whatsoever, that the first element you are getting with __getitem__(0) will be a polyline.
Further more, actions like selecting all elements in the model should be a one-time action. create_elements gets executed over and over again in Allplan, basically every time you move the mouse around in the viewport. It's not a good idea to read all the data from the drawing file with every mouse move.
What you should do is:
implement your logic in a function that gets executed only once, e.g. when a button is pressed. This is the case for on_control_eventdef on_control_event(build_ele: BuildingElement, event_id: int, doc: AllplanElementAdapter.DocumentAdapter) -> bool: if event_id == 1000: create_polyline_copies(doc, build_ele.Length.value) return Falsecreate your own function, e.g. create_polyline_copies(...)
select all elements but then filter them. E.g. create a list by checking, whether each element geometry is really a Polyline3D, like:sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(doc)
polyline_elements = [ele.GetModelGeometry() for ele in sel_elements if isinstance(ele.GetModelGeometry(), AllplanGeometry.Polyline3D)]
Now you can do something with all these polylines. E.g. move them up:

for polyline in polyline_elements: moved_polyline = AllplanGeometry.Move(polyline,vectormove)

At the very end, you should create these polylines in the drawing fileAllplanBaseElements.CreateElements(doc, AllplanGeometry.Matrix3D(), model_ele_list, [], None)
Have a look at the script. You can run it in Allplan. Create some 3D polylines beforehand and then run it and click "Go!".
Best,

Bart

Thank, works like a charm.

def on_control_even is useful for me.

11 - 11 (11)