From 819644560a1174079f90748bd75ac1bccdbbcd94 Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Fri, 21 Jan 2022 23:37:08 +0100 Subject: [PATCH] possibility to set stage on groups (wip) --- ahb_cmd_set_part_stage.py | 15 +++++++++++---- ahb_context.py | 13 +++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ahb_cmd_set_part_stage.py b/ahb_cmd_set_part_stage.py index 523d572..444987e 100644 --- a/ahb_cmd_set_part_stage.py +++ b/ahb_cmd_set_part_stage.py @@ -22,15 +22,22 @@ class AHB_SetPartStage: obj: App.DocumentObject for obj in Gui.Selection.getSelection(): - if obj is not None and obj.TypeId == 'Part::Feature': + if obj is not None and obj.TypeId in ['Part::Feature','App::Part']: if not "AssemblyHandbook_Stage" in obj.PropertiesList: obj.addProperty("App::PropertyInteger", "AssemblyHandbook_Stage", "AssemblyHandbook") if not "AssemblyHandbook_RenderLines" in obj.PropertiesList: obj.addProperty("App::PropertyBool", "AssemblyHandbook_RenderLines", "AssemblyHandbook") obj.AssemblyHandbook_RenderLines = True - if obj.AssemblyHandbook_Stage != stageId: - obj.AssemblyHandbook_Stage = stageId - workbench.context.onPartStageChanged(obj) + + obj.AssemblyHandbook_Stage = stageId + + # if we are setting the stage on a part, remove the property from all features of that part + if obj.TypeId == 'App::Part': + for feature in obj.Group: + if 'AssemblyHandbook_Stage' in feature.PropertiesList: + feature.removeProperty('AssemblyHandbook_Stage') + + workbench.context.onPartStageChanged(obj) from ahb_command import AHB_CommandWrapper AHB_CommandWrapper.addGuiCommand('AHB_setPartStage', AHB_SetPartStage()) diff --git a/ahb_context.py b/ahb_context.py index 70d3493..e4dec63 100644 --- a/ahb_context.py +++ b/ahb_context.py @@ -39,7 +39,7 @@ class AHB_Context: doc = App.ActiveDocument for obj in doc.Objects: - if obj.TypeId == 'Part::Feature': + if obj.TypeId in ['Part::Feature', 'App::Part']: if 'AssemblyHandbook_Stage' in obj.PropertiesList: allStages.add(obj.AssemblyHandbook_Stage) @@ -56,10 +56,15 @@ class AHB_Context: part.ViewObject.ShapeColor = (0.8,0.8,0.8,0.0) for obj in doc.Objects: - if obj.TypeId == 'Part::Feature': + if obj.TypeId in ['Part::Feature', 'App::Part']: if 'AssemblyHandbook_Stage' in obj.PropertiesList: stageIndex = allStages.index(obj.AssemblyHandbook_Stage) - obj.ViewObject.ShapeColor = _colors[stageIndex % len(_colors)] + if obj.TypeId == 'Part::Feature': + obj.ViewObject.ShapeColor = _colors[stageIndex % len(_colors)] + elif obj.TypeId == 'App::Part': + for feature in obj.Group: + if feature.TypeId == 'Part::Feature': + feature.ViewObject.ShapeColor = _colors[stageIndex % len(_colors)] self._updateVisibility() @@ -75,7 +80,7 @@ class AHB_Context: doc = App.ActiveDocument for obj in doc.Objects: - if obj.TypeId == 'Part::Feature': + if obj.TypeId == 'Part::Feature' in ['Part::Feature', 'App::Part']: if 'AssemblyHandbook_Stage' in obj.PropertiesList: obj.ViewObject.Visibility = self._allStagesVisible or activeStageId is None or obj.AssemblyHandbook_Stage <= activeStageId