Last active
March 4, 2020 09:45
-
-
Save GRGSIBERIA/8630178 to your computer and use it in GitHub Desktop.
Mayaのボーンの情報を書き出すためのスクリプト.ボーン名,親ボーン名,X,Y,Zで追記.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- encoding: utf-8 | |
import maya.cmds as cmds | |
import maya.mel as mel | |
import csv | |
import codecs | |
# ルートボーンが選択されている状態で実行する必要あり | |
def GetBoneNames(): | |
cmds.select(hierarchy=True) | |
return cmds.ls(sl=True) | |
def GetParentBone(name): | |
parent = cmds.listRelatives(name, p=True) # 親ボーン名を取得 | |
if parent != None: | |
return parent[0] | |
return "" | |
def ConstructParentHash(bones): | |
bone_hash = {} | |
for bone in bones: | |
bone_hash[bone] = GetParentBone(bone) | |
return bone_hash | |
def ConstructPositionHash(bones): | |
positions = {} | |
for bone in bones: | |
# ボーンの座標を取得 | |
positions[bone] = cmds.xform(bone, q=True, ws=True, t=True) | |
return positions | |
names = GetBoneNames() | |
parents = ConstructParentHash(names) | |
positions = ConstructPositionHash(names) | |
with codecs.open('c:/output_bones.csv', 'w', 'shift_jis') as f: | |
w = csv.writer(f, lineterminator='\r\n', delimiter=',') | |
for name in names: | |
row = [name, parents[name]] + positions[name] | |
w.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment