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
98-mal heruntergeladen
Größe: 635,00 B
1 - 10 (11)

Hi,

can you give more context? E.g. in what situation this function gets called? Maybe you could attach an example PythonPart, where this happens?

Best,
Bart

Zitiert von: bmarciniec
Hi,
can you give more context? E.g. in what situation this function gets called? Maybe you could attach an example PythonPart, where this happens?
Best,

Bart

I have modified the HelloWorld example, try it with interactor , v.v.v But it didn't work.

My ideal is select all objects in a file like NodeSelectAllObjects in Visual Scripting.

Please find the .zip file because I cannot upload .py.

Thanks !

Anhänge (1)

Typ: application/zip
140-mal heruntergeladen
Größe: 1,46 KiB

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
98-mal heruntergeladen
Größe: 635,00 B

Zitiert von: bmarciniec
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

Thank you Bart,

It's worked

Hence, I can get Geometry from Document and use it like Script Object and Interactor PythonPart.

Hi,

in an interactor or script object it is a good Idea to select all elements only once, at the beginning (in the init). Here's an example for an interactor:

class Interactor(BaseInteractor):
    """Examples interactor"""

    def __init__(self,
                 coord_input             : AllplanIFWInput.CoordinateInput,
                 pyp_path                : str,
                 global_str_table_service: StringTableService,
                 build_ele_list          : list[BuildingElement],
                 build_ele_composite     : BuildingElementComposite,
                 control_props_list      : list[BuildingElementControlProperties],
                 modify_uuid_list        : ModificationElementList)                            :
        """Initialize the interactor"""

        self.coord_input               = coord_input
        self.doc                       = self.coord_input.GetInputViewDocument()
        self.all_elements              = AllplanBaseElements.ElementsSelectService.SelectAllElements(self.doc)

Best,
Bart

Hi Bart,

I've tried to do something with the

sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(doc)

that was selected but Allplan crashed after that.

If I run GetGeometry() from SingleElementSelectResult() I can use the result to work.

Can you explain it?

Anhänge (1)

Typ: image/png
34-mal heruntergeladen
Größe: 65,58 KiB

Zitiert von: ChippyCat
Hi Bart,
I've tried to do something with the
sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(doc)
that was selected but Allplan crashed after that.
If I run GetGeometry() from SingleElementSelectResult() I can use the result to work.
Can you explain it?

I cannot explain it, because
  • I don't know, what is this something, that you were trying to do
  • I don't know, what was inside the sel_elements list, when Allplan crashed

You have to provide more context.

Best,
Bart

Hi Bart,

I've tried to do something with the following code :

sel_elemetns = AllplanBaseElements.ElementsSelectService. SelectAllElements(doc)

My idea is to select all 3d polylines in the current document. By " do something" I mean I want to copy, move, of loft the selected objects.

However, Allplan crahsed after that.

You can see in my picture, I can get the geometry of a polyline, but I cannot use it for next function to create a new Polyline3D ( I create a new polyline using AllplanGeometry. Polyline3D(d)).

You can see my attached video.

Here, I provide you with the Allplan file, .pyp and .py files.

I hope you can find something wrong in my code.

Thanks,
Chip

Anhänge (2)

Typ: application/zip
67-mal heruntergeladen
Größe: 1,23 KiB
Typ: application/zip
63-mal heruntergeladen
Größe: 2,51 MiB

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_event
    def 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 False
  • create 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 file
    AllplanBaseElements.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

Anhänge (1)

Typ: application/zip
68-mal heruntergeladen
Größe: 1,78 KiB
1 - 10 (11)