Fixed template-export menu activation.
This commit is contained in:
@@ -312,6 +312,12 @@ class ObjectJob:
|
||||
'''Answer true if the given object can be used as a Base for a job.'''
|
||||
return PathUtil.isValidBaseObject(obj) or isArchPanelSheet(obj)
|
||||
|
||||
def Instances():
|
||||
'''Instances() ... Return all Jobs in the current active document.'''
|
||||
if FreeCAD.ActiveDocument:
|
||||
return [job for job in FreeCAD.ActiveDocument.Objects if hasattr(job, 'Proxy') and isinstance(job.Proxy, ObjectJob)]
|
||||
return []
|
||||
|
||||
def Create(name, base, templateFile = None):
|
||||
'''Create(name, base, templateFile=None) ... creates a new job and all it's resources.
|
||||
If a template file is specified the new job is initialized with the values from the template.'''
|
||||
|
||||
@@ -224,11 +224,26 @@ class CommandJobTemplateExport:
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Export Template"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Exports Path Job as a template to be used for other jobs")}
|
||||
|
||||
def GetJob(self):
|
||||
# if there's only one Job in the document ...
|
||||
jobs = PathJob.Instances()
|
||||
if not jobs:
|
||||
return None
|
||||
if len(jobs) == 1:
|
||||
return jobs[0]
|
||||
# more than one job, is one of them selected?
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
if len(sel) == 1:
|
||||
job = sel[0]
|
||||
return hasattr(job, 'Proxy') and isinstance(job.Proxy, PathJob.ObjectJob)
|
||||
return None
|
||||
|
||||
|
||||
def IsActive(self):
|
||||
return FreeCAD.ActiveDocument is not None
|
||||
return self.GetJob() is not None
|
||||
|
||||
def Activated(self):
|
||||
job = FreeCADGui.Selection.getSelection()[0]
|
||||
job = self.GetJob()
|
||||
dialog = DlgJobTemplateExport(job)
|
||||
if dialog.exec_() == 1:
|
||||
foo = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(),
|
||||
|
||||
@@ -486,22 +486,15 @@ def findParentJob(obj):
|
||||
|
||||
def GetJobs(jobname=None):
|
||||
'''returns all jobs in the current document. If name is given, returns that job'''
|
||||
PathLog.track()
|
||||
jobs = []
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if hasattr(o, 'Proxy') and isinstance(o.Proxy, PathJob.ObjectJob):
|
||||
if jobname is not None:
|
||||
if o.Name == jobname:
|
||||
jobs.append(o)
|
||||
else:
|
||||
jobs.append(o)
|
||||
return jobs
|
||||
if jobname:
|
||||
return [job for job in PathJob.Instances() if job.Name == jobname]
|
||||
return PathJob.Instances()
|
||||
|
||||
def addToJob(obj, jobname=None):
|
||||
'''adds a path object to a job
|
||||
obj = obj
|
||||
jobname = None'''
|
||||
PathLog.track()
|
||||
PathLog.track(jobname)
|
||||
if jobname is not None:
|
||||
jobs = GetJobs(jobname)
|
||||
if len(jobs) == 1:
|
||||
@@ -513,7 +506,6 @@ def addToJob(obj, jobname=None):
|
||||
jobs = GetJobs()
|
||||
if len(jobs) == 0:
|
||||
job = PathJobCmd.CommandJobCreate().Activated()
|
||||
|
||||
elif len(jobs) == 1:
|
||||
job = jobs[0]
|
||||
else:
|
||||
@@ -528,7 +520,7 @@ def addToJob(obj, jobname=None):
|
||||
print(form.cboProject.currentText())
|
||||
job = [i for i in jobs if i.Label == form.cboProject.currentText()][0]
|
||||
|
||||
if obj:
|
||||
if obj and job:
|
||||
job.Proxy.addOperation(obj)
|
||||
return job
|
||||
|
||||
|
||||
Reference in New Issue
Block a user