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 3 years have passed since last update.

mayaの環境を構築していく 6日目

Posted at

さて、骨打ちツールで寄り道したのでリグを進めていきます。

いきなり組み始めると、やり直しが面倒なので
トライアンドエラーしやすいようにリグをビルドするシステムを組んでしまいます。

最終的にはモジュラーリギングシステムにするとして、
今は開発用なので

特定のスクリプトリストを選択して実行

まずはこれだけにしてみようかと。

pythonFileの実行

実行したいのは pythonFileなので、pythonファイルを呼び出して実行する方法を調べる。

"D:\hoge.py"

\hoge.py"
print("hoge!")

このファイルを指定して実行したいとする。

import を使うとなると
pathをsys.pathに追加後、import hoge するとしてこんな感じかしら

import os
import sys
def sourceScriptFile(filePath):
    dirPath = os.path.dirname(filePath)
    fileName = os.path.basename(filePath).split(".")[0]
    
    if dirPath not in sys.path:
        sys.path.append(dirPath)

    exec("import " + fileName)

exec を使うとなると
exec(open("D:\hoge.py").read())

def sourceScriptFile(filePath):    
    exec(open(filePath).read())

んー とりあえず execで('A)

fileのリストを取得

特定のフォルダに格納されているファイルのリストを取得したい

os を使うとこんな感じかしら

import os
def listFiles(dirPath,exts = None):
    files = []            
    for path in os.listdir(dirPath):
        if os.path.isdir(dirPath+path): 
            continue
        
        else:                        
            ext = path.split(".")[-1]
            fileName = os.path.basename(path)
            if exts != None and ext not in exts:
                continue

            files.append(fileName)
    
    return files

ファイルやディレクトリが大量になってくると pathlibを使った方が早いのだけれども、一旦osを使ってしまおう。

あとは適当にGUIをつけて・・・・
あれ、そもそもQFileSystemModel使えばファイルリストできるなということで

image.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?