Created
April 8, 2019 06:06
-
-
Save apokellypse/105a60b445c86a316f1f58fb0ee148b9 to your computer and use it in GitHub Desktop.
Assign Each Object To Separate Layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### assign_to_layers.py | |
### Kelly Yu | |
import maya.cmds as cmds | |
cmds.select(clear=1) | |
# get slices | |
bunny_slices = cmds.ls('polySurface*') | |
# remove surface shapes | |
bunny_slices = [s for s in bunny_slices if 'Shape' not in s] | |
# for each slice: | |
for slice in bunny_slices: | |
# get ymin and ymax | |
((_,_), (ymin,ymax), (_,_)) = cmds.polyEvaluate(slice, boundingBox=True) | |
# get slice index based on ymin and ymax; using zfill to make 1 -> 001 for easier layer sorting later | |
slice_number = str(int(ymax/0.135 + 1)).zfill(3) | |
# rename the slice | |
cmds.select(slice, r=True) | |
cmds.rename('bunny_slice_' + slice_number) | |
# add slice to new layer | |
layer_name = 'slice_' + slice_number | |
cmds.createDisplayLayer(name=layer_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment