Friday, November 18, 2016

V-ray Light inconsistency on "visibility"

 I don't know why Vray lights are set to "visible" , or in some cases not set to "invisible" by default.   I can't think of any time I actually want my lights visible and to affect the alpha of the image.
    However.  no big deal,  I thought I'd write a little script to auto turn them off.. Only to discover that some lights use "visibility" and some use "invisible" for their channels. 

LightDome, sphere  and Rect Lights use "Invisible" while IES use "Visibility" 

In the end, I don't care what the channel name is.. but it sure would be nice if it was consistent. 



 







Monday, October 17, 2016

hiding Arnold channels on shapes



Man, those keyable and visible channels on mesh and curve shapes are super annoying. I have no idea what they do, and have never really understood why they are all there .. but Arnold adds them, and for some reason. Ignores requests to hide them, which is interesting, cause to hide them, is super easy .. 



 so. I wrote a simple script to hide arnold channels,, It's not automatic, so every new mesh or curve needs to have it run, and sometimes when doing mesh separate and mesh combine operations, a new mesh object is created, so the channels are created fresh on the new object.
 


 I just put the script on my shelf and randomly hit it, like a gerbil hitting the space bar for food in a pysch 101 class experiment. 



You don't need anything selected, it just grabs all nurbs curves , and all mesh shapes, and hides the channels,... ( and of course can be reverse engineered if you ever want to show the channels again ) 

here's the script: 

// stephenkmann@gmail.com
// just a quick way to hide all the arnold channels that are added to shapes
global proc hideArnoldChan()
{
string $meshes[] = `ls -type "mesh"`;
for ($mesh in $meshes   )
    {
    setAttr -keyable false -channelBox false ($mesh + ".ai_shadow_density");
    setAttr -keyable false -channelBox false ($mesh + ".ai_exposure");
    setAttr -keyable false -channelBox false ($mesh + ".ai_diffuse");
    setAttr -keyable false -channelBox false ($mesh + ".ai_specular");
    setAttr -keyable false -channelBox false ($mesh + ".ai_sss");
    setAttr -keyable false -channelBox false ($mesh + ".ai_indirect");
    setAttr -keyable false -channelBox false ($mesh + ".ai_volume");
    setAttr -keyable false -channelBox false ($mesh + ".ai_use_color_temperature");
    setAttr -keyable false -channelBox false ($mesh + ".ai_color_temperature");
    setAttr -keyable false -channelBox false ($mesh + ".scr");
    setAttr -keyable false -channelBox false ($mesh + ".scg");
    setAttr -keyable false -channelBox false ($mesh + ".scb");
    setAttr -keyable false -channelBox false ($mesh + ".intensity");
    setAttr -keyable false -channelBox false ($mesh + ".emitDiffuse");
    setAttr -keyable false -channelBox false ($mesh + ".emitSpecular");
    }
    
    
string $nurbsCrvs[] = `ls -type "nurbsCurve"`;
for ($crv in $nurbsCrvs)
    {
    setAttr -keyable false -channelBox false ( $crv + ".rcurve");
    setAttr -keyable false -channelBox false ( $crv + ".cwdth");
    setAttr -keyable false -channelBox false ( $crv + ".srate");
    setAttr -keyable false -channelBox false ( $crv + ".ai_curve_shaderr");
    setAttr -keyable false -channelBox false ( $crv + ".ai_curve_shaderg");
    setAttr -keyable false -channelBox false ( $crv + ".ai_curve_shaderb");
    }

}

Wednesday, September 28, 2016

Random scripts I needed this week

This is more for me than to actually share as I know I'll forget these ...


in a heavy scene file I was running into issues dealing with the geo and blendShapes and just wanted to kick out some things without having to deal with the ui.  ( I had also transferred UV maps which kills basically everything until you get rid of history ) 

 so for exporting the blendShape maps  the command is part of the ART brush commands and will open up the file dialog for size and where you want to save the exported image file

// export maps 
artExportMapDialog "artAttrCtx";



 I also wanted to smooth flood the hell out of my painted maps, but I didn't want to sit there hitting the "flood" button forever.. so I just wrote an uber simple loop script..  What's weird to me is that the flag that coincides with "flood" .. is -clear.    


{
int $i = 0;
while ($i <= 25)
    {
    artAttrCtx -e -clear `currentCtx`;
    $i++;    
    }    
}    


also this is all in Maya 2016. so I am not even sure what works and doesn't in 2017 yet with blendshapes, and blendShape wt maps. 




Monday, April 25, 2016

Maya mode OptionMenu

I do a lot of editing to the source code of Maya's UI to customize and add or remove items.

 One of my personal pet peeves is the "mode" button in the upper left corner of Maya's status bar.   It's huge, I use the hotbox predominantly so it's useless to me, and it doesn't have a "collapse bar" so you can hide it like all the other buttons and ui items on the status bar.

 The purpose of the mode button is to change what menu set is available, like "modeling" , "rendering" etc. 








There isn't that much space on a screen, and this button already is connected to a bunch of hotkeys { which I also don't use}, So I find it very redundant.. Unless I am making  a custom menuSet.. which I guess now I'll have to explain later... but you can make your own menus that show up in the hotbox or menu .. but I'll do that later.. 

in any case the nice thing is this optionMenu is easy to get at , as Maya has already made it a global variable by default

print $gMenuModeButton;

will give you the actual name of the optionMenu, which will change each time you open Maya 

in this instance I get the following
//MayaWindow|toolBar1|MainStatusLineLayout|formLayout5|flowLayout1|optionMenuForm|menuMode

note the numbers in the names, this is due to Maya not caring what those layout's names are . but the Menu Mode Button ,  Maya wants to know because it is accessed all over the place to help show menus and ui ..  So the easiest way for the developers to do that, was to make a it a global variable.. There are a lot of these and they almost all start with 'g'

so even though they named it "button" it's actually an optionMenu. ( which I think I only know from digging into the statusline.mel code) 

So now that you know what it is you can do all sorts of things to it, like hide it 

optionMenu -e -vis 1 $gMenuModeButton

or make it smaller. 
optionMenu -e -width 1  $gMenuModeButton








It's super important to use the -e or -edit flag when running the optionMenu command, or you will end up adding a new optionMenu somewhere in maya.. which of course can be dangerous, and not what you want.

You could add a shelf button or menu somewhere to show/hide the menu, but I just put the above command into my userSetup.mel and let Maya collapse it on start up.

 If I really wanted to dig in I would add a collapse bar in front of the optionMenu, but since I almost never ever use it.. I haven't bothered to do so.

if you want to do other edits to the menu just check out the help docs. 
help -doc optionMenu;



Lately I've been playing with the "custom" menu sets and so I've only been shrinking the mode button down, so I can still access it when I want to without having to run code to reveal it again.. and I can live with 5 -10 pixel width vs 100
( you can't read the menu names, but I know custom is at the bottom so I just click the bottom one) 

hth

-=s




Thursday, April 21, 2016

Friday, March 11, 2016

Simple Maya Script Snippets

 I sort of started doing the rigging dojo challenge of putting out a super simple script snippet a day, that not only does "something" but also displays something interesting in the world of scripting for Maya . None of this is mind bending and I'm sure not new to a lot of people, but maybe it will help someone with an intro


day one:
so this is a super simple script to just get the number of objects you have selected.. I have gotten so use to writing this script that I tend to just pop it into the script editor without thinking
the nice thing here is I'm not creating any variables so they wont be global or overwrite anything in my current Maya session.
mel:
size `ls -sl`;
python:
len(cmds.ls(sl=True))

also since the "select" command does not have a type flag. I use this same sort of method for quickly selecting all of a given node type
mel:
select `ls -type "mesh"`;
python:
cmds.select(cmds.ls(type='mesh'))


day two:
ok, so this one is not so different from the previous, so I'll just call it "super simple script" that can be helpful ( i just ran out of time today)
This one just takes your current object's type and makes a set of every object of that type in your scene . Since I'm dropping this on the shelf or running in the script editor, I scope it inside curly braces to keep the variables from going global. I highly recommend scoping whenever you are prototyping in the script editor with mel.. or you will bang your head against an illegal re-declaration , or an array of the wrong items from time to time.

string $s[] =`ls -sl ` ;
string $c[] =`listRelatives -c -s $s[0]`;
string $type = `nodeType $c[0]` ; 
sets -n ($type + "s") `ls -type $type`;
}
for the Python version I was able to get rid of all the variables as you can nest functions better ( with Mel you only can do it once)
(the following should read as just 2 lines, the first being the import of the maya commands module )
import maya.cmds as cmds
cmds.sets(cmds.ls(type=cmds.nodeType(cmds.listRelatives(cmds.ls(sl=True)[0],c=True,s=True))),n='SET')


day three: 
this is an experiment in fixing up an old script and streamlining it a little bit. the top this time is in Python, and I added the nope variable & print statement just to demonstrate that nope is actually list of booleans and I have to A) pull out the first item using [0] and then use str() to force it into a string for printing
sel=cmds.ls(sl=True,dag=True,shapes=True,noIntermediate=True)
for e in sel:
nope =not(cmds.displaySurface(e,query=True,xRay=True))[0]
print ("the ! issue is : " + str(nope) ) 
cmds.displaySurface(xRay=not(cmds.displaySurface(e,query=True,xRay=True))[0])
pretty much the same thing, but I don't have the same power in MEL to pull the first item out of the int array, and so I have to first make an int array variable and then use that in the action part of the script,, note that in MEL you can use ! for ( opposite or not) while in Python it's "not" to do the same thing
{
string $sel[] = `ls -sl -dag -s -noIntermediate`;
for ($each in $sel)
{
int $x[] =`displaySurface -q -xRay $each`; 
displaySurface -xRay ( !$x[0] ) $each;
}
}

Thursday, January 14, 2016

Python Equivalent of mel whatIs command

A common Maya debug for any mel script in All of Maya is the mel whatIs command. It basically tells you the location of any sourced script on your computers file system. It's a great way to melSteal and figure out what a script is doing.  

for mel you just use whatIs and the name of the command

whatIs BuildDisplayMenu;
// Result: Script found in: C:/Program Files/Autodesk/Maya2015/scripts/startup/buildDisplayMenu.mel // 

whatIs duplicate;
// Result: Command // 

if the command is not a script, but an internal maya command it will return "command".

Then you can use the help or help -doc to look up that command in the maya help reference.


 In python the equivalent to mel whatIs is to envoke its __file__ command.

so if not already imported. use the python import command

import mysteryScript

and then run it's __file__

mysteryScript.__file__

and it should return the scripts file path

C:\Program Files\Autodesk\Maya2016\Python\Lib\site-packages\maya\mysteryScript.py