Skip to content

Instantly share code, notes, and snippets.

@whaison
Created November 22, 2016 09:17
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 whaison/5025ac05ff50c1de849698497b87463d to your computer and use it in GitHub Desktop.
Save whaison/5025ac05ff50c1de849698497b87463d to your computer and use it in GitHub Desktop.
Mayabatch_refImport_And_oneTimeLine_Chara.py
# -*- coding: utf-8 -*-
import sys;
from maya import cmds
import pymel.core as pm
import shutil
import os
# -*- coding: utf-8 -*-
import os.path
import sys;
import maya.cmds as cmds
import maya as maya
import maya.mel as mel
import pymel.core as pm
import os
import os.path
import math
from python.MotionMerge.p015Reference_importReference import Reference_importReference_Simple_workspaces_all_do_method_Class
from python.MotionMerge.p020workspaces_all_do_method_010_move_value_zero_start import Workspaces_all_do_method_010_move_value_zero_start_class
from python import Debug
from datetime import datetime
#import maya.standalone
#maya.standalone.initialize( name='python' )
print("==============Mayabatch_refImport_And_oneTimeLine_Chara.py.py inside================sys.argv=")
print sys.argv
print("==============Mayabatch_refImport_And_oneTimeLine_Chara.py.py inside================sys.argv=")
Debug=Debug.Debug
def FileAppendStr(filepath,str):
print(u"===========FileAppendStr(filepath= "+filepath+",str= "+str+")=============")
f = open(filepath, 'a')
f.write(str)
f.close()
def SaveTextFile(filepath,outputText):
print("==============================SaveTextFile================================Start")
saveTxtPath=filepath
fileExCheckHead0=os.path.exists(saveTxtPath) and os.path.getsize(saveTxtPath)
outputTxt=outputText
#////////////////////////////////////////////////////write
fileExCheckHead=os.path.exists(saveTxtPath) and os.path.getsize(saveTxtPath)
if fileExCheckHead == 0:
print ("file is not exist make new Text File $saveTxtPath= " + saveTxtPath)
#-------------------------------------------------- inside text File Delete
#Put the file path to a variable
exampleFileName=saveTxtPath
#Put the file identifier to a variable
fileId=open(exampleFileName,"w")
#string you want to write
fileId.write("")
#write end
fileId.close()
#pm.internal.shellOutput("echo " + str(outputTxt) + " >> " + saveTxtPath, convertNewlines=False, stripTrailingNewline=False)
FileAppendStr(saveTxtPath,outputTxt+"\n")
#----------------------------------------------------------
else:
print ("txt is Found reSave Text File $saveTxtPath= " + saveTxtPath)
#type return.txt >> output.txt
#pm.internal.shellOutput("echo " + str(outputTxt) + " >> " + saveTxtPath, convertNewlines=False, stripTrailingNewline=False)
FileAppendStr(saveTxtPath,outputTxt+"\n")
print ("==============================SaveTextFile================================End")
#/////////////////////////////////////////////////////////////////
def LogAndTimeSave(title="none"):
workspaceRootDirectory=cmds.workspace( q=True, directory=True ,rootDirectory=True)
FilePath=workspaceRootDirectory+"Auto_Log.txt"
datetimeObj=datetime.now()
datetimeStr=datetimeObj.strftime('%Y/%m/%d %H:%M:%S')
str=datetimeStr+" , "+title+"\n"
print("FilePath="+FilePath)
print("str="+str)
SaveTextFile(FilePath,str)
def p04_refimportWorkSpace():
LogAndTimeSave("p04_refimportWorkSpace ")
print("p04_refimportWorkSpace starting............................................Workspaces_all_do_method_010_WorkSpace")
Workspaces_all_do_method_010_Instance = Workspaces_all_do_method_010_move_value_zero_start_class.Workspaces_all_do_method_010_move_value_zero_start_class() # Class export instance.
Workspaces_all_do_method_010_Instance.workspaces_all_do_method_010_move_value_zero_start_py()
print("p04_refimportWorkSpace Ending............................................Workspaces_all_do_method_010_WorkSpace")
LogAndTimeSave("END ")
def p03_refimportWorkSpace():
LogAndTimeSave("p03_refimportWorkSpace ")
print("p03_refimportWorkSpace starting............................................refimportWorkSpace")
Reference_importReference_Simple_workspaces_class_Instance = Reference_importReference_Simple_workspaces_all_do_method_Class.Reference_importReference_Simple_workspaces_all_do_method_Class() # Class export instance.
Reference_importReference_Simple_workspaces_class_Instance.Reference_importReference_Simple_workspaces_all_do_method_py()
print("p03_refimportWorkSpace Ending...........................................refimportWorkSpace")
p04_refimportWorkSpace()
def evalMelsetProject_C00100(FullDirPath):
print("-----------------------------------maya.mel.eval evalMelsetProject(evalstr)----------------------------------------")# 20161121
evalstr='setProject("'+FullDirPath+'");' #OK
print("evalstr="+evalstr);
maya.mel.eval(evalstr) #OK
print("----------------------------------maya.mel.eval evalMelsetProject(evalstr) End----------------------------------")
def p02_SetWorkSpace(workspacepath):
LogAndTimeSave("p02_SetWorkSpace ")
print ("p02_SetWorkSpace (workspacepath="+workspacepath)
#path = 'C:/temp'
#path = workspacepath
#mel.eval('string $path = "%s";' % path)
#evalstr='string $path = "'+path+'" ;'
#print ("evalstr= "+evalstr)
#mel.eval(evalstr)
#mel.eval('print("$path= "+$path)')
#print("")
#mel.eval('setProject $path;')
cmds.workspace( directory=workspacepath)
evalMelsetProject_C00100(workspacepath)
workspaceRootDirectory=cmds.workspace( q=True, directory=True ,rootDirectory=True)
print("p02_SetWorkSpace workspace RootDirectory setting="+workspaceRootDirectory)
p03_refimportWorkSpace()
def rigBakeAndOnelineOutput():
Instance = Workspaces_all_do_method_010_move_value_zero_start_class.Workspaces_all_do_method_010_move_value_zero_start_class()
#Call Method
Instance.workspaces_all_do_method_010_move_value_zero_start_py()
def p01_UnEscapeWorksSpacePath(pathstr):
LogAndTimeSave("p01_UnEscapeWorksSpacePath")
print ("p01_UnEscapeWorksSpacePath (pathstr="+pathstr)
if pathstr.find('////')!=-1:
global IHaveCmdWorkSpacePath
IHaveCmdWorkSpacePath=1
global CmdWorkSpacePath
CmdWorkSpacePath=pathstr
print("p01_UnEscapeWorksSpacePath found OK CmdWorkSpacePath= "+CmdWorkSpacePath)
# すべて置換
CmdWorkSpacePath = CmdWorkSpacePath.replace("////", ":/")
print("rp01_UnEscapeWorksSpacePath eprace //// CmdWorkSpacePath= "+CmdWorkSpacePath)
p02_SetWorkSpace(CmdWorkSpacePath)
else:
print("////is Notfound")
def Mayabatch_refImport_And_oneTimeLine_Chara(workspacepath):
print ("Mayabatch_refImport_And_oneTimeLine_Chara (workspacepath="+workspacepath)
p01_UnEscapeWorksSpacePath(workspacepath)
IHaveCmdWorkSpacePath=0
CmdWorkSpacePath=""
sysArgvLength=len(sys.argv)
print("sysArgvLength= "+str(sysArgvLength))
"""
for i in range(sysArgvLength):
print i
myStr=sys.argv[i]
print ("sysArgvLength["+str(i)+"]= "+myStr)
UnEscapeWorksSpacePath(myStr)
#if sysArgvLength[i].find('////')!=-1:
# IHaveCmdWorkSpacePath=1
# CmdWorkSpacePath=i
# print("ワークスペースを見つけました。CmdWorkSpacePath= "+CmdWorkSpacePath)
"""
if IHaveCmdWorkSpacePath==0:
print("Command workspacepath is not found !!NG")
#sys.exit ()
if IHaveCmdWorkSpacePath==1:
print("Command workspacepath is found !!OK")
#Reference_importReference_Simple_workspaces_class_Instance = Anim_File_Export_class.Anim_File_Export_class() # Class export instance.
#Reference_importReference_Simple_workspaces_class_Instance.Reference_importReference_Simple_workspaces_all_do_method_py()
#print("-----------------test-------------------------")
#MayapyExeSimple00100 ("D////Maya/scripts/python/MotionMerge/testWorkspace/01RodLite_auto")
#print("-----------------test--------------------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment