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.
2 Likes
Dear Jonathan,
Many thanks for your support. When my input list is at L3 level this script is not working.
What should I do?
Please see photo:
Capture2.dyn (3.5 KB)
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
@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
2 Likes
2 Likes
I think this thread quite nicely shows the beauty and power of both the forum and Dynamo as a tool
The fact that for even a quite simple problem already 5 different possible solutions are offered!
2 Likes