This article is the 15th day article of Maya Advent Calendar 2019.
You saw zebraed's callback using pyside: MEventMessage the other day. Is it?
It is said that OpenMaya can handle the same functions as scriptJob lightly and simply, so I will utilize it in the future.
This time I will write using scriptJob, but ...
Duplicate node names do not cause a fatal error in Maya. However, if you do not write the process in the correct way when creating a mel script, the specified object may not be found and the script may stop.
--Maya Error: Line 0: Multiple Objects Match Name -Avoiding Mel's "More than one object matches name"
--There is no problem if the tool works correctly even if there are duplicate node names, and if you can finally clean the data, you do not need to read this article.
|
(vertical line), the node name is duplicated.python
def rerename(node_uuid):
for node in cmds.ls(node_uuid):
if "|" in node:
basename = re.search("^(.+)?\|(.+?)(\d+)?$", node).group(2)
rename_name = cmds.rename(node, "{}#".format(basename))
--Performs rename processing when NameChanged is executed.
--When renaming manually, I think that only one object is selected, so get the selected object with the ls
command, convert it to UUID, and execute the renaming process.
def renameEvent():
for node_uuid in cmds.ls(cmds.ls(sl=True), uuid=True):
rerename(node_uuid)
nonSameNameAlliance.py#L11-L13
--When duplicating manually, the selection moves to the duplicated object, so rename processing is executed when SelectionChanged is executed. --Dag = True to get the hierarchy, tr = True to get only the transform node, convert it to UUID and execute the rename process.
def duplicateEvent():
for node_uuid in cmds.ls(cmds.ls(sl=True, dag=True, tr=True), uuid=True):
rerename(node_uuid)
nonSameNameAlliance.py#L15-L17
def main():
try:
if jobIds is not None:
for jobId in jobIds:
cmds.scriptJob(kill=jobId, force=True)
except:pass
jobIds = []
jobIds.append(cmds.scriptJob(event=["NameChanged", renameEvent], protected=True))
jobIds.append(cmds.scriptJob(event=["SelectionChanged", duplicateEvent], protected=True))
--If you register a process in a script job, the registered process will be executed at the timing that meets the conditions. --This time, the processes are registered for renameEvent and SelectionChanged respectively.
nonSameNameAlliance.py#L19-L28
userSetup.py
import nonSameNameAlliance;nonSameNameAlliance.main()
Place nonSameNameAlliance.py in Maya's Scripts folder and add the startup process to userSetup.py. Now when Maya starts, the process will be registered in scriptJob and will be automatically renamed.
Click here for this source code https://github.com/teionn/nonSameNameAlliance
The node is automatically renamed when you operate it in the scene, so I think it is basically for modelers.
It is designed to run only on transform nodes.
--If you want to get the effect on all nodes such as intermediate shape nodes, delete tr = True
.
This script does not judge case. Maya can retain case-sensitive objects even in the same hierarchy.
If you bring an asset to Unity in this state, if there are objects ʻobject_a and ʻobject_A
, it seems that either object cannot be referenced.
Tomorrow's article will be about rateionn Do you properly Remove: Unknown Plugins?.
That ... I'm writing ... I haven't written an article yet ...
I'm planning to release the script for free in time, so I'd be happy if I just downloaded it.
Recommended Posts