Skip to content

Instantly share code, notes, and snippets.

@fereria
Last active March 13, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/50d532a9c123255787bd5336627d9a7b to your computer and use it in GitHub Desktop.
Save fereria/50d532a9c123255787bd5336627d9a7b to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
選択しているリファレンスを複製する
複数OK、数値はTransformノード限定
"""
import pymel.core as pm
import os.path
# 現在選択中のノードのFileReferenceを取得する
sel_node = pm.ls(sl=True)
load_reference = []
for i in sel_node:
ref_node = i.referenceFile()
if i.referenceFile() not in load_reference:
load_reference.append(ref_node)
for ref in load_reference:
path = ref.path
bn = os.path.splitext(os.path.basename(path))[0]
to_ref = pm.createReference(path, ns=bn)
to_ns = to_ref.namespace
for n in ref.nodes():
if n.type() == "transform":
to_pynode = pm.PyNode(n.name().replace(ref.namespace + ":", to_ns + ":"))
for attr in ["tx", "ty", "tz", "rx", "ry", "rz", "sx", "sy", "sz", "v"]:
# ノードにConstriantが貼られている場合は無視する
if len(n.attr(attr).connections(scn=True, type="constraint")) == 0:
to_pynode.attr(attr).set(n.attr(attr).get())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment