Just FYI, unless I am mistaken, you are not really wanting to parse gcode. You really just want to process a text file and do a smart search and replace, replacing (for example) "M03 S1000" with a looked up value based on that speed, hypothetically "M100 P2 S125".
Python is excellent for that, but you don't need anywhere near the overhead of a gcode parser to do it. I would suggest googling for "Python text processing tutorial" or something similar and you will find what you need. The entire program should not be more than a dozen lines of code or so (depending on the number of gear ranges and speeds you have). On Thu, Jun 9, 2011 at 12:51 PM, Karl Cunningham <ka...@keckec.com> wrote: > On 06/09/2011 08:59 AM, Andy Howell wrote: > > On 06/09/2011 10:21 AM, Karl Cunningham wrote: > >> I have need to parse a gcode file and I'd like to do it in Python. It > >> seems that wheel must have already been invented and I'd rather not > >> reinvent it. I got the source for grecode, written in c++. I could adapt > >> from that but I think it would be overkill for the simple task I'm > >> trying to do. > >> > >> I'm new to Emc2, but catching on. The machine is a knee mill that will > >> require manual gear changes. What I want to do is write a filter to > >> parse a gcode file for spindle speed settings, and when found, insert > >> M100 Pn Sxxx (where n is the needed gear setting, and xxx is the motor > >> speed for that gear). During a run, another program named M100 (already > >> written in python) will prompt the operator to change the gears > >> according to n. > >> > >> Anyone know of Python code that will parse gcode, at least well enough > >> for this simple task? > >> > >> Any other comments are welcome, such as "can't get there from here." > >> > > > > Karl, > > > > You could look at the heekscnc python that is used to parse > generated gcode. This is used > > to capture the tool paths for display in heekscnc. Its not directly > usable, but it might > > give you a starting point to roll your own. Have a look at: > > > > http://code.google.com/p/heekscnc/source/browse/trunk/nc/iso_read.py > > > > Thanks, Andy. > > This is exactly what I was looking for. > > Karl > > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > Emc-users mailing list > Emc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/emc-users > ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users