Logical Operation - See Photo

Dear Experts,
How can I make script to automatically replace “unoccupied” with continues number 01,02,03 and etc. Please see screenshot.
Please help.

Quite doable by a little python:

And if you need to have the “01” not the “1” this can be accomplished like so:

import clr
lst = IN[0]
cond = IN[1]
num = 1
output = []
for x in lst:
	if x == cond:
		if len(str(num)) == 1:
			output.append('0'+str(num))
		else:
			output.append(str(num))
		num = num+1
	else:
		output.append(x)
OUT = output

And here is the code. :slight_smile:

2 Likes

Dear Jonathan,
Many thanks for your support. When my input list is at L3 level this script is not working. :frowning:
What should I do?
Please see photo:
Capture2.dyn (3.5 KB)

If you make it a custom node and set the list level on the list-input it will work :slight_smile:

2 Likes

Many thanks

@kvusal Using Design Script (ver 2.0)

def rep(a:var[])
{
	return = [Imperative]
	{
		b = 0;
		c = [];
		e = 1;
		for(d in a)
		{
			if(d == "unoccupied")
			{
				c[b] = String.PadLeft(e+"",2,"0");
				b = b+1;
				e = e + 1;
			}
			else
			{
				c[b] = d;
				b = b + 1;
			}
		}
		return c;
	}
};
1 Like

If you want to avoid code, you could try the following:

1 Like

You could also try…just need an Archilab node…

1 Like

@Scott_Crichton and @Dimitar_Venkov
Very nice! I thought that it would be doable using just nodes, I’ve tweaked your graph a little to work with multiple lists and numbers above 9 :slight_smile:

2 Likes

With only OOTB nodes :slight_smile:


replaceMultiple.dyn (29.9 KB) (ver 2.0)

2 Likes

I think this thread quite nicely shows the beauty and power of both the forum and Dynamo as a tool :slight_smile:
The fact that for even a quite simple problem already 5 different possible solutions are offered!

2 Likes