Prior to the company's participation in a project with foreign cooperation, the need for dynamic random selection of some objects in the scene, was used Houdini node +hscript solved;
A similar effect was written in Maya today with a simple and elegant python, The code is as follows:
Import Maya.cmds as MC Import Random def seltest (): mc.select (alldagobjects=1) = Mc.ls (sl=True) = len (SEL) # Print sel Rand = Random.sample (SEL, G) Mc.select (rand, R=1) seltest ()
Operating effect:
This code needs to use Python's random module, but Maya's Commandspython help does not have this module, fortunately we can still call directly from the Python library;
Import Random
There are many functions of the Ramdom module, which can be sampled by sample ().
Add the effect to the random material with this code another time.
Python randomly selects Maya scene elements