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
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
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 ...
Best,
Bart
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
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 !
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 ...
Best,
Bart
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?
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
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:
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
sel_elements = AllplanBaseElements.ElementsSelectService.SelectAllElements(doc) polyline_elements = [ele.GetModelGeometry() for ele in sel_elements if isinstance(ele.GetModelGeometry(), AllplanGeometry.Polyline3D)]
for polyline in polyline_elements: moved_polyline = AllplanGeometry.Move(polyline,vectormove)
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