Im working in one macro and i need to walk the treview and manipulate their objects (Part, Body, groups, etc).
I cant find how to get the object for a given treeview item. Text, data(0,0) and data(0,2) appears to be the label but label is not unique.
Get FreeCAD object associated with QTreeWidgetItem
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Get FreeCAD object associated with QTreeWidgetItem
As strange as it can be, FreeCAD enforces uniqueness of labels too.
Re: Get FreeCAD object associated with QTreeWidgetItem
So theres no "more correct" way?
Must i use ActiveDocument.getObjectsByLabel()[0]?
Theres no way to get internal name from treeview?
Must i use ActiveDocument.getObjectsByLabel()[0]?
Theres no way to get internal name from treeview?
Re: Get FreeCAD object associated with QTreeWidgetItem
I found back this macro I already wrote : https://forum.freecadweb.org/viewtopic. ... et#p446393
I didn't test again, but .text(0) seems to hold the name.
Re: Get FreeCAD object associated with QTreeWidgetItem
The macro is looking for labelopenBrain wrote: ↑Tue Mar 30, 2021 7:40 pm I found back this macro I already wrote : https://forum.freecadweb.org/viewtopic. ... et#p446393
I didn't test again, but .text(0) seems to hold the name.
openBrain said just before code, that "That's all my mistake. I didn't pay attention that the text in the tree is the Label, while the function is searching for the Name.
Here is the fix :"
Code: Select all
def recFindChild(docitem, objname):
for i in range(0, docitem.childCount()):
if docitem.child(i).text(0) == objname: <-- objname is object.Label passed as argument
...
obj = object.Label
...
objitem = recFindChild(docitem, obj)