Maya tmp

From Antoine Vienne | Wiki
Revision as of 16:11, 17 September 2020 by Walter (talk | contribs)
Jump to navigation Jump to search

Maya tmp Scripts

Maya Python - Create object & Randomize Translate

from maya import cmds
import random

numObjects = 4

for n in range(numObjects):
    obj = cmds.polyCube()
    cmds.setAttr(obj[0]+'.translateX', random.randint(0, 5))
    cmds.setAttr(obj[0]+'.translateY', random.randint(0, 5))
    cmds.setAttr(obj[0]+'.translateZ', random.randint(0, 5))

Maya Python - Randomize translate of selection #1

from maya import cmds
import random

objList = cmds.ls(selection=True)

print objList

for obj in objList:
    cmds.setAttr(obj+'.translateX', random.randint(0, 5))
    cmds.setAttr(obj+'.translateY', random.randint(0, 5))
    cmds.setAttr(obj+'.translateZ', random.randint(0, 5))

Maya Python - Randomize translate of selection #2

#La meme chose en utilisant une fonction
from maya import cmds
import random

objList = cmds.ls(selection=True)

print objList

#On definit la fonction
def randomize(minValue=0, maxValue=5):
    for obj in objList:
        cmds.setAttr(obj+'.translateX', random.randint(minValue, maxValue))
        cmds.setAttr(obj+'.translateY', random.randint(minValue, maxValue))
        cmds.setAttr(obj+'.translateZ', random.randint(minValue, maxValue))

#On change si besoin les valeurs par defaut avant d'executer la fonction
randomize(minValue=4, maxValue=20)

Maya Mel - Replace path - getAttr/setAttr

for ( $object in `ls -sl -l` ) {
    $path = getAttr ($object+".filePrefix");   
    setAttr -type "string" ($object+".filePrefix") ($path+"yo");
}

for ( $object in `ls -sl -l` ) {    
    setAttr -type "string" ($object+".filePrefix") ("//blabla/bla.abc");
}

Maya Mel - Auto Uvs and Layout

polyMultiLayoutUV -scale 1 -rotateForBestFit 0 -layout 2;

Instance and Snap


//DE-PARENT meshs
string $VRMeshs = "*VR";
select -r $VRMeshs;
parent -w;
select -cl;


////Basket Grass
//replace_locator_by_object
string $objectCible = "Basket_Grass_VR";
string $locatorPlacement = "Basket_Grass_AR*";

select -cl;
select -r $locatorPlacement;
//pickWalk -d up;
string $selLocatorPlacement[] = `ls -sl`;
int $nbreLocatorPlacement = size ($selLocatorPlacement);

select -r $objectCible;
for ($i=1; $i<$nbreLocatorPlacement; ++$i)
{
    instance -st;
}
select -cl;

////////////////
string $objectCibleI = "Basket_Grass_VR*";
select -r $objectCibleI;
pickWalk -d up;
string $selObjectCible[] = `ls -sl`;
int $nbreObjectCible = size ($selObjectCible);

select -cl;

for ($i=0; $i<$nbreObjectCible; ++$i)
{
    select -r $selLocatorPlacement[$i];
    select -add $selObjectCible[$i];
    pointConstraint -offset 0 0 0 -weight 1;
    orientConstraint -offset 0 0 0 -weight 1;
    scaleConstraint -offset 1 1 1 -weight 1;
    select -r "*Constraint*";
    doDelete;
}

select -cl;

select -r $locatorPlacement;
doDelete;
select -cl;
////////////////