Determine object visibility.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Determine object visibility.
Unnested Body results in "TypeError: 'NoneType' object is not iterable".
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Determine object visibility.
Ah, so it returns None instead of an empty list [].
Code: Select all
def getParents(obj):
if hasattr(obj,"Parents") and obj.Parents:
return [obj.Parents[0][0]]+[FreeCAD.ActiveDocument.getObject(p) for p in obj.Parents[0][1].split('.') if obj != FreeCAD.ActiveDocument.getObject(p) and p != '']
def isVisible(obj):
if not obj.ViewObject.Visibility:
return False
if not obj.VisibleFeature:
return False
parents = getParents(obj)
if not parents:
return True
for par in parents:
if not par.ViewObject.Visibility:
return False
return True
bodies = [obj for obj in FreeCAD.ActiveDocument.Objects if obj.TypeId == "PartDesign::Body"]
FreeCADGui.Selection.clearSelection()
for body in bodies:
if isVisible(body):
FreeCADGui.Selection.addSelection(FreeCAD.ActiveDocument.Name,body.Name)