2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Maya】UnityにFBXとして送信するをボタンひとつで行えるツール

Posted at

概要

MayaのPythonスクリプティングの練習用にMayaで標準機能として備わっている「Unityに送信」するを
ワンポチで行えるツールを作成してみました。

環境

  • Maya Indies2022.3
  • Python3.7.7

UnityにFBXとして送信

「Unityに送信>すべて」をpythonで行ってみます。

GUI

2021-12-19_20h34_20.png

SendToUnityでUnityにFBXとして出力します。

Python

import maya.cmds as cmds
import pymel.core as pm
import os

saveKey = "KeyTextBox"

def SendToUnity(*args):
    input = pm.textField('textBox',q=1,tx=1 )
    
    file_name = os.path.basename(cmds.file(query=True,sceneName=True)).replace(".mb","")
    path = os.path.join(input,file_name)
    fbx_path = os.path.join(path,file_name + '.fbx');
    material_path = os.path.join(path,'Materials');
    texture_path = os.path.join(path,'Textures');
    make_dir(path);
    make_dir(material_path);
    make_dir(texture_path);
    cmds.file(fbx_path,force=True,options="v=0;p=17;f=0",type="FBX export",preserveReferences=True,exportAll=True);

def make_dir(path):
    if not os.path.exists(path):
        os.makedirs(path)
    return path

def TextChangeCommand(*args):
    print(args[0])
    cmds.optionVar(stringValue=(saveKey,args[0]))

def MySendToUnity():
    with pm.window(title="MySendToUnity"):
        with pm.rowColumnLayout(numberOfColumns=3):
            pm.text( label='Name' )
    
            if cmds.optionVar(exists=saveKey) == False:
                cmds.optionVar(stringValue=(saveKey,"D:/"))
            text = cmds.optionVar(q=saveKey)
            
            tb = pm.textField('textBox', tx=text,width=400 , changeCommand=TextChangeCommand)
            pm.button(label="SendToUnity",command=SendToUnity)

MySendToUnity();

2021-12-19_20h41_36.png

ついでにマテリアルとテクスチャのフォルダも自動生成します。

まとめ

あってもなくてもなツールかもしれませんが今回練習用に作成してみました。
あると少しだけ便利かもしれません。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?