Randomise instances of family with various types

On a theatre model I need to randomize the seat family instances with its types so that they don’t look all the same. There are four types (each one with a different person on the seat). Initially the instances can be equally divided a quarter of each type and then shuffled in dynamo.

Using Vikram Subbaiah’s ‘All Elements of Family Name’ and ‘Manage.RandomizeOrder’ I was able to randomize the list of seats but could not apply the list result back to Revit.

FamilyInstance.SetType expects a single family type and doesn’t seem to help.

Any ideas?

image

Thanks for your help erfajo This is quite a sophisticated definition!

It feels like the FamilyInstance.SetType node is where my problem is.

The familyInstance input is finding all instances of the family - if the input in familyType is a type picked using ‘Family Types’ it replaces all instances with this type. However I’m not being able to define the random familyType from the randomized list (probably because the indices change but the association with the element ID remain the same?).

Try this instead:

  1. Grab the seat instances.
  2. List.Shuffle to change the order. You can use a code block and a number slider to trigger new values.
  3. Count the seats.
  4. Create a List of the four family types.
  5. Use a List.OfRepeatedItems node to make each of the four family types about 3/8 of the total seat count (this will enable a better randomization by allowing an uneven count - you can set it to 1/4 if you want even counts though)
  6. Flatten the repeated items in number 4.
  7. Ensure the count of seats matches the count of family types by adding/dropping types as needed.
  8. FamilyInstance.SetType node with @L1 on each input - this will force the node to evaluate matching depth lists individually.
1 Like

Thanks for your solution Jacob, I reached a passable definition late on Friday which was doing the trick using Element.SetParameterByName, also without working with the correct number of seats and then cropping the list to the amount desired. It felt like it wouldn’t do a good job for hundreds of seats, worked fine for the test with 16 though. See below:

Seeing your post late this morning I decided to give it a go and came to a more refined solution, not sure if it is exactly following your steps but it works. Thanks!

1 Like

When I need to create a random list of specified objects I usually go with one of two methods. The first is similar to what @jacob.small mentioned, and the second creates a random list of indices that I use to select my specified objects.

Here’s an example of the second method.

4 Likes

I like the mathematical approach Nick, this gives more control on the list randomness and also informs how many instances of each type will occur. Will keep it on my records, thank you.