【Bifrost】ノードのパスを一覧で取得する

Bifrost Graphノード内の子を再帰的に検索して、ノードのパスを一覧で取得するスクリプトです。

# -*- coding: utf-8 -*-
import maya.cmds as cmds

# bifrostGraphノードを選択して実行
selList = cmds.ls(sl=True)
bifrostBoardNode = ""
if selList != None and len(selList) > 0 and cmds.nodeType(selList[0]) == "bifrostBoard":
	bifrostBoardNode = selList[0]
	
	# ノードのパスを格納する変数
	nodePathList = []
	
	# 再帰で子のノードをパスでリスト化する
	def RecursiveCall_ChildNode(bifrostBoardNode, nodeName, parentPath):
		childNodeList = []
		nodePath = parentPath + "/" + nodeName
		nodePath = nodePath.replace("//", "/")
		try:
			childNodeList = cmds.vnnCompound(bifrostBoardNode, nodePath, listNodes=True)
		except:
			pass
		nodeTypeName = cmds.vnnNode(bifrostBoardNode, nodePath, queryTypeName=True)
		if nodePath != "/" and nodeTypeName != "":
			nodePathList.append(nodePath)
		for childNode in childNodeList:
			RecursiveCall_ChildNode(bifrostBoardNode, childNode, nodePath)
	
	# 引数の2番目に任意のパスを入れることで、そのパスから処理できる
	RecursiveCall_ChildNode(bifrostBoardNode, "", "")
	
	# 取得したノードのパスを処理
	for nodePath in nodePathList:
		
		nodeTypeName = cmds.vnnNode(bifrostBoardNode, nodePath, queryTypeName=True)
		nodeTypeList = nodeTypeName.split(",")
		compoundType = ""
		try:
			compoundType = cmds.vnnCompound(bifrostBoardNode, nodePath, specializedTypeName=True)
		except:
			pass
		isReferenced = False
		if compoundType != "":
			isReferenced = cmds.vnnCompound(bifrostBoardNode, nodePath, queryIsReferenced=True)
		
		# ノードのパスとタイプ等を表示
		print nodePath
		print (u"	library : {0}".format(nodeTypeList[1]))
		print (u"	type : {0}".format(nodeTypeList[2]))
		print (u"	compoundType : {0}".format(compoundType))
		print (u"	isReferenced : {0}".format(isReferenced))
		print ""
		

上記のPythonスクリプトをスクリプトエディタにコピペして、任意のBifrostGraphノード(bifrostBoard)を選択して実行すると、スクリプトエディタにノードのパス等の一覧が表示されます。
(ノードが複雑なほど、時間がかかるので注意してください。
基本的に検索したいノード(コンパウンド)を一つに絞った状態で実行した方が良いかと)



一応、想定している用途としては、配布用のコンパウンドを作る場合に、
コンパウンド内に他の自作のリファレンス化したコンパウンドがあると面倒なので、
(どこまで配布したら正しく動くか分からなかったりすると思いますし)
任意の条件のものを対象に一括でリファレンスの解除(Make Editable)したい時とかに使えるかと思います。

上記のスクリプトの45~51行目あたり(# ノードのパスとタイプ等を表示)を↓以下の処理に置き換えれば、一括でリファレンスの解除ができるかと

		# ライブラリのパスに「User::」とついていて、
		# 且つリファレンスの物を対象にリファレンスを解除(Make Editable)
		if nodeTypeList[1].find("User::") >= 0 and isReferenced == True:
			print nodePath
			print (u"	library : {0}".format(nodeTypeList[1]))
			print (u"	type : {0}".format(nodeTypeList[2]))
			print (u"	compoundType : {0}".format(compoundType))
			print (u"	isReferenced : {0}".format(isReferenced))
			print ""
			cmds.vnnCompound(bifrostBoardNode, nodePath, setIsReferenced=False)

(ライブラリのパスが「User::」とついている物を対象にしています)

こちらのスクリプトはご自由に改造してお使いください。


あと一応ですが、ネットから取得したコンパウンドを使用して作成したコンパウンドの場合は、このスクリプトを使ってリファレンスを解除して配布すると良くないかなと思いますので気を付けた方がよさそうです(明確に再配布可のものなら良いと思いますが)


…ちなみに「vnnCompound」コマンドって何故かMaya2017のヘルプにしか記載がなくて、2018とか2019のヘルプには記載がないんですよね…、謎です。
(Bifrostでガッツリ使っているっぽいので廃止にはならないと思いますが…)