Codeblock for loops with nodes

#1

Hi,
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)

0 Likes

#2

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

#3

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

Try :

List.AddItemToEnd(s,result);

and :

List.AddItemToEnd(DSCore.Element.name(e),result);

Hope it helps.

0 Likes

#4

Thx for your help,


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

0 Likes

#5

0 Likes

#6

no sorry, its not working

0 Likes

#7

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

Something like :

s=="Keine"?"Keine":Element.Name(s);

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

0 Likes

#8

mh, now i get a null

0 Likes

#9

Maybe Revit.Element.name ?

0 Likes

#10

not working, sorry

0 Likes

#11

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

0 Likes

#12

seems like this a combination of:


and

2 Likes

#13

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

#14

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.

0 Likes

#15

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.

0 Likes

#16

yes i have installed Dynamo 1.3 and 2.0

0 Likes

#17

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

0 Likes

#18

I have uninstalled 2.0. Nothing has changed:(

0 Likes

#19

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).

0 Likes

#20

like this?

0 Likes