From b4eb9b72070f0138ded019eae488952488d80b27 Mon Sep 17 00:00:00 2001 From: Youen Date: Wed, 5 Oct 2022 12:12:33 +0200 Subject: [PATCH] added code to annotate an object in TechDraw with its name (wip) --- InitGui.py | 3 +++ ahb_cmd_view_annotate.py | 49 ++++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/InitGui.py b/InitGui.py index a719139..91c863e 100644 --- a/InitGui.py +++ b/InitGui.py @@ -67,6 +67,9 @@ class AssemblyHandbookWorkbench(Gui.Workbench): self.importModule('ahb_cmd_animate') toolbox.append("AHB_animate") + + self.importModule('ahb_cmd_view_annotate') + toolbox.append("AHB_view_annotate") if self.dev: self.importModule('ahb_cmd_parse_step') diff --git a/ahb_cmd_view_annotate.py b/ahb_cmd_view_annotate.py index c85f525..ef9dacb 100644 --- a/ahb_cmd_view_annotate.py +++ b/ahb_cmd_view_annotate.py @@ -1,17 +1,42 @@ -doc = App.activeDocument() -view = doc.getObject('View') +import FreeCADGui as Gui +import FreeCAD as App -if len(Gui.Selection.getSelection()) != 1: - raise Exception("Veuillez sélectionner exactement un objet") +class AHB_View_Annotate: + def GetResources(self): + return {"MenuText": "View/Annotate", + "ToolTip": "Annotates a TechDraw view with object names", + "Pixmap": "" + } -object = Gui.Selection.getSelection()[0] + def IsActive(self): + return True -# Get object center in view space -objectCenterWorld = object.LinkPlacement.Matrix.multiply(object.LinkedObject.Shape.CenterOfGravity) -vertId = view.makeCosmeticVertex3d(objectCenterWorld) -vert = view.getCosmeticVertex(vertId) -objectCenterView = vert.Point -view.removeCosmeticVertex(vertId) + def Activated(self): + doc = App.activeDocument() + page = doc.getObject('Page') + view = page.Views[0] -# Create Balloon + if len(Gui.Selection.getSelection()) != 1: + raise Exception("Veuillez sélectionner exactement un objet") + object = Gui.Selection.getSelection()[0] + + # Get object center in view space + objectCenterWorld = object.LinkPlacement.Matrix.multiply(object.LinkedObject.Shape.CenterOfGravity) + vertId = view.makeCosmeticVertex3d(objectCenterWorld) + vert = view.getCosmeticVertex(vertId) + objectCenterView = vert.Point + view.removeCosmeticVertex(vertId) + + # Create Balloon + balloon = App.ActiveDocument.addObject("TechDraw::DrawViewBalloon", "Balloon") + balloon.SourceView = view + balloon.OriginX = objectCenterView.x + balloon.OriginY = objectCenterView.y + balloon.Text = "1" + balloon.Y = objectCenterView.x + 20 + balloon.X = objectCenterView.y + 20 + page.addView(balloon) + +from ahb_command import AHB_CommandWrapper +AHB_CommandWrapper.addGuiCommand('AHB_view_annotate', AHB_View_Annotate())