Select all parents and children belonging to a shape

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
andre
Posts: 96
Joined: Wed Nov 13, 2013 5:34 am

Select all parents and children belonging to a shape

Post by andre »

I use this to help me find all of the linked parametric steps for any selected face/object on the GUI screen:

Code: Select all

objects=[]

sel = FreeCADGui.Selection.getSelection()
sel = sel[0]
linkname=sel.Name
lastlinkfound=linkname
objects.append(linkname)

linkname = sel.InList 
#Find all objects AFTER the main selection

while True:
	if len(linkname) == 0:
		FreeCAD.Console.PrintMessage("no more!")
		break
	linkname=linkname[0]
	linkname = linkname.Name
	objects.append(linkname)
	sel=FreeCAD.ActiveDocument.getObject(linkname)
	FreeCADGui.Selection.addSelection(sel)
	lastlinkfound=linkname
	linkname=Gui.activeDocument().getObject(linkname).Object.InList

#Find all objects BEFORE the main selection
linkname=Gui.activeDocument().getObject(lastlinkfound).Object.OutList

while True:
	if len(linkname) == 0:
		FreeCAD.Console.PrintMessage("no more!")
		break
	linkname=linkname[0]
	linkname = linkname.Name
	objects.append(linkname)
	sel=FreeCAD.ActiveDocument.getObject(linkname)
	FreeCADGui.Selection.addSelection(sel)
	linkname=Gui.activeDocument().getObject(linkname).Object.OutList

FreeCAD.Console.PrintMessage(objects)
This is useful for me when I want to MOVE or ROTATE an object. I noticed when you move or rotate a shape (especially with Draft module), some of the shape's sketches get left behind. So much so that the shape may move back to it's original position. By selecting all of the linked steps belonging to an object, I can then move the entire parametric object using the Draft module. Much cleaner method.
Post Reply