You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.9 KiB
43 lines
1.9 KiB
from typing import Optional |
|
|
|
import FreeCADGui as Gui |
|
import FreeCAD as App |
|
|
|
class AHB_SetPartStage: |
|
def GetResources(self): |
|
return {"MenuText": "Set part stage", |
|
"ToolTip": "Sets the stage for this part to the currently active stage", |
|
"Pixmap": "" |
|
} |
|
|
|
def IsActive(self): |
|
return True |
|
|
|
def Activated(self, stageId: Optional[int] = None): |
|
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") |
|
if stageId is None: |
|
stageId = workbench.context.getActiveStage() |
|
if stageId is None: |
|
raise BaseException("You must activate a stage before using this command") |
|
|
|
obj: App.DocumentObject |
|
for obj in Gui.Selection.getSelection(): |
|
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 |
|
|
|
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())
|
|
|