From 4ba221c5bbec43849240f9a496d679cedb051b69 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Thu, 9 May 2019 20:12:56 +0800 Subject: [PATCH] gui: add command for adding App::Placement --- assembly.py | 34 +++++++++++++++++++--------------- gui.py | 7 +++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/assembly.py b/assembly.py index b0076ee..3cb5c02 100644 --- a/assembly.py +++ b/assembly.py @@ -4091,11 +4091,6 @@ class AsmWorkPlane(object): if tp == 3: obj = Assembly.addOrigin(info.PartGroup,name) else: - if not name: - name = 'Workplane' - obj = doc.addObject('Part::FeaturePython',name) - AsmWorkPlane(obj) - ViewProviderAsmWorkPlane(obj.ViewObject) if tp==1: pla = FreeCAD.Placement(info.Placement.Base, FreeCAD.Rotation(FreeCAD.Vector(0,1,0),-90)) @@ -4105,16 +4100,25 @@ class AsmWorkPlane(object): else: pla = info.Placement - if utils.isVertex(info.Shape): - obj.Length = obj.Width = 0 - elif utils.isLinearEdge(info.Shape): - if info.BoundBox.isValid(): - obj.Length = info.BoundBox.DiagonalLength - obj.Width = 0 - pla = FreeCAD.Placement(pla.Base,pla.Rotation.multiply( - FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90))) - elif info.BoundBox.isValid(): - obj.Length = obj.Width = info.BoundBox.DiagonalLength + if tp == 4: + if not name: + name = 'Placement' + obj = doc.addObject('App::Placement',name) + elif not name: + name = 'Workplane' + obj = doc.addObject('Part::FeaturePython',name) + AsmWorkPlane(obj) + ViewProviderAsmWorkPlane(obj.ViewObject) + if utils.isVertex(info.Shape): + obj.Length = obj.Width = 0 + elif utils.isLinearEdge(info.Shape): + if info.BoundBox.isValid(): + obj.Length = info.BoundBox.DiagonalLength + obj.Width = 0 + pla = FreeCAD.Placement(pla.Base,pla.Rotation.multiply( + FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90))) + elif info.BoundBox.isValid(): + obj.Length = obj.Width = info.BoundBox.DiagonalLength obj.Placement = pla diff --git a/gui.py b/gui.py index 0bf53b0..2782835 100644 --- a/gui.py +++ b/gui.py @@ -756,6 +756,12 @@ class AsmCmdAddWorkplaneZY(AsmCmdAddWorkplane): _iconName = 'Assembly_Add_WorkplaneZY.svg' _makeType = 2 +class AsmCmdAddPlacement(AsmCmdAddWorkplane): + _id = 30 + _menuText = 'Add placement' + _iconName = 'Assembly_Add_Placement.svg' + _makeType = 4 + class AsmCmdAddOrigin(AsmCmdCheckable): _id = 14 _menuText = 'Add Origin' @@ -788,6 +794,7 @@ class AsmCmdAddWorkplaneGroup(AsmCmdBase): _cmds = (AsmCmdAddWorkplane.getName(), AsmCmdAddWorkplaneXZ.getName(), AsmCmdAddWorkplaneZY.getName(), + AsmCmdAddPlacement.getName(), AsmCmdAddOrigin.getName()) @classmethod