Access elements of a list with python

Hi Guys,
I have a list of points. Points have X,Y and Z coordinates but Z can only be = 3000 or = 6000.
I would like to create a python script to extract Z coordinate = 3000 in a list and Z coordinate = 6000 in another.

I would also like to know how it is possible to access in elements of a list.

There are ways to do this with OotB nodes, but to answer your question you would have to use a for loop that would say

``````for point in points:
z = point.Z
``````

This would iterate through the list of points (`points`) and would set `z` equal to the z coordinate for that specific point. You would still have to figure out the logic for creating two lists but that should get you started.

1 Like

I think you should consider looking into â€śif-elseâ€ť statements in python, this is among the very first things you should learn to effectively use Pythonâ€¦

You could start here:
https://www.tutorialspoint.com/python/python_if_else.htm

Anywho, I believe what youâ€™re trying to achieve would be easier just doing with OOTB nodes (Out Of The Box).

I will second what @Jonathan.Olesen has said. This is all pretty basic python stuff. If youâ€™re looking to learn python (great!) try some tutorials and search the web for forums and basics. If you just want to get the result youâ€™re looking for, you could probably get it with just a few OotB nodes or a code block.

As said @Jonathan.Olesen and @Nick_Boyts , OotB nodes really seem sufficient for what you are trying to achieve. Take a look at the List.FilterByBoolMask, the Point.Z and the == nodes. (see last example in the following link)

http://primer.dynamobim.org/en/06_Designing-with-Lists/6-2_working-with-lists.html