Tags

Sunday, October 23, 2011

D'aww, my first script.

I've been learning Python for a few months now and have been really enjoying it. To start off this new section of my blog, here is my first script I've written here at home! It's written in Python, using the PyMEL module.

This script will take what ever you have selected, group and add a '_Group' suffix. Very simple, but I use it often.

import pymel.core as pm
import maya.OpenMaya as om
 
# List our selection
sel = pm.ls(sl=1)
 
# Check to see if you have objects selected or not.
if len(sel) < 1:
    # No objects selected? Display this message.
    om.MGlobal.displayError("No objects selected.")
else:
    # 1 or more objects selected? Group all of them and 
    # add  '_Group' suffix
    for item in sel:
        pm.group(item, n=str(item) + "_Group")
It took me a while to get that Syntax Highlighter script working, but it was worth it. Click the little question mark in the top right of the code to find out more. Fantastic!