From 380b4a7b62ad42efc247692ad09294bb11a65128 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sat, 23 Jan 2016 19:39:34 -0200 Subject: [PATCH] Path: Fixed non-functioning Path From Shape --- src/Mod/Path/PathScripts/PathFromShape.py | 41 +++++++++++------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathFromShape.py b/src/Mod/Path/PathScripts/PathFromShape.py index 21518197dee9..118676aebb02 100644 --- a/src/Mod/Path/PathScripts/PathFromShape.py +++ b/src/Mod/Path/PathScripts/PathFromShape.py @@ -36,7 +36,10 @@ def translate(context, text, disambig=None): def translate(context, text, disambig=None): return QtGui.QApplication.translate(context, text, disambig) +#TODO make the shape parametric class FromShape: + + def __init__(self,obj): obj.addProperty("App::PropertyLink","Base","Shape",translate("Shape Object","The base Shape of this toolpath")) obj.Proxy = self @@ -53,6 +56,7 @@ def execute(self,obj): class _ViewProviderFromShape: + def __init__(self,vobj): #mandatory vobj.Proxy = self @@ -72,37 +76,30 @@ def getIcon(self): #optional class CommandFromShape: def GetResources(self): return {'Pixmap' : 'Path-Shape', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("PathFromShape","Gcode from a Shape"), + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_FromShape","Path from a Shape"), 'Accel': "P, S", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathFromShape","Creates GCode from a FreeCAD wire/curve")} + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_FromShape","Creates a Path from a wire/curve")} def IsActive(self): return not FreeCAD.ActiveDocument is None def Activated(self): - FreeCAD.ActiveDocument.openTransaction(translate("PathFromShape","Create GCode from a wire/curve")) - FreeCADGui.addModule("PathScripts.PathFromShape") - - consolecode = ''' -import Path -import PathScripts -from PathScripts import PathFromShape -from PathScripts import PathUtils - -obj = FreeCAD.activeDocument().addObject('Path::FeatureShape','PathShape') -obj.Shape= FreeCAD.activeDocument().Rectangle.Shape.copy() - -PathUtils.addToProject(obj) - -PathScripts.PathFromShape._ViewProviderFromShape(obj.ViewObject) -App.ActiveDocument.recompute() -''' - FreeCADGui.doCommand(consolecode) + + # check that the selection contains exactly what we want + selection = FreeCADGui.Selection.getSelection() + if len(selection) != 1: + FreeCAD.Console.PrintError(translate("Path_FromShape","Please select exactly one Part-based object\n")) + return + if not(selection[0].isDerivedFrom("Part::Feature")): + FreeCAD.Console.PrintError(translate("Path_FromShape","Please select exactly one Part-based object\n")) + return + + FreeCAD.ActiveDocument.openTransaction(translate("Path_FromShape","Create path from shape")) + FreeCADGui.doCommand("obj = FreeCAD.activeDocument().addObject('Path::FeatureShape','PathShape')") + FreeCADGui.doCommand("obj.Shape = FreeCAD.activeDocument()."+selection[0].Name+".Shape") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() if FreeCAD.GuiUp: # register the FreeCAD command FreeCADGui.addCommand('Path_FromShape',CommandFromShape()) - -FreeCAD.Console.PrintLog("Loading PathFromShape... done\n")