So I have already started on this script. I want to make a script that opens a g-code file and then creates a modified version of this file called "modified (name of original file).gcode". Once matlab has opened the G-code file I want to it to read every line of the file and determine which lines start G0 and G1 and have X Y E values. I use regular expressions to do this. The original G-code file only has X and Y direction parameters so I have my script insert a Z parameter using "InsertBefore". Right now this Z value is just some arbritary value that is added to every line that matches the regular expressions format. I want to change the X Y Z and E values in all of the G0 and G1 lines by 0.2 percent of the original value.
Currently I have it add 0.2% of the original to the original but I would prefer if it could add or subtract randomly, just alter the value in any direction by 0.2%.
I want this script to also do two things in addition to what it already does, which is read, modify, and rewrite lines.
I want it to look at only G0 and G1 lines between blocks of lines that I specify (ie. modify only lines through 20-80). This is because in the original g-code file "dogbone (centered)" there are chunks of lines I want to look at specifically like the lines that follow ;MESH: and ;TYPE:WALL-INNER.
For the Z-value it adds, is there any way where I can apply the same 0.2% changing between the Z values in every line that has it?
I have attatched my script and the dogbone(centered) text file.