from maya import cmds
import os
def get_referenced_file_paths():
referenced_file_paths = []
reference_nodes = cmds.ls(references=True)
for ref_node in reference_nodes:
ref_path = cmds.referenceQuery(ref_node, filename=True)
if ref_path:
referenced_file_paths.append(ref_path)
return referenced_file_paths
referenced_paths = get_referenced_file_paths()
print(referenced_paths)
for reference_file_path in referenced_paths:
f_name = os.path.basename(reference_file_path)
ns = f_name.split(".")[0]
cmds.file(reference_file_path, removeReference=True)
new_reference_node = cmds.file(reference_file_path, reference=True, iv=True, gr=True, gl=True, namespace=ns, op="v=0;", returnNewNodes=True)