2012-02-10 16:20:03 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
< html > < head > < title > Python: module fabmetheus_utilities.gcodec< / title >
< / head > < body bgcolor = "#f0f0f8" >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "heading" >
< tr bgcolor = "#7799ee" >
< td valign = bottom > < br >
< font color = "#ffffff" face = "helvetica, arial" > < br > < big > < big > < strong > < a href = "fabmetheus_utilities.html" > < font color = "#ffffff" > fabmetheus_utilities< / font > < / a > .gcodec< / strong > < / big > < / big > ($Date: 2008/21/04 $)< / font > < /td
>< td align = right valign = bottom
>< font color = "#ffffff" face = "helvetica, arial" > < a href = "." > index< / a > < br > < a href = "file:/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/fabmetheus_utilities/gcodec.py" > /home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/fabmetheus_utilities/gcodec.py< / a > < / font > < / td > < / tr > < / table >
< p > < tt > Gcodec is a collection of utilities to decode and encode gcode.< br >
< br >
To run gcodec, install python 2.x on your machine, which is avaliable from < a href = "http://www.python.org/download/" > http://www.python.org/download/< / a > < br >
< br >
Then in the folder which gcodec is in, type 'python' in a shell to run the python interpreter. Finally type 'from gcodec import *' to import this program.< br >
< br >
Below is an example of gcodec use. This example is run in a terminal in the folder which contains gcodec and Screw Holder Bottom_export.gcode.< br >
< br >
> > > from gcodec import *< br >
> > > getFileText('Screw Holder Bottom_export.gcode')< br >
'G90< br >
G21< br >
M103< br >
M105< br >
M106< br >
M110 S60.0< br >
M111 S30.0< br >
M108 S210.0< br >
M104 S235.0< br >
G1 X0.37 Y-4.07 Z1.9 F60.0< br >
M101< br >
< br >
..< br >
many lines of text< br >
..< / tt > < / p >
< p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#aa55cc" >
< td colspan = 3 valign = bottom > < br >
< font color = "#ffffff" face = "helvetica, arial" > < big > < strong > Modules< / strong > < / big > < / font > < / td > < / tr >
< tr > < td bgcolor = "#aa55cc" > < tt > < / tt > < / td > < td > < / td >
< td width = "100%" > < table width = "100%" summary = "list" > < tr > < td width = "25%" valign = top > < a href = "__init__.html" > __init__< / a > < br >
< a href = "fabmetheus_utilities.archive.html" > fabmetheus_utilities.archive< / a > < br >
< / td > < td width = "25%" valign = top > < a href = "cStringIO.html" > cStringIO< / a > < br >
< a href = "fabmetheus_utilities.euclidean.html" > fabmetheus_utilities.euclidean< / a > < br >
< / td > < td width = "25%" valign = top > < a href = "math.html" > math< / a > < br >
< a href = "os.html" > os< / a > < br >
< / td > < td width = "25%" valign = top > < a href = "sys.html" > sys< / a > < br >
< a href = "traceback.html" > traceback< / a > < br >
< / td > < / tr > < / table > < / td > < / tr > < / table > < p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#ee77aa" >
< td colspan = 3 valign = bottom > < br >
< font color = "#ffffff" face = "helvetica, arial" > < big > < strong > Classes< / strong > < / big > < / font > < / td > < / tr >
< tr > < td bgcolor = "#ee77aa" > < tt > < / tt > < / td > < td > < / td >
< td width = "100%" > < dl >
< dt > < font face = "helvetica, arial" > < a href = "fabmetheus_utilities.gcodec.html#BoundingRectangle" > BoundingRectangle< / a >
< / font > < / dt > < dt > < font face = "helvetica, arial" > < a href = "fabmetheus_utilities.gcodec.html#DistanceFeedRate" > DistanceFeedRate< / a >
< / font > < / dt > < / dl >
< p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#ffc8d8" >
< td colspan = 3 valign = bottom > < br >
< font color = "#000000" face = "helvetica, arial" > < a name = "BoundingRectangle" > class < strong > BoundingRectangle< / strong > < / a > < / font > < / td > < / tr >
< tr bgcolor = "#ffc8d8" > < td rowspan = 2 > < tt > < / tt > < / td >
< td colspan = 2 > < tt > A class to get the corners of a gcode text.< br > < / tt > < / td > < / tr >
< tr > < td > < / td >
< td width = "100%" > Methods defined here:< br >
< dl > < dt > < a name = "BoundingRectangle-getFromGcodeLines" > < strong > getFromGcodeLines< / strong > < / a > (self, lines, radius)< / dt > < dd > < tt > Parse gcode text and get the minimum and maximum corners.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "BoundingRectangle-isPointInside" > < strong > isPointInside< / strong > < / a > (self, point)< / dt > < dd > < tt > Determine if the point is inside the bounding rectangle.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "BoundingRectangle-parseCorner" > < strong > parseCorner< / strong > < / a > (self, line)< / dt > < dd > < tt > Parse a gcode line and use the location to update the bounding corners.< / tt > < / dd > < / dl >
< / td > < / tr > < / table > < p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#ffc8d8" >
< td colspan = 3 valign = bottom > < br >
< font color = "#000000" face = "helvetica, arial" > < a name = "DistanceFeedRate" > class < strong > DistanceFeedRate< / strong > < / a > < / font > < / td > < / tr >
< tr bgcolor = "#ffc8d8" > < td rowspan = 2 > < tt > < / tt > < / td >
< td colspan = 2 > < tt > A class to limit the z feed rate and round values.< br > < / tt > < / td > < / tr >
< tr > < td > < / td >
< td width = "100%" > Methods defined here:< br >
< dl > < dt > < a name = "DistanceFeedRate-__init__" > < strong > __init__< / strong > < / a > (self)< / dt > < dd > < tt > Initialize.< / tt > < / dd > < / dl >
2012-02-16 14:06:50 +00:00
< dl > < dt > < a name = "DistanceFeedRate-addFlowRateLine" > < strong > addFlowRateLine< / strong > < / a > (self, flowRate)< / dt > < dd > < tt > Add a flow rate line.< / tt > < / dd > < / dl >
2012-02-10 16:20:03 +00:00
< dl > < dt > < a name = "DistanceFeedRate-addGcodeFromFeedRateThreadZ" > < strong > addGcodeFromFeedRateThreadZ< / strong > < / a > (self, feedRateMinute, thread, travelFeedRateMinute, z)< / dt > < dd > < tt > Add a thread to the output.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addGcodeFromLoop" > < strong > addGcodeFromLoop< / strong > < / a > (self, loop, z)< / dt > < dd > < tt > Add the gcode loop.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addGcodeFromThreadZ" > < strong > addGcodeFromThreadZ< / strong > < / a > (self, thread, z)< / dt > < dd > < tt > Add a thread to the output.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addGcodeMovementZ" > < strong > addGcodeMovementZ< / strong > < / a > (self, point, z)< / dt > < dd > < tt > Add a movement to the output.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addGcodeMovementZWithFeedRate" > < strong > addGcodeMovementZWithFeedRate< / strong > < / a > (self, feedRateMinute, point, z)< / dt > < dd > < tt > Add a movement to the output.< / tt > < / dd > < / dl >
2012-02-16 14:06:50 +00:00
< dl > < dt > < a name = "DistanceFeedRate-addGcodeMovementZWithFeedRateVector3" > < strong > addGcodeMovementZWithFeedRateVector3< / strong > < / a > (self, feedRateMinute, vector3)< / dt > < dd > < tt > Add a movement to the output by Vector3.< / tt > < / dd > < / dl >
2012-02-10 16:20:03 +00:00
< dl > < dt > < a name = "DistanceFeedRate-addLine" > < strong > addLine< / strong > < / a > (self, line)< / dt > < dd > < tt > Add a line of text and a newline to the output.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addLineCheckAlteration" > < strong > addLineCheckAlteration< / strong > < / a > (self, line)< / dt > < dd > < tt > Add a line of text and a newline to the output and check to see if it is an alteration line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addLines" > < strong > addLines< / strong > < / a > (self, lines)< / dt > < dd > < tt > Add lines of text to the output.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addLinesSetAbsoluteDistanceMode" > < strong > addLinesSetAbsoluteDistanceMode< / strong > < / a > (self, lines)< / dt > < dd > < tt > Add lines of text to the output and ensure the absolute mode is set.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addParameter" > < strong > addParameter< / strong > < / a > (self, firstWord, parameter)< / dt > < dd > < tt > Add the parameter.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addPerimeterBlock" > < strong > addPerimeterBlock< / strong > < / a > (self, loop, z)< / dt > < dd > < tt > Add the edge gcode block for the loop.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addTagBracketedLine" > < strong > addTagBracketedLine< / strong > < / a > (self, tagName, value)< / dt > < dd > < tt > Add a begin tag, value and end tag.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addTagBracketedProcedure" > < strong > addTagBracketedProcedure< / strong > < / a > (self, procedure)< / dt > < dd > < tt > Add a begin procedure tag, procedure and end procedure tag.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-addTagRoundedLine" > < strong > addTagRoundedLine< / strong > < / a > (self, tagName, value)< / dt > < dd > < tt > Add a begin tag, rounded value and end tag.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getBoundaryLine" > < strong > getBoundaryLine< / strong > < / a > (self, location)< / dt > < dd > < tt > Get boundary gcode line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getFirstWordMovement" > < strong > getFirstWordMovement< / strong > < / a > (self, firstWord, location)< / dt > < dd > < tt > Get the start of the arc line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getInfillBoundaryLine" > < strong > getInfillBoundaryLine< / strong > < / a > (self, location)< / dt > < dd > < tt > Get infill boundary gcode line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getIsAlteration" > < strong > getIsAlteration< / strong > < / a > (self, line)< / dt > < dd > < tt > Determine if it is an alteration.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getLineWithFeedRate" > < strong > getLineWithFeedRate< / strong > < / a > (self, feedRateMinute, line, splitLine)< / dt > < dd > < tt > Get the line with a feed rate.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getLineWithX" > < strong > getLineWithX< / strong > < / a > (self, line, splitLine, x)< / dt > < dd > < tt > Get the line with an x.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getLineWithY" > < strong > getLineWithY< / strong > < / a > (self, line, splitLine, y)< / dt > < dd > < tt > Get the line with a y.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getLineWithZ" > < strong > getLineWithZ< / strong > < / a > (self, line, splitLine, z)< / dt > < dd > < tt > Get the line with a z.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getLinearGcodeMovement" > < strong > getLinearGcodeMovement< / strong > < / a > (self, point, z)< / dt > < dd > < tt > Get a linear gcode movement.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getLinearGcodeMovementWithFeedRate" > < strong > getLinearGcodeMovementWithFeedRate< / strong > < / a > (self, feedRateMinute, point, z)< / dt > < dd > < tt > Get a z limited gcode movement.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-getRounded" > < strong > getRounded< / strong > < / a > (self, number)< / dt > < dd > < tt > Get number rounded to the number of carried decimal places as a string.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "DistanceFeedRate-parseSplitLine" > < strong > parseSplitLine< / strong > < / a > (self, firstWord, splitLine)< / dt > < dd > < tt > Parse gcode split line and store the parameters.< / tt > < / dd > < / dl >
< / td > < / tr > < / table > < / td > < / tr > < / table > < p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#eeaa77" >
< td colspan = 3 valign = bottom > < br >
< font color = "#ffffff" face = "helvetica, arial" > < big > < strong > Functions< / strong > < / big > < / font > < / td > < / tr >
< tr > < td bgcolor = "#eeaa77" > < tt > < / tt > < / td > < td > < / td >
< td width = "100%" > < dl > < dt > < a name = "-addLineAndNewlineIfNecessary" > < strong > addLineAndNewlineIfNecessary< / strong > < / a > (line, output)< / dt > < dd > < tt > Add the line and if the line does not end with a newline add a newline.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-addLinesToCString" > < strong > addLinesToCString< / strong > < / a > (cString, lines)< / dt > < dd > < tt > Add lines which have something to cStringIO.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getArcDistance" > < strong > getArcDistance< / strong > < / a > (relativeLocation, splitLine)< / dt > < dd > < tt > Get arc distance.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getDoubleAfterFirstLetter" > < strong > getDoubleAfterFirstLetter< / strong > < / a > (word)< / dt > < dd > < tt > Get the double value of the word after the first letter.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getDoubleForLetter" > < strong > getDoubleForLetter< / strong > < / a > (letter, splitLine)< / dt > < dd > < tt > Get the double value of the word after the first occurence of the letter in the split line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getDoubleFromCharacterSplitLine" > < strong > getDoubleFromCharacterSplitLine< / strong > < / a > (character, splitLine)< / dt > < dd > < tt > Get the double value of the string after the first occurence of the character in the split line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getDoubleFromCharacterSplitLineValue" > < strong > getDoubleFromCharacterSplitLineValue< / strong > < / a > (character, splitLine, value)< / dt > < dd > < tt > Get the double value of the string after the first occurence of the character in the split line, if it does not exist return the value.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getFeedRateMinute" > < strong > getFeedRateMinute< / strong > < / a > (feedRateMinute, splitLine)< / dt > < dd > < tt > Get the feed rate per minute if the split line has a feed rate.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getFirstWord" > < strong > getFirstWord< / strong > < / a > (splitLine)< / dt > < dd > < tt > Get the first word of a split line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getFirstWordFromLine" > < strong > getFirstWordFromLine< / strong > < / a > (line)< / dt > < dd > < tt > Get the first word of a line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getFirstWordIndexReverse" > < strong > getFirstWordIndexReverse< / strong > < / a > (firstWord, lines, startIndex)< / dt > < dd > < tt > Parse gcode in reverse order until the first word if there is one, otherwise return -1.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getGcodeFileText" > < strong > getGcodeFileText< / strong > < / a > (fileName, gcodeText)< / dt > < dd > < tt > Get the gcode text from a file if it the gcode text is empty and if the file is a gcode file.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getGcodeWithoutDuplication" > < strong > getGcodeWithoutDuplication< / strong > < / a > (duplicateWord, gcodeText)< / dt > < dd > < tt > Get gcode text without duplicate first words.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getIndexOfStartingWithSecond" > < strong > getIndexOfStartingWithSecond< / strong > < / a > (letter, splitLine)< / dt > < dd > < tt > Get index of the first occurence of the given letter in the split line, starting with the second word. Return - 1 if letter is not found< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getLineWithValueString" > < strong > getLineWithValueString< / strong > < / a > (character, line, splitLine, valueString)< / dt > < dd > < tt > Get the line with a valueString.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getLocationFromSplitLine" > < strong > getLocationFromSplitLine< / strong > < / a > (oldLocation, splitLine)< / dt > < dd > < tt > Get the location from the split line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getRotationBySplitLine" > < strong > getRotationBySplitLine< / strong > < / a > (splitLine)< / dt > < dd > < tt > Get the complex rotation from the split gcode line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getSplitLineBeforeBracketSemicolon" > < strong > getSplitLineBeforeBracketSemicolon< / strong > < / a > (line)< / dt > < dd > < tt > Get the split line before a bracket or semicolon.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getStringFromCharacterSplitLine" > < strong > getStringFromCharacterSplitLine< / strong > < / a > (character, splitLine)< / dt > < dd > < tt > Get the string after the first occurence of the character in the split line.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getTagBracketedLine" > < strong > getTagBracketedLine< / strong > < / a > (tagName, value)< / dt > < dd > < tt > Get line with a begin tag, value and end tag.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-getTagBracketedProcedure" > < strong > getTagBracketedProcedure< / strong > < / a > (procedure)< / dt > < dd > < tt > Get line with a begin procedure tag, procedure and end procedure tag.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-isProcedureDone" > < strong > isProcedureDone< / strong > < / a > (gcodeText, procedure)< / dt > < dd > < tt > Determine if the procedure has been done on the gcode text.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-isProcedureDoneOrFileIsEmpty" > < strong > isProcedureDoneOrFileIsEmpty< / strong > < / a > (gcodeText, procedure)< / dt > < dd > < tt > Determine if the procedure has been done on the gcode text or the file is empty.< / tt > < / dd > < / dl >
< dl > < dt > < a name = "-isThereAFirstWord" > < strong > isThereAFirstWord< / strong > < / a > (firstWord, lines, startIndex)< / dt > < dd > < tt > Parse gcode until the first word if there is one.< / tt > < / dd > < / dl >
< / td > < / tr > < / table > < p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#55aa55" >
< td colspan = 3 valign = bottom > < br >
< font color = "#ffffff" face = "helvetica, arial" > < big > < strong > Data< / strong > < / big > < / font > < / td > < / tr >
< tr > < td bgcolor = "#55aa55" > < tt > < / tt > < / td > < td > < / td >
< td width = "100%" > < strong > __author__< / strong > = 'Enrique Perez (perez_enrique@yahoo.com)'< br >
< strong > __date__< / strong > = '$Date: 2008/21/04 $'< br >
< strong > __license__< / strong > = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'< br >
< strong > absolute_import< / strong > = _Feature((2, 5, 0, 'alpha', 1), (2, 7, 0, 'alpha', 0), 16384)< / td > < / tr > < / table > < p >
< table width = "100%" cellspacing = 0 cellpadding = 2 border = 0 summary = "section" >
< tr bgcolor = "#7799ee" >
< td colspan = 3 valign = bottom > < br >
< font color = "#ffffff" face = "helvetica, arial" > < big > < strong > Author< / strong > < / big > < / font > < / td > < / tr >
< tr > < td bgcolor = "#7799ee" > < tt > < / tt > < / td > < td > < / td >
< td width = "100%" > Enrique Perez (perez_enrique@yahoo.com)< / td > < / tr > < / table >
< / body > < / html >