2013-10-30 2 views
0

안녕하세요, Maya 용 Python 스크립트 작성 초보자. 나는 참조와 함께 Maya 파일을 여는 과정을 자동화하는 스크립트를 작성하려고합니다. 대개 상위 파일과 참조 파일이 다른 대상에있을 때 Maya는 참조되는 파일을 열 수 없으므로 파일을 열어 파일을 열어야합니다. 나는 이것을 자동화하려고 노력하고있다. 사용자가 파일을 열려고하면 모든 참조와 함께 열어야합니다. 지금까지 이걸 가지고 있는데, 가장 중요한 부분은 혼란 스럽습니다. 모든 행동이 일어나는 곳Maya의 다른 대상에서 참조 파일을 자동으로로드하기위한 스크립트

import pymel.api as api 

def callFunc(): 
    print "hello world" # just a print cmd to check 

print "registering a file reference call back" 
cb = api.MSceneMessage_addCallback(api.MSceneMessage.kAfterOpen, callFunc()) 

def callbackOff(): 
    api.MSceneMessage.removeCallback(cb) 

그래서 기능 callFunc()가 호출 될 때,이입니다. 이제 어떻게 진행해야할지 모르겠습니다.

+0

에서 마야 파이썬 문서를 체크 아웃 Maya에서이 메커니즘을 구현 한 ** dirmap **은 자동으로 파일을 다른 곳으로 리디렉션 할 수 있습니다. 일반적으로 참조를로드하지 않으면 (사용자가 덮어 쓸 수없는 경우) ** dirmap **을 사용하지 않고 참조를로드하는 경우 너무 늦습니다. – joojaa

답변

2

pymel를 사용하는 특별한 이유가 아니라면, 내가 정기적으로 마야와 함께 가고 싶어요 명령 : fileDialog2file에 대한 자세한 옵션을 보려면

import maya.cmds as cmds 
import os 

def openFileAndRemapRefs(): 
    multipleFilters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)" 

    # Choose file to open 
    filename = cmds.fileDialog2(fileFilter=multipleFilters, dialogStyle=2, fileMode=1) 

    # Open file with no reference loaded 
    cmds.file(filename[0], open=True, force=True); 

    # Dir containing the references 
    refDir = 'C:/References' 

    # A list of any references found in the scene 
    references = cmds.ls(type='reference') 

    # For each reference found in scene, load it with the path leading up to it replaced 
    for ref in references: 
     refFilepath = cmds.referenceQuery(ref, f=True) 
     refFilename = os.path.basename(refFilepath)  
     print 'Reference ' + ref + ' found at: ' + cmds.referenceQuery(ref, f=True) 
     cmds.file(os.path.join(refDir, refFilename), loadReference=ref, options='v=0;') 

openFileAndRemapRefs() 

,이 http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/index.html

+0

고맙습니다.하지만 할 수있는 또 다른 방법을 찾았습니다. – zingy

+0

@zingy이 문제를 해결하기 위해 다른 방법을 찾았습니까? :) –

관련 문제