Python randomly selects Maya scene elements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.