It doesn't sound like you want to be trying to do what you are doing with just g code. If you have many different discreet files that you need to load, you will have to use a macro and do the whole thing in Lua. You can run subroutines in g code but it sounds like you probably need more than that.
Here is an example of a function in Lua that will open a file and place each line of code (could be g code) into an array called file_data:
function populate(filename) --function to put saved parameters in appropriate boxes
local rc --return code
local file_data = {} --array for holding data
local file_path = c:\your directory .. filename
if io.open(file_path,"r") == nil then --if the file cannot be opened
error("error loading file: " .. filename)
return nil, nil
else
io.input(io.open(file_path,"r")) --open the file
end
for i = 0, 200 do --read the file line by line, and place each line in the next position of the array
file_data = io.read("*line")
end
io.input():close() -- close current file
return file_data, mc.MERROR_NOERROR
end
or, more simply you can just dump the entirety of a file into a string called gcode
io.input(io.open(file path,"r")) --open file in read mode
gcode = gcode .. io.read("*all") --copy the whole thing to a variable called gcode
end
io.input():close() -- close current file
then use mc.mcCntlGcodeExecuteWait(inst, gcode) to execute the file
Just in case you think subroutines in g code would work, here is an example:
m98 p010 L2 (call subroutine 010, repeat 2 times)
O010 (subroutine 010) (this could be the code for your first part?)
g0 x1
g0 x0
M99 (end of subroutine)
O011 (subroutine 011)(second part?)
etc.
Hope that helps!