#Name: Print on Object #Info: Lets you print an object on an other one. Attention, be sure that the printhead can go to his home position to initialize. Deactivate the skirt (for Cura - 13.06.4 under Expert --> Open expert settings... --> Skirt, set Line count to "0"). Check for the comment about PrintonObject plugin used in gcode on first line. #Depend: GCode #Type: postprocess #Param: objectheight(float:0) Object height (mm) #version of the plugin version = 1.1 #import the Library of Regular expressions import re #only lines with this key will be processed key = "Z" #comment sign used in gcode files commentsign = ";" #compile regular expression to a pattern object and save it regex = re.compile("Z[0-9]+\\.?[0-9]*") #search and change the values of the "Z" axis. #key = only lines with this key will be processed #line = the current line who will be edited #objectheight = the value which will be added to the current value of the "Z" axis #commentsign = commentsign of Gcode files, #regex = regular expression pattern object which is used to find the substring who have to be edited. def changeValue(key, line, objectheight, commentsign, regex): #sorts out lines who will not be processed if key in line and not(commentsign in line and line.find(key) > line.find(commentsign)): #saves the result of the search for the regex in the current line in "match" match = regex.search(line) #if there is a result saved in "match" if match != None: #saves the matched substring of the line in "substr" substr = match.group() #so it does'nt change the Home position if float(substr[1::1]) != 0: #replace the current value with the current value + "objectheight" and returns the whole line return line.replace(substr[1::1],str(float(substr[1::1])+objectheight)) #if one, two or all of the ifs aren't true it returns the line unchanged return line #opens the file with the filename provided by Cura in read mode and create the reference "f" with open(filename, "r") as f: #creates an array "lines", an empty list of lines lines = [] #iterates with "line" through every line in the file referenced by "f" for line in f: #add every line to the end of the array "lines" lines.append(line) #opens the file with the filename provided by Cura in write mode and create the reference "f" with open(filename, "w") as f: #write comment header - no more supported by UM2 #f.write("; This Gcode file has been edited with PrintonObject version " + str(version) + "\n") #iterates with "line" through every line in the array "lines" for line in lines: #writes the return value of the function "changeValue" into the file f.write(changeValue(key, line, objectheight, commentsign, regex))