Sequentially number specific lines in list

Within the G-code, How do we Sequentially number the NAMES and MOVES as show here?


Number specific lines.gh (19.3 KB)

TYIA

I don’t have any experience with RegEx or what flavour of it Grasshopper uses, but I gave it a go, and this seems to work.

Adds leading zeros to the names and moves as needed. You really need to start doing your own work instead of outsourcing it to the forum though.

Number specific lines 1.gh (19.3 KB)

1 Like

@Volker_Rakow

Thank you so Much … I am learning as much as I can as fast as I can.

If there are 10 or more MOVE and NAME, it adds a zero in front of the single digits, but if there are fewer than 10 there is no zero, how do we make it so the zero always appears?

I recently needed leading zeros for layer names. Replaced a kludge method with a single line of Python. It determines the number of zeros by the length of the zFill ‘L’ input.

zfill_2024Aug28a
zfill_2024Aug28a.gh (7.2 KB)

a = N.zfill(len(L))

2 months later :interrobang:

P.S. If I understand @Volker_Rakow’s code correctly, it could be added like this:

zfill_2024Aug28a2

Thank you @Joseph_Oster @Volker_Rakow

@Joseph_Oster @Volker_Rakow

When you add additional MOVES and NAMES to the source, double zero’s appear in the single digits.

Disconnect the Concat ‘A’ input, it is not needed.


Number specific lines_2024Aug28a.gh (17 KB)

P.S. I don’t want to modify too much of @Volker_Rakow’s code and haven’t tried to understand all of it but… I would add the purple group.


Number specific lines_2024Aug28bb.gh (16.4 KB)

P.P.S. @MJD, this is your code now and I believe you should understand it and be able to modify it as may be needed. I still don’t understand all of @Volker_Rakow’s code but experiment shows that adding a third term to the list is not as simple as one might hope. It could be better.

Number specific lines_2024Aug28bb2

This looks easy but it wasn’t. Though I started with code from @Volker_Rakow, I replaced everything because I wanted it to be easy to add more keywords to be numbered.

This image shows three words in a text panel connected to TMatch (upper left). More can be added easily.


Number specific lines_2024Aug29a.gh (20.0 KB)

The G-code might be corrupted by lines added for testing?