[英]How do I send an variable to a blender python script?
I have script1, in there the String "path" gets set.我有script1,在那里设置了字符串“路径”。 Then the script1 runs blender as a subprocess, together with script2.
然后 script1 与 script2 一起运行 blender 作为子进程。 Now script2 needs to have access to the String "path", how can I do this?
现在 script2 需要访问字符串“路径”,我该怎么做?
Currently im Saving the string to a text file and then accesing it from script2 but I know this solution is very very ugly.目前我将字符串保存到文本文件,然后从 script2 访问它,但我知道这个解决方案非常难看。
maybe someone has an idea?也许有人有想法? :)
:)
script1:脚本1:
path=("/example/ex/")
subprocess.run([blenderpath, "--background", blenderscene, "--python", scriptpath])
script2 (atm just reading out the txt file with the right path, but that's not how I want it to be): script2(atm 只是用正确的路径读出 txt 文件,但这不是我想要的):
file=open("Blabla")
file_name = fiel.readline()
mat_path = file_name
def prepscene(mat_path)
It works right now with the text file, but If I try to import the variable into the second script it won't work, if I try to somehow start the blender script with it it also won't work.它现在适用于文本文件,但如果我尝试将变量导入第二个脚本,它将不起作用,如果我尝试以某种方式启动搅拌机脚本,它也将不起作用。
import sys # to get command line args
argv = sys.argv
argv will be array
If you just want to access the varible you can use importing.如果您只想访问变量,您可以使用导入。
ScriptA:脚本A:
...
path = "/example/ex/"
...
ScriptB:脚本B:
from .ScriptA import path
(this only works if both scripts are in the same directory) (这仅在两个脚本位于同一目录中时才有效)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.