From 4cf613ec31632285c5e2da5e7cf6ea4479a5cc78 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Thu, 28 Sep 2023 15:19:25 +0200 Subject: [PATCH] Draft: get_movable_children: prevent endless loop Forum topic: https://forum.freecad.org/viewtopic.php?t=81547 --- src/Mod/Draft/draftutils/groups.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Mod/Draft/draftutils/groups.py b/src/Mod/Draft/draftutils/groups.py index a1e5f15789..e48851395d 100644 --- a/src/Mod/Draft/draftutils/groups.py +++ b/src/Mod/Draft/draftutils/groups.py @@ -276,7 +276,7 @@ def getGroupContents(objectslist, spaces, noarchchild) -def get_movable_children(objectslist, recursive=True): +def get_movable_children(objectslist, recursive=True, _donelist=[]): """Return a list of objects with child objects that move with a host. Builds a list of objects with all child objects (`obj.OutList`) @@ -295,6 +295,9 @@ def get_movable_children(objectslist, recursive=True): Otherwise, only direct children of the input objects are added to the output list. + _donelist: list + List of object names. Used internally to prevent an endless loop. + Returns ------- list @@ -306,8 +309,14 @@ def get_movable_children(objectslist, recursive=True): objectslist = [objectslist] for obj in objectslist: + if obj.Name in _donelist: + continue + + _donelist.append(obj.Name) + # Skips some objects that should never move their children - if utils.get_type(obj) not in ("Clone", "SectionPlane", + if utils.get_type(obj) not in ("App::Part", "PartDesign::Body", + "Clone", "SectionPlane", "Facebinder", "BuildingPart", "App::Link"): children = obj.OutList if (hasattr(obj, "Proxy") and obj.Proxy @@ -318,17 +327,14 @@ def get_movable_children(objectslist, recursive=True): for child in children: if hasattr(child, "MoveWithHost") and child.MoveWithHost: - if hasattr(obj, "CloneOf"): - if obj.CloneOf: - if obj.CloneOf.Name != child.Name: - added.append(child) - else: + if hasattr(obj, "CloneOf") and obj.CloneOf: + if obj.CloneOf.Name != child.Name: added.append(child) else: added.append(child) if recursive: - added.extend(get_movable_children(children)) + added.extend(get_movable_children(children, recursive, _donelist)) return added