Skip to content

Commit

Permalink
Path: Fixed non-functioning Path From Shape
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jan 23, 2016
1 parent baf103a commit 380b4a7
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/Mod/Path/PathScripts/PathFromShape.py
Expand Up @@ -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
Expand All @@ -53,6 +56,7 @@ def execute(self,obj):

class _ViewProviderFromShape:


def __init__(self,vobj): #mandatory
vobj.Proxy = self

Expand All @@ -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")

0 comments on commit 380b4a7

Please sign in to comment.