mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-06 05:48:04 +08:00
Add support for {filename} tag in gcode.
This commit is contained in:
parent
ad48bc6484
commit
9fd5a9b020
@ -93,9 +93,9 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp
|
|||||||
|
|
||||||
def getCraftedText(fileName, text='', repository=None):
|
def getCraftedText(fileName, text='', repository=None):
|
||||||
'Alteration a gcode linear move text.'
|
'Alteration a gcode linear move text.'
|
||||||
return getCraftedTextFromText(archive.getTextIfEmpty(fileName, text), repository)
|
return getCraftedTextFromText(archive.getTextIfEmpty(fileName, text), repository, fileName)
|
||||||
|
|
||||||
def getCraftedTextFromText(gcodeText, repository=None):
|
def getCraftedTextFromText(gcodeText, repository=None, fileName=''):
|
||||||
'Alteration a gcode linear move text.'
|
'Alteration a gcode linear move text.'
|
||||||
if gcodec.isProcedureDoneOrFileIsEmpty(gcodeText, 'alteration'):
|
if gcodec.isProcedureDoneOrFileIsEmpty(gcodeText, 'alteration'):
|
||||||
return gcodeText
|
return gcodeText
|
||||||
@ -103,7 +103,7 @@ def getCraftedTextFromText(gcodeText, repository=None):
|
|||||||
repository = settings.getReadRepository(AlterationRepository())
|
repository = settings.getReadRepository(AlterationRepository())
|
||||||
if not repository.activateAlteration.value:
|
if not repository.activateAlteration.value:
|
||||||
return gcodeText
|
return gcodeText
|
||||||
return AlterationSkein().getCraftedGcode(gcodeText, repository)
|
return AlterationSkein().getCraftedGcode(gcodeText, repository, fileName)
|
||||||
|
|
||||||
def getGcodeTextWithoutRedundantMcode(gcodeText):
|
def getGcodeTextWithoutRedundantMcode(gcodeText):
|
||||||
'Get gcode text without redundant M104 and M108.'
|
'Get gcode text without redundant M104 and M108.'
|
||||||
@ -170,11 +170,12 @@ class AlterationSkein:
|
|||||||
|
|
||||||
def addFromUpperLowerFile(self, fileName):
|
def addFromUpperLowerFile(self, fileName):
|
||||||
"Add lines of text from the fileName or the lowercase fileName, if there is no file by the original fileName in the directory."
|
"Add lines of text from the fileName or the lowercase fileName, if there is no file by the original fileName in the directory."
|
||||||
alterationFileLines = settings.getAlterationFileLines(fileName)
|
alterationFileLines = map(lambda l: l.replace('?filename?', self.fileName), settings.getAlterationFileLines(fileName))
|
||||||
self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(alterationFileLines)
|
self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(alterationFileLines)
|
||||||
|
|
||||||
def getCraftedGcode(self, gcodeText, repository):
|
def getCraftedGcode(self, gcodeText, repository, fileName):
|
||||||
"Parse gcode text and store the bevel gcode."
|
"Parse gcode text and store the bevel gcode."
|
||||||
|
self.fileName = fileName
|
||||||
self.lines = archive.getTextLines(gcodeText)
|
self.lines = archive.getTextLines(gcodeText)
|
||||||
if repository.replaceVariableWithSetting.value:
|
if repository.replaceVariableWithSetting.value:
|
||||||
self.setSettingDictionary()
|
self.setSettingDictionary()
|
||||||
|
@ -81,7 +81,7 @@ profileDefaultSettings = {
|
|||||||
}
|
}
|
||||||
alterationDefault = {
|
alterationDefault = {
|
||||||
#######################################################################################
|
#######################################################################################
|
||||||
'start.gcode': """;Sliced at: {day} {date} {time}
|
'start.gcode': """;Sliced {filename} at: {day} {date} {time}
|
||||||
;Basic settings: Layer height: {layer_height} Walls: {wall_thickness} Fill: {fill_density}
|
;Basic settings: Layer height: {layer_height} Walls: {wall_thickness} Fill: {fill_density}
|
||||||
;Print time: {print_time}
|
;Print time: {print_time}
|
||||||
;Filament used: {filament_amount}m {filament_weight}g
|
;Filament used: {filament_amount}m {filament_weight}g
|
||||||
@ -388,7 +388,7 @@ def calculateSolidLayerCount():
|
|||||||
## Alteration file functions
|
## Alteration file functions
|
||||||
#########################################################
|
#########################################################
|
||||||
def replaceTagMatch(m):
|
def replaceTagMatch(m):
|
||||||
tag = m.group(0)[1:-1]
|
tag = m.group(1)
|
||||||
if tag == 'time':
|
if tag == 'time':
|
||||||
return time.strftime('%H:%M:%S')
|
return time.strftime('%H:%M:%S')
|
||||||
if tag == 'date':
|
if tag == 'date':
|
||||||
@ -410,7 +410,7 @@ def replaceTagMatch(m):
|
|||||||
elif isPreference(tag):
|
elif isPreference(tag):
|
||||||
f = getProfileSettingFloat(tag)
|
f = getProfileSettingFloat(tag)
|
||||||
else:
|
else:
|
||||||
return tag
|
return '?%s?' % (tag)
|
||||||
if (f % 1) == 0:
|
if (f % 1) == 0:
|
||||||
return str(int(f))
|
return str(int(f))
|
||||||
return str(f)
|
return str(f)
|
||||||
@ -478,5 +478,5 @@ def getAlterationFileContents(filename):
|
|||||||
#Always remove the extruder on/off M codes. These are no longer needed in 5D printing.
|
#Always remove the extruder on/off M codes. These are no longer needed in 5D printing.
|
||||||
prefix = 'M101\nM103\n'
|
prefix = 'M101\nM103\n'
|
||||||
|
|
||||||
return unicode(prefix + re.sub("\{[^\}]*\}", replaceTagMatch, alterationContents).rstrip() + '\n' + postfix).encode('utf-8')
|
return unicode(prefix + re.sub("\{([^\}]*)\}", replaceTagMatch, alterationContents).rstrip() + '\n' + postfix).encode('utf-8')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user