Created
April 8, 2019 06:02
-
-
Save apokellypse/5699d984f0a49d43e72fb6a80badd965 to your computer and use it in GitHub Desktop.
Combine Objects Along Same Y-Plane Slice
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
### combine_slices.py | |
### author: Kelly Yu | |
import maya.cmds as cmds | |
cmds.select(clear=1) | |
# get slices | |
bunny_slices = cmds.ls('polySurface*', o=True) | |
# remove surface shapes | |
bunny_slices = [s for s in bunny_slices if 'Shape' not in s] | |
# slice_number to slice_name | |
slices_map = {} | |
# 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 | |
slice_number = str(int(ymax/0.135 + 1)).zfill(3) | |
# init slices_map list if necessary and add the slice to the list that corresponds to its slice number | |
if slice_number not in slices_map: | |
slices_map[slice_number] = [slice] | |
else: | |
slices_map[slice_number].append(slice) | |
for grouped_slices in slices_map.keys(): | |
# if along a slice there are multiple objects | |
if len(slices_map[grouped_slices]) > 1: | |
# combine these objects | |
cmds.polySelect(slices_map[grouped_slices], r=True) | |
cmds.polyUnite(slices_map[grouped_slices]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment