Coloring based on parameter

Hi guys,

I am currently writing my first dynamo script but I am not getting anywhere, even with videos on youtube.

Below is my situation:

I have a host family with 9 nested families. I have a model where this host-family appears in different combinations with these 9 nested families. I have added a custom parameter “RLadder” in this host-family. This is based on the 10R model to increase circularity in construction. Each element in my model can have a score different in this 10R model. I want to assign a color to each score (from 1 to 10) via a Dynamo script so I can see at a glance which element gets which score on the R-Ladder.

I used this youtube video to set up the script but at the last 2 nodes I get the following error message:

List.GetItemAtIndex operation failder. Index was out of range. Must be non-negative.
and
Element.OverrideColorInview operation failed.

If this explanation of the situation is not clear I will be happy to provide more information.

Who can help me with this?

Sounds like you don’t have the same number of items each time.
Index out of range means you’re looking for item number 6 (for example) when you’ve only got 4 items in your list.

You need to write in a count so this doesn’t happen…

Sounds like quite an ambitious script for a first go though.

Maybe do a few simpler ones first so you get the basics?

1 Like

Not sure I understand the structure of your model, but an export of your graph’s workspace with node previews expanded would help.

After zooming in so your node names are clearly legible use the “export as image” feature in the top right hand corner (or the camera icon in older builds) to save the entire canvas as a png, and post that here or on a 3rd party site such as dropbox, google drive, box, onedrive, etc…

Zoom in so a single node can be clearly read before you do the export. Also expand the data previews for both nodes leading into the first node with a warning so we can see what type of data you’re working with and what the structure is.

1 Like

Hello, are the 250 elements well informed and/or of the same family

Cordially
christian.stan

The 250 elements are a listing of all nested families in my model. I give the host family in the model the classification on the R ladder and it links them into the nested families of this type.

Is it readable for you if you download it?

Also the colors seems to change everytime i open the script

Ok, now I see what is going on. you hav ea list of lists of true/false values, and you’re looking for the index of true in that list of lists. You likely want to look though each sublist directly. Set the node circled in red to use @L2 as the list input.

That said, you’re likely going to get some odd values. Instead of using a List.GetItemAtIndex a dictionary would be more effective here. I’ll try and put a sample together before I leave the office…

1 Like

So i’ve changed the input to L2, and indeed, i got some weird values. Strange thing is that some of the elements in my model get colored already, but not all of them

You have gone from 250 elts to 259 elts and you also have a warning message at the String to number node
Cordially
christian.stan

Ah, I see. I’ve added an other family to try some things. When i delete it, the warning is gone

1 Like

The solution via dictionary will be much more efficient as mentioned by Mr. Jacob and will dispense you with a nice number of spaghetti and the string to number node
Cordially
christian.stan

With a few minutes to spare, I built a Sandbox solution so you can look at the concepts and decipher how to implement them in the context of your project.


Color Dictionary.dyn (31.3 KB)

1 Like

Hi Jacob. I am trying to understand the graph and build your example but I don’t see the connection with my elements. I build a graph based on your example and it runs without warnings but nothing seems to happen in my model.

This is because there isn’t one. As I don’t have your Revit model I can’t build something in that context. I did try to put annotations into the group to explain how things relate to your workflow, but effectively:

  1. Where I generate points, you want to get your Revit elements somehow.
  2. Where I pull the Z value, you want to get the parameter value for ‘RLadder’.
  3. Where I list numbers as strings, you want to list the possible parameter values of ‘RLadder’.
  4. Where I have 4 colors, you want a color for each ‘RLadder’ value.
  5. Where I build a dictionary, you should do the same.
  6. Where I get the value from the dictionary, you should do the same.
  7. Where I change the color, you want to use an OverrideColorInView

If you post a sample model and a .dyn showing an attempt at building the stuff above then I can step in to help more directly. If you are unable to post to the forum directly, you can utilize a 3rd party service such as Dropbox, GoogleDrive, OneDrive, etc…

1 Like

Here is a link to my revit model with the family.

Can you make that an open link? I don’t have a publicly exposed google account.

Ah, it is now

Didn’t have an RLadder value on the family you had in the file, so I copied a few of them around and added values of “A”, “B”, “C”, or “D” to each. This graph worked fine for me from there. The original graph I posted is above, with the changes below.

Result looks like this:
Color Override

Having done this I can’t help but notice that a better workflow (and Revit native) would be to utilize a filter on the view, as that would update in real time and this will not.

2 Likes