Random color script

 From:  Michael Gibson
3876.10 In reply to 3876.9 
Hi Pilou, so I was thinking - do you really need a completely different random color for every single thing? What if it was more like 20 different base colors which were then randomly assigned? That would be a lot easier to set up because that would only involve creating 20 styles.

So the way that would work would be to first set up 20 different styles, and you can assign them the colors that you want, or use the script from here to randomize their colors:
http://moi3d.com/forum/index.php?webtag=MOI&msg=2987.2


Then you can use the following script on a shortcut key to randomly assign each face or edge to one of those styles:

script: /* Assign random styles to faces and edges */ var styles = moi.geometryDatabase.getObjectStyles(); var breps = moi.geometryDatabase.getObjects().getBReps(); for ( var i = 0; i < breps.length; ++i ) { var brep = breps.item(i); var edges = brep.getEdges(); for ( var j = 0; j < edges.length; ++j ) { edges.item(j).styleIndex = Math.floor(Math.random() * styles.length); } var faces = brep.getFaces(); for ( var j = 0; j < faces.length; ++j ) { faces.item(j).styleIndex = Math.floor(Math.random() * styles.length); } }


You can also just use this with the default set of styles as well, it will randomly assign each face or edge to one of the current style colors. Then if you want more variety add more styles.

- Michael