Who can tell me how to use python to add custom items to the treepanel,give me some examples!
thx!
Who can tell me how to use python commands to add custom nodes to the structure tree
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Who can tell me how to use python commands to add custom nodes to the structure tree
Open a document, switch to Part WB, start the script
Code: Select all
# 1. create object
Obj = App.ActiveDocument.addObject('Part::FeaturePython','MyPart')
# 2. define properties
Obj.addProperty('App::PropertyLength','A').A=5.0
# 3.create the shape
Shape1 = Part.makeBox(10.0,10.0,10.0)
Shape2 = Part.makeBox(10.0,10.0,10.0)
Shape2.Placement.move(App.Vector(Obj.A,Obj.A,Obj.A))
Obj.Shape=Shape1.fuse(Shape2)
# 4. make it visible
Obj.ViewObject.Proxy=0
Re: Who can tell me how to use python commands to add custom nodes to the structure tree
Re: Who can tell me how to use python commands to add custom nodes to the structure tree
thx!openBrain wrote: ↑Wed Nov 04, 2020 4:53 pmATM, that's just a read-the-doc question :
FeaturePython Objects
Scripted objects
but I want to add ChildItem to FeaturePython Object in tree view,I cannot find any example.
Re: Who can tell me how to use python commands to add custom nodes to the structure tree
thank you very much,but I try to script like this:openBrain wrote: ↑Tue Nov 17, 2020 3:36 pmMaybe https://forum.freecadweb.org/viewtopic. ... 34#p194209
parent=App.ActiveDocument.addObject("App::FeaturePython","Parent")
child=App.ActiveDocument.addObject("App::FeaturePython","Child")
child.addProperty("App::PropertyLink","LinkToParent")
child.LinkToParent=parent
parent and child are in the same level, bu I want to make the tree like:
doc
..parent
.......child1
.......child2
...........subchild1
...........subchild2
...............subsubchild
.......child3
Re: Who can tell me how to use python commands to add custom nodes to the structure tree
Do your parent viewprovider implements the claimChildren() function as in the example ?
Re: Who can tell me how to use python commands to add custom nodes to the structure tree
Have a look at the viewprovider API : https://www.freecadweb.org/api/d3/db3/c ... vider.html
You can implement the 'doubleClicked' method or have a look at the 'edit methods'.