Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

list - Maya: Get name of all nodes created by script

I was wondering if there’s a way to get the name of any new node every time a new node is created. I’d like to compile a list of all the nodes created by my script so they can be cleanly deleted all at once if needed.

*Edit - A better solution would be if I can get to the name of all the new nodes in the scene after the script is done executing. This way if my script renames a new node while executing, the correct name will be stored.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use a scriptJob and listen for the DagObjectCreated event: http://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/scriptJob.html

However, unless your script is calling external dependencies that you have little/no control over the output from, I think you'd be much better off simply recording the actions your script is taking. And if necessary, persisting this data as JSON or similar to use between sessions or modules.

Edit: As per comments, to detect created or modified non-dag objects it may be more useful to list scene contents with cmds.ls(): http://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/ls.html

Eg:

import maya.cmds as cmds

before = cmds.ls()
cmds.polySphere()
cmds.polyCube()
after = cmds.ls()

diff = set(before).symmetric_difference(set(after))
print(diff)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...