Getting a value between 0.1 and 1 using Python

Hi all,

I have a list of vectors and I am trying to filter out the “Z” values to only contain values between 0.1 and 1. Once I have a list, I need to match these up to the original Vectors to get a new list containing only the Vectors between 0.1 and 1.
I don’t have much python experience but this is what I have tried so far:

I also tried to run nested if loops to test if Z was bigger than 0.1 and if Z was less than 1, but that just returns the entire original list I fed into Python.
I know this can be done without Python but I am trying to get better at it. If someone could help me with this I would really appreciate it.


Python is not needed for this. :slight_smile:
This should work just fine:

Input >= 0.1 && Input <= 1 ? true : false;

Edit: Sorry i did not fully read that you would like to do this in Python, let me try doing this in python :slight_smile:

1 Like

Thank you very much, that worked perfectly!

I see you are trying it in Python as well, if you could show me that workflow I would be grateful! :slight_smile:

1 Like

Yes, look at this:
*Note, if you only want the values in between, remove the =

If Statement in Python.dyn (7.3 KB)

1 Like

Thank you so much, I tried the “and” before, but i missed the ‘else’ I think that is why it wasn’t working :slight_smile:

It actually still isn’t working, but I think that is most likely because I have to import additional references?? But that is not important for now, I just wanted the correct syntax for the function.
Thanks very much for your time and effort Daan :slight_smile:

1 Like

It is possible that you need to import Revit and Dynamo into your Python. that is done like this:
*Note: I am not 100% sure that you need all of this. Maybe you can drop some lines :slight_smile:

import clr
from Autodesk.DesignScript.Geometry import *

import Revit

from Revit.Elements import *

import clr
from DSCore import *

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')

I tried this and got the following result:

I have a hunch that it has to do with my list structure in the p.Z code block where I have 3 levels, I assume I have to account for that somewhere in the code maybe, as the Python is outputting 2 levels only?

I do not know what causes that problem or how to solve that with python build you could try this:

List.Flatten > Python > List.Chop
and then have a list.count on list level 2 be the input for the list.chop

Or maybe try adding more brackets [ ] in the python code itself.

1 Like

The list.flatten > python method does work, so it’s definitely a list management issue inside the Python node… I will look around and see if I can figure this out, but you have done more than enough to help, really appreciate it :slight_smile:

1 Like

No problem, I like to share my knowledge :smiley:

1 Like

Looks like you need to loop over the lists of lists to get the data, that is for L in Lst then move into for d in data.


That worked perfectly, thanks so much Jacob!!