[maya]maya_usdでシーンにある選択したステージをmaya_usd apiのstageとして取得するには?

How to get the selected stage in the scene in maya_usd as the stage in maya_usd api?

import maya.cmds as cmds

def get_stage(stagePath):
    import mayaUsd.ufe
    #stagePath="|stage1|stageShape1"
    #stage = mayaUsd.ufe.getStage("|stage1|stageShape1")
    stage = mayaUsd.ufe.getStage(stagePath)
    print("stage= "+str(stage))
    # レイヤーを取得
    layer = stage.GetRootLayer()
    print("layer= "+str(layer))

def get_selected_maya_usd_stage():
    selectedlist=cmds.ls(sl=True,long=1)
    print("selectedlist= "+str(selectedlist))
    selectedZero=selectedlist[0]
    selectedZeroType=cmds.objectType( selectedZero )
    print("selectedZeroType= "+str(selectedZeroType))
    
    stagePath=""
    if(str(selectedZeroType)=="mayaUsdProxyShape"):
        stagePath=selectedZero
        get_stage(stagePath)
    elif(str(selectedZeroType)=="transform"):
        stagePath="|stage"+stageNumStr+"|stageShape"+stageNumStr
        get_stage(stagePath)
    else:
        print("not stage!!!!")
        
get_selected_maya_usd_stage()

OUTPUT

selectedlist= ['|stage5']
selectedZeroType= transform
stage= Usd.Stage.Open(rootLayer=Sdf.Find('anon:000002B5C8EA5570:anonymousLayer1'), sessionLayer=Sdf.Find('anon:000002B5C8EA5870:anonymousLayer1-session.usda'), pathResolverContext=Ar.DefaultResolverContext())
layer= Sdf.Find('anon:000002B5C8EA5570:anonymousLayer1')

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

selectedlist= ['|stage5|stageShape5']
selectedZeroType= mayaUsdProxyShape
stage= Usd.Stage.Open(rootLayer=Sdf.Find('anon:000002B5C84B1070:anonymousLayer1'), sessionLayer=Sdf.Find('anon:000002B5C84B1670:anonymousLayer1-session.usda'), pathResolverContext=Ar.DefaultResolverContext())
layer= Sdf.Find('anon:000002B5C84B1070:anonymousLayer1')

参考URL
https://github.com/Autodesk/maya-usd/issues/1046

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です