The nice thing about using a context manager is that you ensure the
callback is removed, no matter what.

It gets a little fuzzy what code belongs to me and what belongs to my
employer since I write stuff at home that's influenced by 'work' work and
vica-versa.  I can't give you the exact code, but feel free to ping me if
you want a push in the right direction :)

Paul - looking forward to Saturday!  Still gotta figure out a costume :)

On Tue, Oct 23, 2012 at 8:23 AM, Paul Molodowitch <[email protected]>wrote:

> You can even create a nice little 'with' statement handler for tracking
> node creation... John Patrick (who's on here sometimes) wrote a handy one
> we use over here...
>
> - Paul
>
>
>
>
> On Mon, Oct 22, 2012 at 9:29 PM, Danny Wynne <[email protected]> wrote:
>
>> add a callback to MObjectHandle, then you can get every node that is
>> created regardless of what the command returns. Once you got your nodes,
>> remove the callback
>>
>> import maya.OpenMaya as om
>> import maya.cmds as cmds
>> cmds.polyCube(n="testCube")
>> new_nodes = []
>> def cb_add_nodes(node, data):
>> new_nodes.append(om.MObjectHandle(node))
>> id = om.MDGMessage.addNodeAddedCallback(cb_add_nodes)
>> #setDrivenKeyframe command does not return the anim_curve node
>> cmds.setDrivenKeyframe("testCube", v=1, at="tx", cd="testCube.ty", dv=1,
>> ott = "spline", itt = "spline")
>> om.MDGMessage.removeCallback(id)
>> for n in new_nodes:
>> n_name = om.MFnDependencyNode(n.object()).name()
>> print n_name
>>
>>
>> I learned this from http://www.macaronikazoo.com/
>>
>> On Thursday, October 18, 2012 12:04:07 PM UTC+8, Berg Jones wrote:
>>>
>>> Trying to get the name of a newly created node without having to use a
>>> certain workaround. Im adding a light shader with DL_createSurfaceShader.
>>> This creates uber_surfaceN depending on whats in the scene. Then Im doing
>>> more stuff in the same loop. How do I capture the name?
>>>
>>>
>>> import maya.cmds as cmds
>>> import maya.mel as mel
>>>
>>> def checkGeo():
>>>     objNames = cmds.ls(sl=1)
>>>     if objNames:
>>>         geoShapes = cmds.ls(geometry=1)
>>>         if geoShapes:
>>>             geoTransforms = cmds.listRelatives(geoShapes, p=1)
>>>             if 'lockedGeo1' in geoTransforms:
>>>                 for i in objNames:
>>>                     cmds.select(i)
>>>                     createSurfaceShader()
>>>                     cmds.select(clear=1)
>>>
>>> def createSurfaceShader():
>>>     mel.eval('$selected_geo = `ls -sl`')
>>>     mel.eval('$selected_geo_shape = `listRelatives -children -shapes
>>> $selected_geo[0]`')
>>>     mel.eval('DL_setObjectAttrib(**DL_createSurfaceShader("uber_**surface",
>>> 0), "surface", $selected_geo_shape)')
>>>
>>  --
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings:
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>  --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>



-- 
John Patrick
404-242-2675
[email protected]
http://www.canyourigit.com

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to