Hello everyone,
I was trying to create a very simple Foor loop and I am not getting the outcome that I expected. Previously I got a warning which said “Float is not iterable” and now I get Empty list. All de inputs are Double Object.Types:
Hello everyone,
I was trying to create a very simple Foor loop and I am not getting the outcome that I expected. Previously I got a warning which said “Float is not iterable” and now I get Empty list. All de inputs are Double Object.Types:
there are always severial ways
start = IN[0]
end = IN[1]
list = IN[2]
OUT = []
for i in list:
if i >= start and i <= end:
OUT.append(i)
else:
OUT.Remove(i)
If I copy and paste it, it is not working for me
Despite existing several ways to do it, what did I do wrong?
the scond one is a codeblock,
and the first one should work
is your object type double or float ?
# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
start = IN[0]
end = IN[1]
list = IN[2]
OUT = []
for i in list:
if i >= start and i <= end:
OUT.append(i)
else:
OUT.Remove(i)
The issue is that your start
and end
values are a list. You need to reduce them to a single item to compare.
you can not always use python one to one, you can varify the code:
# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
start = IN[0]
end = IN[1]
list = IN[2]
OUT = []
for i in list:
if i >= start and i <= end:
OUT.append(True)
else:
OUT.Remove(False)
ahhhh
this way
Again, the code is not the problem. The inputs are what are causing the code to fail.
You can add a few lines to the beginning of your code to make sure inputs follow the exact structure you need.
Something like this will ensure you always have a singleton or list depending on your needs:
it is item vs list… … i search for a item not a list!
Thank you @Nick_Boyts for your explanation and this workaround. I will keep those functions in my mind for future samples.
However, I did something that it worked for me but I am quite sure it is not Python good practice:
It’s the most straight forward workaround. I’d recommend reducing the input structure outside the python code though, just so it’s more clear what’s happening. It’s better practice (in my mind) to make the inputs match your workflow rather than making the workflow match your inputs in this case.