Codeblock for loops with nodes

i try to learn design script.
I use Dynamo 1.3 and Revit 2019.
In my example i have 6 walls with differents phase values.
Keine = nothing selected

The Element.Name node don’t work if you feed them the hole list. So i need to use the Element.Name only on the “Phase Elements”.

The codeblock has no error, but why is the list i return empty? The list should return only strings like [Keine,Keine,Keine,Phase 1,Keine Keine]

Second question:
How can i do something like the zip() function in Python? So i don’t need to use 2 for loops.
codeblock_loop.dyn (6.4 KB)

Just use an If statement instead. If the item is “Keine”, return “Keine” (or some other specified value). Otherwise, return the element name.

1 Like

Althought I agree with @Nick_Boyts, I think the problem is your syntax in the Code Block.

Try :


and :


Hope it helps.

Thx for your help,

Try 1:
Error: List is not defined
Try 2:
Empty list
Try 3:


no sorry, its not working

Ok then try the Code Block version of the if statement :

Something like :


And directly plug the output of Element.GetParameterValueByName to match s.

mh, now i get a null

Maybe ?

not working, sorry

What if you use instead of Revit.Element.Name(s) ?

seems like this a combination of:



It doesn’t automatically count the elements in the list so you’ll have to specify:

I tried for (i in 0..str) as well but it doesn’t work either. It’s one of those areas where the functionality is a bit different from some other languages.
Also be careful to keep the List.Count() outside of the Imperative block. They don’t play well together as shown in the issue highlighted by @Michael_Kirschner2

Edit: I realised I’m using Dynamo 2.0 instead of 1.3, but I think it should work the same, just with different brackets…? I think the Imperative block hasn’t changed much.

1 Like

thx you for your help! I worked threw the links, but couldn’t get a result.
I have deleded all packages now.
The function Element.Name() gets not found by Dynamo.

Quick thought : Do you have multiple version of Dynamo installed ? Maybe they are in conflict or what …

Also, in your last screen, you cannot define the same variable multiple times in a CodeBlock outside of a Imperative block. DesignScript is an associative way of programming, meaning that :

a = b + 1;
b = 2;

Will result in a evaluated at 3. Things like a = a+1; are prohibited, that is why loops are limited to Imperative blocks.

yes i have installed Dynamo 1.3 and 2.0

Maybe try to uninstall the version you are not using. Not sure about this though, but i guess it is worth the try.

I have uninstalled 2.0. Nothing has changed:(

While I’m not sure about the other issues, I do notice that you don’t seem to have taken my advise to heart;

In particular, the i in 0..cnt part.
for i in collection only works (sort of) if the collection is numbers, but even then it’s a bit weird about it.
See how the outputs change with different specification:

(to avoid the null at the end in the last case, simply subtract 1 from k).

like this?