LoginSignup
1
0

mayaで ファイルを開かずにreferenceしてるファイルを知りたい2

Last updated at Posted at 2023-12-15

mayaで ファイルを開かずにreferenceしてるファイルを知りたい
https://qiita.com/9boz/items/10da0a3c9ba4f4305925

承前

なんかうまく行かない奴

実際の案件データで試していたところ、アセットを何も使ってないと返ってくるファイルが多数。
maファイルの中身を覗いてみると

file -rdi 1 -ns "hoge" -rfn "hogeRN" -op "v=0;" -typ
		 "mayaAscii" "C:/Users/kubo/Desktop/tama.ma";
file -r -ns "hoge" -dr 1 -rfn "hogeRN" -op "v=0;" -typ
		 "mayaAscii" "C:/Users/kubo/Desktop/tama.ma";



かよ!(伯方の塩の感じで

対応

1行ずつ評価はするとして、

  • file で始まって、 ; で終わってる場合は従来通りその行を取得
  • file で始まって、 ; で終わっていない場合は、次以降の行も連結させる。
  • 行の連結が始まっていて、 ; で終わってる場合は行の連結を終了

とかですかねぇ

雑改造

def getReferenceFilePath(sceneFilePath):
    allFilePath = []
    
    with open(sceneFilePath,"r") as f:
        lines = f.readlines()

        tmpString = ""
        for l in lines:            
            if l.startswith("file -r"):            
                if l.endswith(";\n"):  
                #1行で完結してるパターン
                    tmpString = l.split(" \"")[-1]
                    referenceFilePath = tmpString.replace("\";\n","")
                    
                    if referenceFilePath not in allFilePath:
                        allFilePath.append(referenceFilePath)

                    tmpString = ""
                    continue      
                else:
                #1行で完結してないので、連結開始
                    tmpString = l.replace("\n","").replace("\t"," ")                    
                    continue

            elif l.startswith("file -r") == False:
                if tmpString != "":
                #連結受付中
                    if l.endswith(";\n"):
                    #連結終了
                        tmpString = tmpString + l.replace("\n","")
                        tmpString = tmpString.replace("\t"," ")
                        
                        tmpString = l.split(" \"")[-1]
                        referenceFilePath = tmpString.replace("\";\n","")
                        
                        if referenceFilePath not in allFilePath:
                            allFilePath.append(referenceFilePath)
                        
                        tmpString = ""
                        continue     

                    elif l.endswith("\n"):
                    #連結継続
                        tmpString = tmpString + l.replace("\n","").replace("\t"," ")
                        continue
                else:
                #連結受付してない
                    tmpString = ""                    
                    continue                            
        f.close()

    return allFilePath
    
sceneFilePath = "C:/Users/kubo/Desktop/refTest.ma"
print(getReferenceFilePath(sceneFilePath))

おっけぇ 改行対応はなんとかできました。
まだ見ぬ障害はあるかもしれませんが、一旦これにて〆ます。

1
0
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
1
0