[Maya] Different default node values on node creation

Hi everybody,

I’m looking for a universal way setting new default values for nodes on creation time.

Sure these nodes could be created with a custom script and modified later on, but I think this is not very user friendly, because there are so many ways nodes could be created. I’m pretty sure not everybody would get used to it using only shelf buttons instead or something like this.

My first thought was doing this via a scriptJob. Sadly, this is only doable with DAG nodes (DagObjectCreated event), but not with DG nodes like the file node for example.

Is there a other way, maybe something with AETemplates or so? I didn’t figured out if this would possible yet.

Thanks in advance,
Peter

Do you have a use-case/example? Creating nodes with varying default attributes and/or values sounds like something a custom UI would suit? That way creating the nodes would be done via code anyway, so a few lines to create/set attributes/values is, AFAIK, the ‘standard’ way to go about it for ‘most’ use-cases (and adding options to the UI to allow the user to alter said defaults).
However this may not suit a specific use-case you might have?
And for something related (advanced), check out Jason Parks Subclassing PyMel.

Hi Lee,

thank you for your response.

Basically you are right. Creating nodes with a custom UI could work, but I think it is not very user friendly when working with Maya’s included nodes like shading nodes. The most artists are used to various workflows and I don’t want to interrupt these workflows in an optimal way. For example a lot of artist are creating shading nodes with the TAB key, since Maya’s Node Editor was introduced. Some artist still using the Node Library and using middle mouse drag and so on.

A workaround could be hooking custom code into the UI Mel scripts where node creation is executed, but doing this with a lot of different node types is far to costly, I think.

The link you attached seems pretty interesting. I will definitely have a deeper look on it.

Best,
Peter

I’ts pretty easy to do in code. For any given maya command you can always store the default arguments in a dictionary and pass them with the ** syntax


cube_defaults = {'width': 1, 'height': 2, 'depth':3, 'name' :'fancyCube'}
cmds.polyCube(**cube_defaults)

It’s much harder to do this in the Maya UI, since the users will always be able to get in there behind your back and changed the defaults. The default settings for most node types are stored in optionVars. For example with cubes you’ll see


polyPrimitiveCubeAxis
polyPrimitiveCubeCreateUVs
polyPrimitiveCubeDepth
polyPrimitiveCubeHeight
polyPrimitiveCubeNormalize
polyPrimitiveCubeNormalizeType
polyPrimitiveCubePreserveAspectRatio
polyPrimitiveCubeSX
polyPrimitiveCubeSY
polyPrimitiveCubeSZ
polyPrimitiveCubeTexture
polyPrimitiveCubeWidth

You could set those to the values you want at startup and those would be the defaults that were used when the user hits the menu item or a shelf button (at least, if the shelf button does not set values explicitly). However there is no way to lock those values so the user can blow away your settings by opening the option box in the Create menu and changing them. There’s really no way to prevent that. Not every node type has associated optionVars either, so there’s no way to easily force preferences on, say, new file texture nodes.

If the values you need to set are mission-critical, you can add an idle scriptJob to check relevant nodes when the user is not busy and to either ask them what to do or silently update the values as needed. That will work for lightweight cases but idle jobs should be used with care: if you’re checking a few tens of nodes it’s fine, but if you’re checking thousands of nodes Maya will start to feel sluggish.

You can also just apply the fixes at save time, at export time, or render time – this will allow you to present the user with choices if you’re not sure what to do but also to make sure the data is good before it gets shared with others.

Hi Steve,

thank you for your help.

Using the optionVars could be a option, but I think it is very limited. Yes, a lot of nodes created via the Maya menu’s are using optionVars managed user-based default values, but not all. As you describe hacking into this could be very risky. I think, a lot of DG nodes (e.g. shading nodes) are not using the optionVars, they just using the defaults hardcoded into the node code.

Maybe I’ve found a possibility utilizing the API for this. There is a class for creating callback even for DG changes:

http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_d_g_message_html

I’m playing around with it right now and it looks promising.

I’ll keep you posted.

Peter

Hi,

just for your information. The attempt with MDGMessage is working like a charm. There’s only one thing you should aware of. The NodeAddedCallback also is triggered on scene loading events like scene opening or (re)loading references into Maya. But you can filter these events with the MFileIO class to set the default attributes only on (user) creation time.

Thanks for your hints guys.

Cheers,
Peter