Open variable file in G-code

I am looking for a way to import variable files (from 1 to 10 or from 1-20). Each file consists of a single layer. The 3D printer needs to import file 1 do the layer and move to generate layer 2 which is included in file 2. The printer knows when last layer is generated because this layer (file) carries (End) . Is it possible to create a G-code loop like this?

Marlin has limited macros if your firmware supports them, M810-M819, but I don't think they will solve your problem.

Not sure if this will help but see OctoPrint Gcode Macros Plugin.

Can you give us more details and/or examples of what you are trying to accomplish?

Something like OpenSCAD could be used to generate a single Gcode file. IceSL is a slicer with a scripting language so that is another possibility.

Dear b-morgan,

we want to simplify CT scans. We will use a CT line scanner to simply scan a single line and we want to store this line into a 2D contour. This contour needs to be taken by the 3D printer. During this time the CT scanner will scan line two. In other words we will receive files that are named starting from file1, file2, ... file_end. So the 3D printer should start printing while the CT scanner has not even finished scanning. So the printer will start, the G-code takes file1 and print its countour and the printer should wait until file2 is available. This should go on until file end. The printer needs to go into its end position after file-end.
I hope this explains it a bit.

May I ask why you don't just finish the CT scan and then convert the scan files to a printable stl file?
That's the usual way and there are already several solutions for it.

I know and this is what we also do so far. But with complex parts the voxel count increases so that a transfer into stl is hard and it will be even harder to slice this big data set. So we are going to use a line CT scanner (which is cheaper). This is already giving us a sliced data (why would you stitch it together to get a huge file which no one can handle anymore.) The sliced data can be used in raw and transfered into countour data. The rest as mentioned in the previous mail

If I understand correctly, you have the ability to generate gcode from an application other than a slicer and you can do this in (semi) real-time, i.e. layer by layer.

The 3D printers that OctoPrint communicates with have a USB serial interface over which lines of gcode are sent and printer responses are received.

So one possibility is for your application to send the gcode it generates directly to the USB port bypassing OctoPrint completely. If you still want OctoPrint around, then we need to figure out if there is some way to hook in so you can send gcode "layer by layer". Not sure if this is a plugin or something else.

I did find this video which might generate some ideas. This link might also provide some food for thought.