View Full Version : script to assign seperate collision layer to shatter peices

04 April 2010, 03:48 AM
I feel kinda lazy asking this...

but i havn't played with mel for a while...

does anyone know of s simple script that would take selected shatter peices, and then assign each one an individual collision layer...

I tried writing one for a couple of hours, but it's been 5 years since i touched maya...

basically i know i would have to make an array from list selected

something like

string $shatterPieces[];
string $currentPiece;

$currentPiece = `ls -sl`; (but it would have to select the rigidbody node i believe)

for ($currentPiece in $shatterPieces)
setAttr (($currentPeice).collisionlLayer) ($shatterPieces[]);

basically something that would take the size of the array and iterate through assigning a collision layer based on the array index ect ect.

anybody care to help with's been a while

04 April 2010, 05:06 PM
slap that in a python tab... :)

import maya.cmds as mc

sel =

for i in range(len(sel)):
mc.setAttr('%s.collisionLayer' % sel[i], i)


04 April 2010, 06:00 PM
thanks chris,

I should have mentioned...not only have i not touched maya in 5 years....but the version i am using is about that old as well...right now Maya 8...
I don't think there is a python interface for maya 8...8.5 could use Pymel or others

04 April 2010, 09:22 PM
Hey MD,

you can select the rigid node directly by running a ls -type command.
So here is an example using the ls -type command to set different collision layers:

string $rbds[] = `ls -type rigidBody`;
int $i;
for($i = 0; $i<(size($rbds)); $i++){
setAttr ($rbds[$i] + ".collisionLayer") $i;


CGTalk Moderation
04 April 2010, 09:22 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.