-- Flow_rate.lua -- KISSlicer example code -- open files collectgarbage() -- ensure unused files are closed local fin = assert( io.open( arg[1] ) ) -- reading local fout = assert( io.open( arg[1] .. "-processed.g", "wb" ) ) -- writing must be binary -- Set extrusion height and width to automatically calculate the required perimter flow rate based on Nopheads equation height = 0.2 width = 0.53 perimeter = math.floor((1 + (3.14159/4 -1) / (width/height))*100) -- Set flow rate in percentage of default flow rate -- Uses M221 Snn interface = 100 support = 100 loops = 100 solid_infill = 100 sparse_infill = 100 -- read lines for line in fin:lines() do local inter = line:match( "; 'Support Interface',") -- Find start of support interface local sup = line:match( "; 'Support (may Stack)',") -- Find start of support local perim = line:match( "; 'Perimeter',") -- Find start of perimeter local loop = line:match( "; 'Loop',") -- Find start of loops local solid = line:match( "; 'Solid',") -- Find start of solid infill local sparse = line:match( "; 'Stacked Sparse Infill',") -- Find start of sparse infill -- Set new flow rate of support interface if inter then fout:write("; Set support interface flow rate.\r\n") fout:write("M221 S") fout:write(interface) fout:write("\r\n") fout:write(line) -- Set new flow rate of support elseif sup then fout:write("; Set support flow rate.\r\n") fout:write("M221 S") fout:write(support) fout:write("\r\n\r\n") fout:write(line) -- Set new flow rate of outer perimeter elseif perim then fout:write("; Set perimeter flow rate.\r\n") fout:write("M221 S") fout:write(perimeter) fout:write("\r\n\r\n") fout:write(line) -- Set new flow rate of loops elseif loop then fout:write("; Set flow rate for loops.\r\n") fout:write("M221 S") fout:write(loops) fout:write("\r\n\r\n") fout:write(line) -- Set new flow rate of solid infill elseif solid then fout:write("; Set solid infill flow rate.\r\n") fout:write("M221 S") fout:write(solid_infill) fout:write("\r\n\r\n") fout:write(line) -- Set new flow rate of sparse infill elseif sparse then fout:write("; Set sparse infill flow rate.\r\n") fout:write("M221 S") fout:write(sparse_infill) fout:write("\r\n\r\n") fout:write(line) else fout:write( line .. "\n" ) end end -- done fin:close() fout:close() print "done"