[maya] MEL To Python2 From pymel For Maya 2016

MEL To Python2

これがシンプルな状態
import pymel.tools.mel2py as mel2py

pyCmd = mel2py.mel2pyStr(melCmd,pymelNamespace=’pm‘)

pyCmd = mel2py.mel2pyStr(melCmd,pymelNamespace=’cmds‘)でいいのかも

# -*- coding: cp932 -*-
import pymel.core as pm
import pymel.tools.mel2py as mel2py
import re
import math
import random
melCmd = """
$value1 = `floatFieldGrp -q -label "Frame range" -v1`;
	"""
pyCmd =  mel2py.mel2pyStr(melCmd,pymelNamespace='pm')

melで改行をしてる「+”¥n”」と「¥n」を けしてから

あと、出力結果がPyMelにならないようにしてみたり。

# -*- coding: cp932 -*-
import pymel.core as pm
import pymel.tools.mel2py as mel2py
import re
import math
import random
melCmd = """
global proc Generic_modelFileOpen()
{
  string $workspaceRoot = `workspace -q -rootDirectory`;
    string $motionFileDir= $workspaceRoot+"scenes/Generic_model_wep.mb";
    file -f -options "v=0;"  -ignoreVersion  -typ "mayaBinary" -o $motionFileDir;
        if(`file -q -writable`==1){
            select `ls -type joint`;
    
    string $joints[] =`ls -type joint`;
   int $jointsLength=size($joints);
    if($jointsLength==0)
    {
      print ("-------------------------joint nothing-----------------------------");
    }else{
        for	($joint in $joints)
        {
            //setKeyframe 0 ,1
            currentTime 0 ;
            setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 -time 0 $joint;
           currentTime 1 ;
            setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 -time 0 $joint;
        }
    }
    print("-------------------------joint-----------------------------");
    print($joint);
    print ("\n-------------------------joint-----------------------------");
    if($joint=="")
    {
    print ("-------------------------joint nothing-----------------------------");
    }
    ////////////////////////////////////////////////////////joint select
            print("TstanceFBXExport()");
           TstanceFBXExport();
    }
}
$value1 = `floatFieldGrp -q -label "Frame range" -v1`;
	"""
		
print "----------------mel code replace----------------------------"
#melCmd = melCmd.replace('$writable_bool','`file -q -writable`')
melCmd = melCmd.replace('"\n--', '"--')
melCmd = melCmd.replace('+"\n"', '')
melCmd = melCmd.replace('\n"', '"')
print("melCmd="+melCmd)
print "------------------------------------------------"
# mel2py.mel2pyStr  
pyCmd =  mel2py.mel2pyStr(melCmd,pymelNamespace='pm')
pyFixed_Dest = ""
#pyFixed_Dest = pyFixed_Dest + "# -*- coding: cp932 -*- \n"
pyFixed_Dest = pyFixed_Dest + "# -*- coding: utf-8 -*- \n"
#pyFixed_Dest = pyFixed_Dest + "# -*- coding: shift-jis -*- \n"
pyFixed_Dest = pyFixed_Dest + "from maya import cmds \n"
pyFixed_Dest = pyFixed_Dest + "from python import Debug \n"
pyFixed = pyCmd.replace("pymel.all","pymel.core")
pyFixed = pyFixed.replace("pm.pm.cmds","cmds")
pyFixed_Dest = pyFixed_Dest + pyFixed+"\n"
print "----------------------python sorce replace----------------------"

pyFixed_Dest = pyFixed_Dest.replace('import pymel.core as pm', 'import pymel.core as pm \nDebug=Debug.Debug')
pyFixed_Dest = pyFixed_Dest.replace('pm.file', 'cmds.file')
pyFixed_Dest = pyFixed_Dest.replace('pm.ls', 'cmds.ls')
pyFixed_Dest = pyFixed_Dest.replace('pm.select', 'cmds.select')
pyFixed_Dest = pyFixed_Dest.replace('pm.internalVar', 'cmds.internalVar')
pyFixed_Dest = pyFixed_Dest.replace('pm.keyframe', 'cmds.keyframe')
pyFixed_Dest = pyFixed_Dest.replace('pm.workspace', 'cmds.workspace')
pyFixed_Dest = pyFixed_Dest.replace('pm.getFileList', 'cmds.getFileList')
pyFixed_Dest = pyFixed_Dest.replace('=="1"', '==1')
pyFixed_Dest = pyFixed_Dest.replace('== "1"', '== 1')
pyFixed_Dest = pyFixed_Dest.replace('print("', 'print(u"')
pyFixed_Dest = pyFixed_Dest.replace('print "', 'print u"')
pyFixed_Dest = pyFixed_Dest.replace('pm.flushUndo()', 'cmds.flushUndo()')
pyFixed_Dest = pyFixed_Dest.replace('pm.parent', 'cmds.parent')
pyFixed_Dest = pyFixed_Dest.replace('pm.objExists', 'cmds.objExists')
pyFixed_Dest = pyFixed_Dest.replace('pm.rename', 'cmds.rename')
pyFixed_Dest = pyFixed_Dest.replace('pm.playbackOptions', 'cmds.playbackOptions')
pyFixed_Dest = pyFixed_Dest.replace('pm.mel.DebugLog', 'self.DebugLog')
pyFixed_Dest = pyFixed_Dest.replace('pm.currentTime', 'cmds.currentTime')
pyFixed_Dest = pyFixed_Dest.replace('pm.setKeyframe', 'cmds.setKeyframe')
#pyFixed_Dest = pyFixed_Dest.replace('maya.mel.eval("listRelatives -pa -ad `ls -sl -l`"', 'cmds.listRelatives(path=True, allDescendents =True,cmds.ls(selection=True, long=True))'))
#for Class
pyFixed_Dest = pyFixed_Dest.replace('():', '(self):')
pyFixed_Dest = pyFixed_Dest.replace('():', '(self):')
regex = r'print+'
#pattern = re.compile(regex)
#matchObj = pattern.match(pyFixed_Dest)
#matchObj = re.search(r'[a-z]+', pyFixed_Dest)

def repl(m):
    inner_word1 = list(m.group(1))  #prin(\w\W)    "prin" "t" " "    real ['t', ' ']
    #print("inner_word1= "+str(inner_word1))   
    inner_word2 = list(m.group(2))    #(.*)     something strings "----1-----" real ['u', '"', '-', '-', '-', '-', '1', '-', '-', '-', '-']
    #print("inner_word2= "+str(inner_word2))
    inner_word3 = list(m.group(3))
    #inner_word4 = list(m.group(4))    #(\")  double cout   real  ['"']
    print("inner_word123= "+str(inner_word1)+str(inner_word2)+str(inner_word3)+""+str(list(m.group(4)))+str(list(m.group(5)))+"")
    #print("inner_word2= "+str(inner_word1)+str(inner_word2)+str(inner_word3))
    #random.shuffle(inner_word)
    #back= m.group(1) + "".join(inner_word) + m.group(3)
    back="00000"+ str(m.end())
    back=m.group(1) +m.group(2)+"("+m.group(3)+m.group(4)+m.group(5)+")" #for print
    back=m.group(1) +"Debug.Log"+"("+m.group(3)+m.group(4)+m.group(5)+")"  #for Debug.Log  Debug Class is https://gist.github.com/whaison/fc625381dce126ca5d88d1f914ce89f0
    
    return back
#text = "Professor Abdolmalek, please report your absences promptly."
text = """
print "----1----"
print "----2----"
print "----3----"
print "----4----"
print "----5----"
print "----6----"
print "----7----"
	"""
#resub=re.sub(r"(\w)(\w+)(\w)", repl, text)
#resub=re.sub(r'(prin\w)', repl, text)
resub=re.sub(r'(.*)(prin\w\W)(.*)(\")(.*)', repl, text)

print("resub    --------------------output  start")
print resub 
#print resub[:m.start()]
#print resub[m.end():]
print("resub    --------------------output  end")
pyFixed_Dest=re.sub(r'(.*)(prin\w\W)(.*)(\")(.*)', repl, pyFixed_Dest)
print("resub  pyFixed_Dest  --------------------output  start")
print pyFixed_Dest 
#print resub[:m.start()]
#print resub[m.end():]
print("resub pyFixed_Dest   --------------------output  end")
print("search    --------------------output  start")
email = "tony@tiremove_thisger.net"
m = re.search(r'print*', text)
print text[:m.start()] +"print("+ text[m.end():]
print("search    --------------------output  end")
print "------------------------------------------------"
print pyFixed_Dest

出力結果

------------------------------------------------
# -*- coding: utf-8 -*- 
from maya import cmds 
from python import Debug 
import pymel.core as pm 
Debug=Debug.Debug

def Generic_modelFileOpen(self):
	
	workspaceRoot=str(cmds.workspace(q=1, rootDirectory=1))
	motionFileDir=workspaceRoot + "scenes/Generic_model_wep.mb"
	cmds.file(motionFileDir, ignoreVersion=1, typ="mayaBinary", options="v=0;", o=1, f=1)
	if cmds.file(q=1, writable=1) == 1:
		cmds.select(cmds.ls(type='joint'))
		joints=cmds.ls(type='joint')
		jointsLength=len(joints)
		if jointsLength == 0:
			Debug.Log(u"-------------------------joint nothing-----------------------------")
			
		
		else:
			for joint in joints:
				cmds.currentTime(0)
				#setKeyframe 0 ,1
				cmds.setKeyframe(joint, breakdown=0, hierarchy='none', shape=0, time=0, controlPoints=0)
				cmds.currentTime(1)
				cmds.setKeyframe(joint, breakdown=0, hierarchy='none', shape=0, time=0, controlPoints=0)
				
			
		Debug.Log(u"-------------------------joint-----------------------------")
		print joint
		Debug.Log(u"-------------------------joint-----------------------------")
		if joint == "":
			Debug.Log(u"-------------------------joint nothing-----------------------------")
			
		Debug.Log(u"TstanceFBXExport()")
		#//////////////////////////////////////////////////////joint select
		pm.mel.TstanceFBXExport()
		
	

value1=pm.floatFieldGrp("Frame range", q=1, v1=1, label=1)

when i create a C++ project in UE5.3 but I create a project it gives me this error message

WindowsTargetRules.Compiler to VisualStudio2019. The current compiler version was detected as: 14.29.30152

Error Message

Running F:/Program Files/Epic Games/UE_5.3/Engine/Build/BatchFiles/Build.bat  -projectfiles -project="F:/Download/Game/CppFuncToBluePrint/CppFuncToBluePrint4/CppFuncToBluePrint4.uproject" -game -rocket -progress
Using bundled DotNet SDK version: 6.0.302
Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -projectfiles -project="F:/Download/Game/CppFuncToBluePrint/CppFuncToBluePrint4/CppFuncToBluePrint4.uproject" -game -rocket -progress
Log file: C:\Users\abcd\AppData\Local\UnrealBuildTool\Log_GPF.txt

Generating VisualStudio project files:
Discovering modules, targets and source code for project...
Microsoft platform targets must be compiled with Visual Studio 2022 17.4 (MSVC 14.34.x) or later for the installed engine. Please update Visual Studio 2022 and ensure no configuration is forcing WindowsTargetRules.Compiler to VisualStudio2019. The current compiler version was detected as: 14.29.30152

日本語 メッセージ

F:/Program Files/Epic Games/UE_5.3/Engine/Build/BatchFiles/Build.bat -projectfiles -project="F:/Download/Game/CppFuncToBluePrint/CppFuncToBluePrint4/CppFuncToBluePrint4.uproject" -game -rocket -progress を実行します。
バンドルされている DotNet SDK バージョンの使用: 6.0.302
UnrealBuildTool の実行: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -projectfiles -project="F:/Download/Game/CppFuncToBluePrint/CppFuncToBluePrint4/CppFuncToBluePrint4.uproject" -game -rocket -progress
ログ ファイル: C:\Users\abcd\AppData\Local\UnrealBuildTool\Log_GPF.txt

VisualStudio プロジェクト ファイルの生成:
プロジェクトのモジュール、ターゲット、ソース コードを検出しています...
Microsoft プラットフォーム ターゲットは、インストールされているエンジンに対して Visual Studio 2022 17.4 (MSVC 14.34.x) 以降でコンパイルする必要があります。 Visual Studio 2022 を更新し、WindowsTargetRules.Compiler を VisualStudio2019 に強制する構成がないことを確認してください。 現在のコンパイラのバージョンは 14.29.30152 として検出されました。

直し方はVisual Studio Installer で個別のコンポーネントタブからMSVC のなかから14.29.30152のチェックを外すこと

参考

https://forums.unrealengine.com/t/help-when-i-create-a-c-project-in-ue5-3-but-i-create-a-project-it-gives-me-this-error-message/1305945

maya ls python のまとめ

このごろサイトが丸ごとなくなったので置いておく

Top Node をとってくる

topNodeList=cmds.ls(assemblies=True)

dagObjects 階層をとってくる

topNodeList=cmds.ls( "root", dagObjects=True, type="transform" )

[UnrealEngine] PythonでGet All Collision Presets

DefaultEngine.iniに記載されているので無理やり読む

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs


project_config_dir=unreal.Paths.project_config_dir()
#D:\MOSAProduct\MOSAProduct\Config\DefaultEngine.ini
DefaultEngineINI_Path=project_config_dir+"DefaultEngine.ini"
print("DefaultEngineINI_Path="+DefaultEngineINI_Path)
#fout = codecs.open('sjis.txt', 'w', 'shift_jis')

import re
def get_CollisionProfileNameStr(content):
    #m = re.search('"(.*)".*', content)
    result = re.findall('"(.*?)"', content)
    print("result[0]="+str(result[0]))
    #print("result[1]="+str(result[1]))
    return str(result[0])

CollisionProfileStrArr=[]
for line in codecs.open(DefaultEngineINI_Path, 'r', 'utf_8'):
    #fout.write(line)
    #print(line)
    if("-Profiles=(Name=" in line):
        ProfilesName=get_CollisionProfileNameStr(line)
        CollisionProfileStrArr.append(ProfilesName)
    if("+Profiles=(Name=" in line):
        ProfilesName=get_CollisionProfileNameStr(line)
        CollisionProfileStrArr.append(ProfilesName)
        
print("-----------------------Do Unique-----------------------------")
CollisionProfileStrSet = set(CollisionProfileStrArr)
CollisionProfileStrArr = list(CollisionProfileStrSet)
CollisionProfileStrArr.sort()
CollisionProfileStrArrBuildCSV=""
for CollisionProfileStr in CollisionProfileStrArr:
    print("CollisionProfileStr="+CollisionProfileStr)
    CollisionProfileStrArrBuildCSV=CollisionProfileStrArrBuildCSV+","+CollisionProfileStr

print("CollisionProfileStrArrBuildCSV="+CollisionProfileStrArrBuildCSV)