Ian, you rock!
OpenMaya.MFileIO.isReadingFile() handles all the cases that I need (open,
reference, import) and OpenMaya.MDGMessage.addNodeAddedCallback() accepts
an explicit node type as a second argument, so the callback system won't
call my script to inspect every single node. Great! The only remaining
minor gotcha is that duplicating a node of this type will change the
attributes, but thats something the users can probably live with.
Thanks a lot!
Cheers,
Szabolcs
Just for the archives:
--
import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
def nodeCreationCB(node, info):
if OpenMaya.MFileIO.isReadingFile():
return
mayaNodeName = OpenMaya.MFnDependencyNode(node).name()
cmds.setAttr(mayaNodeName + '.attr', 1)
cbid = OpenMaya.MDGMessage.addNodeAddedCallback(nodeCreationCB,
'myNodeType')
--
On Thursday, March 30, 2017 at 4:26:18 PM UTC+2, Ian Waters wrote:
>
> Hey,
> You can run that check without a callback:
>
> from maya import OpenMaya as om
>
> if not om.MFileIO.isReadingFile():
> change some stuff...
>
> That would avoid callback spaghetti :)
> Best,
> Ian
>
> On 30 Mar 2017, at 12:20, Szabolcs <[email protected] <javascript:>>
> wrote:
>
> Hi,
>
> I'd like to change the default attribute values of a certain node type,
> but because of an existing asset library I can't simply change the defaults
> in the plugin, because that would break existing Maya scenes. I tried using
> OpenMaya.MDGMessage.addNodeAddedCallback() to setup a callback to change
> the attributes after node creation and it works ok, but the problem is that
> the callback executes not only when a new node is created by hand (or
> script) but also when a scene file is loaded / imported / referenced. I
> could disable the callback for scene load using another callback (yuck!)
> but it sounds like its leading into a mess of callbacks fighting with each
> other. I'm also not super happy about having a callback that examines the
> node type of every created node either, I'm afraid that it would slow down
> some scripts.
>
> So the question is: is there a bulletproof solution for doing something
> like this? Or are there any tricks to check the reason of the
> addNodeAddedCallback being called? Or should I simply hijack createNode and
> shadingNode commands and wrap them into custom code (for both mel and
> python)? Any suggestion is much appreciated!
>
> Cheers,
> Szabolcs
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2bd95713-2224-4b8f-8dfb-cf74b0f275a4%40googlegroups.com
>
> <https://groups.google.com/d/msgid/python_inside_maya/2bd95713-2224-4b8f-8dfb-cf74b0f275a4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/5c7cc0a3-72cf-469b-b9a6-b6fcffea5458%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.