If else in nested for

Hi,

Cant get this to work, HELP!!!

OutPutList=[]
for x in IN[0]:
 Looplist = []
for x in IN[0]:
 if x==1:Looplist.append(0)
 elif x==2:Looplist.append(3)
 else:Looplist="1"
OutPutList.append(Looplist)
OUT=OutPutList
OutPutList=[]
for x in IN[0]:
 Looplist = []
for x in IN[0]:
 if x==1:Looplist="0"
 elif x==2:Looplist="00"
 else:Looplist="1"
OutPutList.append(Looplist)
OUT=OutPutList

Hello


Good reading

Python script:

# The vital minimum to do various things
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

OutputList=[] #Your container
for x in IN[0]: #Your loop
    if x==1:    #A removal for the loop
        OutputList.append(0)    #Assignment (addition) to the empty             container (outputlist)
    elif x==2:
        OutputList.append(3)
    else:
        OutputList.append("1")
        
OUT = OutputList,type(OutputList[3]) #Assignment of the container (filled) at the end of the loop at the exit (OUT)

cordially
christian.stan

@BIM_Mrbrango it depends on what you are looking for ā€¦ is this it?

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

OutPutList = []

for x in IN[0]:
    if x == 1:
        OutPutList.append("0")
    elif x == 2:
        OutPutList.append("3")
    else:
        OutPutList.append("1")

OUT = OutPutList
1 Like

Hi and Thanks to the both of you.

Iā€™m getting the length of ā€œENDā€ of filename, if its 1 digit then add 2(0) and if its 2 digits then add 1(0)

I tried your code but the sam problem

1 Like

Itā€™s still a little unclear what youā€™re after. Are you trying to normalize the string length by padding with 0? You can use a node for that or you can write a simple If statement (in a codeblock or python):

2 Likes

Here is modified (as you have 3 possibilities (2 from M. Nick))

# The vital minimum to do various things
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

OutputList=[] #Your container
for x in IN[0]: #Your loop
    if len(x)==1:    #A removal for the loop
        OutputList.append(x+"00")    #Assignment (addition) to the empty             container (outputlist)
    elif len(x)==2:
        OutputList.append(x+"0")
    else:
        OutputList.append(x)
        
OUT = OutputList #Assignment of the container (filled) at the end of the loop at the exit (OUT)

cordially
christian.stan

1 Like

Hi Nick_Boyts

I will try to explain, I have families that I want to rename and picture below is my goal.

The red line is a fixed carachters depending on the family, the blue is the sequence depending on the numer of families.

And in in that category there are 5.
So the serie will be something like this:

QA101,QA102,QA103,QA104,QA105
But if a category contains more than 9 familes I want it to look like this

QA110,QA111

That just seems like counting the number of families in a category and adding it to 100. You can do that with a sequence based on total count or step through each family and keep track of a counter. The former is much easier but the latter could be seen as the streamlined version if you already have a list of categories and their families.

1 Like

You are absolutly correct, but the sequence is not keeping the formating to number 9, Iā€™d like to have
number 01,02,03 and so on to 10?

Hello,
I succeeded in a way (Padright) :wink:

OutputList=[] #Your container
for x in IN[0]: #Your loop
    y=x+"00"
    OutputList.append(y[:3])
OUT = OutputList #Assignment of the container (filled) at the end of the loop at the exit (OUT)

cordially
Christian.stan

1 Like

Is it formatted as category (QA) and count (1xx) or as category (QA1) and count (xx)? If youā€™re starting the count at 100 then thereā€™s no formatting. If youā€™re starting at 00 (and the 1 is part of the category) then you just pad the left like Iā€™ve shown with 2 digits. Create a sequence of digits based on family count, convert to string, then pad.

3 Likes

Thanks Christian,

Always helpfull!!!

1 Like

Thanks Nick_Boyts!
You are absolutly correctā€¦

1 Like