2017-03-16 64 views
-1

我在bash中有一個名爲「Nautilus Script」的腳本。它可以從系統文件夾來執行,使得自定義操作與選定的文件:從bash傳輸值到python腳本

#!/bin/bash 

while [ $# -gt 0 ]; do 
    file=$1 
    #doing smf with selected file 
    shift 
done 

Аlso,我知道在CMD能力推出攪拌機,自定義Python腳本:

blender -b blendfile.blend -P script.py -x 1 -F PNG -f 1 

我whant到取一個值file,並將其傳送到Python腳本中script.py使用它:

#!/bin/bash 

while [ $# -gt 0 ]; do 
    file=$1 
    blender -b blendfile.blend -P script.py//+put here $file// -x 1 -F PNG -f 1  
    shift 
done 

我怎麼能這樣做呢?

關於this answer注意,Python腳本在攪拌機啓動,而不是在bash shell中

+0

你是想說,'攪拌機-b blendfile.blend -P script.py「$ 1」-x 1 -F PNG -f 1'在循環內不會執行你所要求的操作? – tripleee

+0

@tripleee答案來自Nils Werner的作品。 [這個答案](http://stackoverflow.com/questions/10667314/python-script-with-arguments-for-command-line-blender)解釋了爲什麼這種簡單的方式不起作用 – Crantisz

回答

1

blender.stackexchange

攪拌機忽略所有參數的--後,Python不會。您可以搜索在Python --和讀取所有的參數使用

import sys 
argv = sys.argv 
argv = argv[argv.index("--") + 1:] # get all args after "--" 

後,你會被傳遞然後論點看起來像

blender -b blendfile.blend -P script.py -x 1 -F PNG -f 1 -- $file 
+0

這個作品,謝謝! – Crantisz