简体   繁体   English

如何使用已经运行的blender运行python脚本?

[英]How do I run a python script using an already running blender?

Normally, I would use "blender -P script.py" to run a python script. 通常,我会使用“blender -P script.py”来运行python脚本。 In this case, a new blender process is started to execute the script. 在这种情况下,启动一个新的blender进程来执行脚本。 What I am trying to do now is to run a script using a blender process that is already running, instead of starting a new one. 我现在要做的是使用已经运行的blender进程运行脚本,而不是启动一个新脚本。

I have not seen any source on this issue so far, which makes me concern about the actual feasibility of this approach. 到目前为止,我还没有看到任何关于这个问题的消息来源,这使我对这种方法的实际可行性感到担忧。

Any help would be appreciated. 任何帮助,将不胜感激。

Blender isn't designed to be started from the cli and to then keep receiving more commands from the cli as it is running. Blender不是设计用于从cli启动,然后在cli运行时继续从cli接收更多命令。 It does however include a text editor that can open text files and run the text block as a python script, it also includes a python console that can be used to interactively type in commands while blender is running. 但它包含一个文本编辑器 ,可以打开文本文件并将文本块作为python脚本运行,它还包括一个python控制台 ,可用于在blender运行时以交互方式键入命令。 You may also find this addon useful as it lets you to run a text block in the python console, this leaves you with an interactive session that contains the variables as they exist at the end of the scripts execution. 你也可以发现这个插件很有用,因为它允许你在python控制台中运行一个文本块,这会留下一个交互式会话,其中包含脚本执行结束时存在的变量。

There is a cli option to run blender as a python console blender --python-console - the gui does not get updated while this console is running, so you could open and exec several scripts and then when you exit the console, blender will update it's gui and allow interactive use, or if you start in background mode -b then it will quit when you exit the console. 有一个cli选项来运行blender作为python控制台blender --python-console - 当这个控制台运行时gui没有得到更新,所以你可以打开并执行几个脚本然后当你退出控制台时,blender会更新它是gui并允许交互式使用,或者如果你以后台模式-b启动,那么它将在你退出控制台时退出。

My solution was to launch Blender via console with a python script (blender --python script.py) that contains a while loop and creates a server socket to receive requests to process some specific code. 我的解决方案是通过控制台启动Blender,其中包含一个包含while循环的python脚本(blender --python script.py),并创建一个服务器套接字来接收处理某些特定代码的请求。 The loop will prevent blender from opening the GUI, and the socket will handle the multiple requests inside the same blender process. 循环将阻止blender打开GUI,套接字将处理同一个blender进程内的多个请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM