Adding random material to families (first script)

hi

i’m trying to add a random material to a list of families. i have created a list with tree materiales, and i would like to add them to 20 objects, but right now it’s only random at the first three objects, i need somehow to shuffle the material-list on the run. can anyone give me a tip so i can make it work :slight_smile: thanks jorgensen

i tried the not so dynamic solution - expanded the list to 20.

but it seems that list.shuffle does only random once? even if i press “run” several times - the ‘randomness’ stays the same :-/

what am i doing wrong?

 

Use random numbers or randomize list from lunchbox. These also include “seeds” which is used to recall the numbers.

hi john

i will look into the lunchbox.

but is it intended that random gives the same result by every run?

i even tried this function that i found in the forum:

def shuffle1(l1:var[]) {
return = [Imperative]
{
n = Count(l1) - 1;
l2 = {};
for (each in l1)
{
i = Math.Random(0, n);
l2 = List.AddItemToEnd(l1[i], l2);
l1 = List.RemoveItemAtIndex(l1, i);
n = n - 1;
}
return = l2;
}
};

that also gives the same result :-/

thanks

jorgensen

Hi Bo,

That code you posted was for a different purpose. It was to shuffle nested lists independently because that’s currently broken in Dynamo 0.91.

What you want is a list shuffle with a SEED value, just like John suggested:

Dimitar, do you plan on throwing this node in SpringNodes. It’s pretty awesome!

hi dimitar

it works fine - though revit crashes often :-/

one more question.

does my material list need to be as long as the number of elements?

right now i have to repeat a, b, c into a list, but is it possible to have one list with the materials i have a, b, c and then run through the list of elements, and let et select a random material from the material list? not sure if this is as good enough explanation…

thanks

jorgensen

Bo,

You could use “List.Cycle” to repeat the material list as much as you need. If the material list is shorter, the last material will be re-used for the rest of the elements.

John,

I don’t think so. It was just a quick one-off example. This might be less practical than you think because you get different results for the same “seed”. The whole point of using a seed is to get exactly the same output for the same seed.

hi dimitar

my limited experience in programming comes from php, so this node way of doing things are new to me.

if i should have done something similar in php i would have done someting like this (pure imagination).

$elements = revit.getElements(“block”);

$materials[0] = “a”;
$materials[1] = “b”;
$materials[2] = “c”;

foreach($elements as $element) {
$i = rand(0,2);
$element(revit.setElementParameter(“material”, $materials[i]);
}

i think my challenge is to understand the flow in the node script :-/ - but i guess i just need to practice :slight_smile:

maybe something like the above could be done via python?
(as i understand that is the programming language used in dynamo).

thanks
jorgensen

 

 

 

 

IT’s not incredibly difficult to grab all materials, cycle the list and take the randomized order of materials for the elements.

Graph:

 

 

 

 

 

In Action:

2 Likes

Thanks John

For a completely (dynamo) noob it’s quite difficult :wink:

Thank you for your kind example, which i will study. It’s very appreciated.

jorgensen

 

No problem! My comment regarding the difficulty was mostly discussing that is uses a lot of OOTB nodes. :slight_smile: No such thing as a noob question, we’re all here to learn and help! Keep 'em coming, it means you are interested in the possibilities, and that is exciting!

 

-John

Hi John

is it possible to filter the materials, so only those containing “random” gets used?

thanks :slight_smile:

/Jorgensen

Definitely! :slight_smile:

hi John

thanks - it works very nice.

thanks for the effort, i really appreciate it.

jorgensen

Working on my 2nd ever DynaScript: I’m trying to have all my Materials to be shown onto Families with an extruded Cube with a material parameter that I use in on a Material Board that I tag reading several descriptive parameters in my Materials & Finishes Sheet. Can someone point me to references (if already done in this forum) that I can use as samples to have Dynamo create a family (as many needed for each material in Document) per material & apply the next material on the list until all have been applied & or ones not in use?

Side note: Working on my Material Library RVT file that I manage it all in. I have users select the Cubes with the materials they need & copy/paste into their project. Same for Family creation, I have them edit family duplicate the cube, apply materials, then copy/paste into family if needed, otherwise apply in the Project environment.

The 1st script I created was to List & export to Excel all Materials, & its Ids, & assigned Assets.