Another option would be to split the strings into sections and group them by value. Then you count how many unique values there are per section and increment that way.
@Mark.Ackerley the second number does not have to be always one, however in the structures @Andriy supplied there is no way for a one to generate in the second column, this could happen in a sequence like this though:
def generate_paragraph_structure(strings):
result = []
counter = [0] * 10 # Counter to keep track of the number at each level
for string in strings:
dot_count = string.count('.')
counter[dot_count] += 1
counter[dot_count+1:] = [0] * (10 - dot_count - 1)
paragraph = '.'.join(map(str, counter[:dot_count+1]))
result.append(paragraph)
return result
OUT = generate_paragraph_structure(IN[0])
That’s because you are missing 1 level in between the current and previous value (or the current and next, dependant on how you see it). You’re jumping from 2 “.” to 4 “.”. At line 30 the output is as expected since the structure is incremental.
A simple fix would be to add a String.Replace node afterwards to replace all zeroes with ones:
def generate_paragraph_structure(strings):
result = []
counter = [0] * 10 # Counter to keep track of the number at each level
for string in strings:
dot_count = string.count('.')
counter[dot_count] += 1
counter[dot_count+1:] = [0] * (10 - dot_count - 1)
paragraph = '.'.join(map(str, counter[:dot_count+1]))
result.append(paragraph)
return result
OUT = generate_paragraph_structure(IN[0])
It could probably also be fixed within the Python Script, but I’m lazy and this works too.