简体   繁体   English

在 PYTHON 中将网格从一个进程转移到另一个进程

[英]Transferring a mesh from one process to another in PYTHON

I've been cracking my head over this but nothing comes to my mind yet.我一直在为此绞尽脑汁,但我还没有想到任何东西。 I want my script to execute a.py file inside of another already started process.我希望我的脚本在另一个已经启动的进程中执行一个 .py 文件。 I have a maya process opened, and inside for example modo I want to start file hello.py (print 'hello.') inside that exact Maya.我打开了一个 Maya 进程,例如在 modo 中,我想在那个确切的 Maya 中启动文件 hello.py (print 'hello.')。

I already got the PID of that maya process, but don't know how to actually send a command to execute.我已经获得了该 Maya 进程的 PID,但不知道如何实际发送要执行的命令。

is theres some attribute/flag in subprocess or signal modules I could be missing?子进程或信号模块中是否有一些属性/标志我可能会丢失? or is it done even another way?还是以另一种方式完成?

import os

openedMaya = []
r = os.popen('tasklist /v').read().strip().split('\n')
for i in range(len(r)):
    s = r[i]
    if 'maya.exe' in s and ': untitled' in s:
        openedMaya.append(s)
mayaPID = openedMaya.split('maya.exe')[1].split('Console')[0]

I need a command that could execute hello.py in that maya process.我需要一个可以在该 Maya 进程中执行 hello.py 的命令。

You could use RPyC to act as a bridge so that you can communicate from one software to another.您可以使用RPyC作为桥梁,以便您可以从一个软件到另一个软件进行通信。 The idea is that you use RPyC to run an idle server in Maya, where the PYTHONPATH is also pointing to your hello.py script.这个想法是您使用RPyC在 Maya 中运行一个空闲服务器,其中PYTHONPATH也指向您的hello.py脚本。 This server stays active in the session, but the user shouldn't notice it exists.此服务器在 session 中保持活动状态,但用户不应注意到它的存在。

Then in your other software you use RPyC to broadcast a message using the same port as the server so that it triggers it in Maya.然后在您的其他软件中,您使用RPyC使用与服务器相同的端口广播消息,以便它在 Maya 中触发它。 This would then run your command.然后这将运行您的命令。

It's slightly more overhead, but I have been able to use this successfully for stand-alone tools to trigger events in Maya.它的开销稍大一些,但我已经能够成功地将它用于独立工具来触发 Maya 中的事件。 As far as using subprocess , you can use it to run a command in a new Maya session, but I don't think there's a way to use it for an existing one.至于使用subprocess ,您可以使用它在的 Maya session 中运行命令,但我认为没有办法将它用于现有的。

Hope that nudges you in the right direction.希望这会推动您朝着正确的方向前进。

Maybe an easier way would be to transfer your mesh by using an intermediate file.也许更简单的方法是使用中间文件传输您的网格。 One process creates the file, another process (running inside the host app) reads it in.一个进程创建文件,另一个进程(在主机应用程序内运行)读取它。

Thanks for the advices, at the end I found a solution by opening the port of maya, by starting a mel command (at the startup):感谢您的建议,最后我通过启动 mel 命令(在启动时)打开maya端口找到了解决方案:

commandPort -n ":<some_port>";

and connecting from modo to that port through socket:并通过套接字从 modo 连接到该端口:

HOST = '127.0.0.1'
PORT = <some_port>
ADDR=(HOST,PORT)

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
client.send(<message_that_you_want_to_send)
data = client.recv(1024)
client.close()

and i'm able to do whatever I want inside that opened maya, as long as I send mel commands.只要我发送 mel 命令,我就可以在打开的 Maya 中做任何我想做的事情。

Thanks for the help though!不过感谢您的帮助!

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

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