diff --git a/src/Mod/Path/PathScripts/PathCustom.py b/src/Mod/Path/PathScripts/PathCustom.py index f66ca4f20a..de8290696d 100644 --- a/src/Mod/Path/PathScripts/PathCustom.py +++ b/src/Mod/Path/PathScripts/PathCustom.py @@ -24,10 +24,11 @@ import FreeCAD import FreeCADGui import Path -from PySide import QtCore, QtGui +from PySide import QtCore """Path Custom object and FreeCAD command""" + # Qt tanslation handling def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) @@ -35,9 +36,8 @@ def translate(context, text, disambig=None): class ObjectCustom: - def __init__(self,obj): - obj.addProperty("App::PropertyStringList","Gcode","Path",QtCore.QT_TRANSLATE_NOOP("App::Property","The gcode to be inserted")) + obj.addProperty("App::PropertyStringList", "Gcode", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "The gcode to be inserted")) obj.Proxy = self def __getstate__(self): @@ -74,8 +74,7 @@ class CommandPathCustom: FreeCAD.ActiveDocument.openTransaction("Create Custom Path") FreeCADGui.addModule("PathScripts.PathCustom") FreeCADGui.addModule("PathScripts.PathUtils") - FreeCADGui.doCommand( - 'obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Custom")') + FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","Custom")') FreeCADGui.doCommand('PathScripts.PathCustom.ObjectCustom(obj)') FreeCADGui.doCommand('obj.ViewObject.Proxy = 0') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') diff --git a/src/Mod/Path/PathScripts/PathSimpleCopy.py b/src/Mod/Path/PathScripts/PathSimpleCopy.py index 34b7c42ec1..086165bdab 100644 --- a/src/Mod/Path/PathScripts/PathSimpleCopy.py +++ b/src/Mod/Path/PathScripts/PathSimpleCopy.py @@ -23,14 +23,17 @@ import FreeCAD import FreeCADGui -from PySide import QtCore, QtGui +import PathScripts +from PySide import QtCore """Path SimpleCopy command""" + # Qt tanslation handling def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) + class CommandPathSimpleCopy: def GetResources(self): @@ -39,11 +42,13 @@ class CommandPathSimpleCopy: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_SimpleCopy", "Creates a non-parametric copy of another path")} def IsActive(self): - if FreeCAD.ActiveDocument is not None: - for o in FreeCAD.ActiveDocument.Objects: - if o.Name[:3] == "Job": - return True - return False + if bool(FreeCADGui.Selection.getSelection()) is False: + return False + try: + obj = FreeCADGui.Selection.getSelectionEx()[0].Object + return isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp) + except: + return False def Activated(self): # check that the selection contains exactly what we want @@ -59,11 +64,14 @@ class CommandPathSimpleCopy: FreeCAD.ActiveDocument.openTransaction( translate("Path_SimpleCopy", "Simple Copy")) + FreeCADGui.doCommand("srcpath = FreeCADGui.Selection.getSelectionEx()[0].Object.Path\n") + FreeCADGui.addModule("PathScripts.PathUtils") - FreeCADGui.doCommand( - 'obj = FreeCAD.ActiveDocument.addObject("Path::Feature","' + selection[0].Name + '_copy")') - FreeCADGui.doCommand( - 'obj.Path = FreeCAD.ActiveDocument.' + selection[0].Name + '.Path') + FreeCADGui.addModule("PathScripts.PathCustom") + FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython","' + selection[0].Name + '_SimpleCopy")') + FreeCADGui.doCommand('PathScripts.PathCustom.ObjectCustom(obj)') + FreeCADGui.doCommand('obj.ViewObject.Proxy = 0') + FreeCADGui.doCommand('obj.Gcode = [c.toGCode() for c in srcpath.Commands]') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()