Problem with For Loop inside a Code Block

Hi everyone.
I’m having trouble trying to write a simple For Loop inside a Code Block.
As seen in the image I have a collection of solids representing exterior areas each one. And a definition for my Green color.
What I’m trying to do is to assign that Color to each one of my solids list.
Could anyone explain me how is the correct way to write this for loop function inseide my Code Block?
Thanks a lot!

DESIGN_SCRIPT

Hi @DavidMena ,

You don’t need a for loop for this, simply use the GeometryColor.ByGeometryColor node as is.

1 Like

Hello

code block:

greenAreas=[con,sph,cyl,cub];
K=DSCore.List.Count(greenAreas);
color=[];
green=Color.ByARGB(255,0,128,0);
[Imperative]
{
	for (a in 0..(K-1))
		{
		color[a]=GeometryColor.ByGeometryColor(greenAreas[a],green);
		}
return color;
};

cordially
christian.stan

4 Likes

Hey @christian.stan Thank you for your help!
It is working but… Do you know why it is changing color only in the watch 3D Node but not in the background view?
I don’t know if it is something as simple as one configuration missing or just a weird bug or something :man_shrugging:

1 Like

Element creation and modification is non-destructive in Dynamo. Because you have pulled in the green areas as a list they are displaying in this node, and likely other nodes before it. Disable the geometry preview of all the nodes (select everything, right click the canvas and select hide preview), and then add a new new Object.Identity node to display just the output of the “Green Area”, or use the GeometryColor.ByGeometryColor node to produce the outcome from a list of the green areas before they are colored.

4 Likes

@jacob.small
Thank you!. It works :slight_smile:

1 Like