Maya tmp

From Antoine Vienne | Wiki
Revision as of 15:38, 14 April 2021 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;
////////////////

Maya Mel - Primary visibility off

for ( $object in `ls -sl -l` ) {
    print($object+"\n");
    setAttr ($object + ".primaryVisibility") 0;
}

Maya Mel - Multi Snap

/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /* type the command MS()

  • /

/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// source "generateChannelMenu.mel";

global proc MS () {

    global string $sourceObjects;
    global string $destinationObjects;


   // If the window exists already, delete it.
   if (`window -exists multiSnapWindow`)
   {
       deleteUI multiSnapWindow;
   }
   // Build the window.
   global string $man_window;
   string $man_window = `window -title " MULTI SNAP" -sizeable 0 -w 300 multiSnapWindow`;
   frameLayout -label "Snap source objects on destination objects.";
   rowLayout -width 540 -nc 2 -cw4 10 20 20 100;
   // Source objects section
   frameLayout -label "Source objects";
   $sourceObjects = `textScrollList -width 600 -height 300`;
   rowLayout -width 240 -nc 2 -cw2 120 120;
   button -label "Add selected" -command "MS_addObjects ();" -width 120;
   button -label "Remove selected" -command "MS_removeObjects ();" -width 120;
   setParent ..;
   rowLayout -width 240 -nc 2 -cw2 120 120;
   button -label "Remove All" -command "MS_clearObjects ();" -width 240;
   setParent ..;
   setParent ..;
   rowLayout -nc 3;
   button -label "Create" -command "VRAYCONNECDO() " -width 140 -align center;
   button -label "Close" -command "DAC_CloseUI() " -width 140 -align center;
   setParent ..;
   setParent ..;
   // Destination objects section
   frameLayout -label "Destination objects";
   $destinationObjects = `textScrollList -width 600 -height 300`;
   rowLayout -width 240 -nc 2 -cw2 120 120;
   button -label "Add selected" -command "MS_addMM ();" -width 120;
   button -label "Remove selected" -command "MS_removeMM ();" -width 120;
   setParent ..;
   setParent ..;
   rowLayout -nc 3;
   button -label "SNAP IT" -command "VRAYCONNECDO() " -width 140 -align center;
   button -label "Close" -command "DAC_CloseUI() " -width 140 -align center;
   setParent ..;
   setParent ..;

// Show the window. showWindow multiSnapWindow; }

global proc string[] getShaders(string $from) { // get the shapes from the input string $shapes[] = ls("-o", "-dag", "-s", $from); // give me the connected "shadingEngines" string $shadingEngines[] = listConnections("-type","shadingEngine", $shapes); // list the connected materials (shaders) from that string $materials[] = ls("-mat", listConnections($shadingEngines)); // remove duplicate occurrences. return (stringArrayRemoveDuplicates($materials)); }

//Add selected objects to list. global proc MS_addObjects () {

     global string $sourceObjects;
     string $selectedshapes[] = `ls -sl -l`;
     //print $selectedshapes;
     int $count = 0;

if ($selectedshapes[0] != "") { for ($i in $selectedshapes) { $count ++; textScrollList -edit -append $i $sourceObjects; } } }

//Add selected objects to list. global proc MS_addMM () {

     global string $destinationObjects;
     string $selectedshapes[] = `ls -sl -l`;
     //print $selectedshapes;
     int $count = 0;

if ($selectedshapes[0] != "") { for ($i in $selectedshapes) { $count ++; textScrollList -edit -append $i $destinationObjects; } } }

// Clear objects from list. global proc MS_clearObjects () {

   global string $sourceObjects;

textScrollList -e -ra $sourceObjects; }

// Remove selected object from list. global proc MS_removeObjects () {

  global string $sourceObjects;
   int $index [] = `textScrollList -query -selectIndexedItem $sourceObjects`;
   if ($index [0] != 0)
   {
       textScrollList -edit -removeIndexedItem $index [0] $sourceObjects;
   }
  global string $sourceObjects;

}


global proc VRAYCONNECDO() {

  	// UI Elements

global string $sourceObjects; global string $destinationObjects; // Define user selected objects string $selected_objects[] = `textScrollList -query -allItems $sourceObjects`; string $meshMaterial[] = `textScrollList -query -allItems $destinationObjects`; int $i = 0; //Progress bar global string $gMainProgressBar;

// Start the progress bar and adjust its max value for this operation.

   int $steps = size($selected_objects);
   progressBar -edit -beginProgress -isInterruptable true -status "Connecting shaders to mesh material ..." -maxValue $steps $gMainProgressBar;
 

for ($i = 0; $i < size($selected_objects); $i ++) {

       select -r $selected_objects[$i];
       select -add $meshMaterial[$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;

// Update the progress bar. progressBar -edit -step 1 $gMainProgressBar; } // End the progress. progressBar -edit -endProgress $gMainProgressBar; }