self.Bind(wx.EVT_MENU, self.OnLoadProfile, i)
i = fileMenu.Append(-1, 'Save Profile...')
self.Bind(wx.EVT_MENU, self.OnSaveProfile, i)
+ i = fileMenu.Append(-1, 'Load Profile from GCode...')
+ self.Bind(wx.EVT_MENU, self.OnLoadProfileFromGcode, i)
fileMenu.AppendSeparator()
i = fileMenu.Append(-1, 'Reset Profile to default')
self.Bind(wx.EVT_MENU, self.OnResetProfile, i)
profile.loadGlobalProfile(profileFile)
self.updateProfileToControls()
dlg.Destroy()
+
+ def OnLoadProfileFromGcode(self, e):
+ dlg=wx.FileDialog(self, "Select gcode file to load profile from", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
+ dlg.SetWildcard("gcode files (*.gcode)|*.gcode")
+ if dlg.ShowModal() == wx.ID_OK:
+ gcodeFile = dlg.GetPath()
+ f = open(gcodeFile, 'r')
+ hasProfile = False
+ for line in f:
+ if line.startswith(';CURA_PROFILE_STRING:'):
+ profile.loadGlobalProfileFromString(line[line.find(':')+1:].strip())
+ hasProfile = True
+ if hasProfile:
+ self.updateProfileToControls()
+ else:
+ wx.MessageBox('No profile found in GCode file.\nThis feature only works with GCode files made by Cura 12.07 or newer.', 'Profile load error', wx.OK | wx.ICON_INFORMATION)
+ dlg.Destroy()
def OnSaveProfile(self, e):
dlg=wx.FileDialog(self, "Select profile file to save", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
### Get the alteration file for output. (Used by Skeinforge)\r
def getAlterationFileContents(filename):\r
prefix = ''\r
+ postfix = ''\r
alterationContents = getAlterationFile(filename)\r
if filename == 'start.gcode':\r
#For the start code, hack the temperature and the steps per E value into it. So the temperature is reached before the start code extrusion.\r
temp = getProfileSettingFloat('print_temperature')\r
if temp > 0 and not '{print_temperature}' in alterationContents:\r
prefix += 'M109 S%f\n' % (temp)\r
+ elif filename == 'end.gcode':\r
+ #Append the profile string to the end of the GCode, so we can load it from the GCode file later.\r
+ postfix = ';CURA_PROFILE_STRING:%s\n' % (getGlobalProfileString())\r
elif filename == 'replace.csv':\r
#Always remove the extruder on/off M codes. These are no longer needed in 5D printing.\r
prefix = 'M101\nM103\n'\r
\r
- return unicode(prefix + re.sub("\{[^\}]*\}", replaceTagMatch, alterationContents).rstrip() + '\n').encode('utf-8')\r
+ return unicode(prefix + re.sub("\{[^\}]*\}", replaceTagMatch, alterationContents).rstrip() + '\n' + postfix).encode('utf-8')\r
\r