Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting socket using only python for bulk processing of animations #5

Open
Animixer opened this issue Apr 8, 2021 · 9 comments
Open

Comments

@Animixer
Copy link

Animixer commented Apr 8, 2021

Hello Numes,

Hope you are well!

I am setting up a workflow for creating offline animations using FACSvatar in bulk. I am using the FACSvatar-Blender addon. As part of this process, I try connect the socket from within Blender using bpy.ops.socket.connect_subscriber(). But somehow this does not actually connect the socket. It shows below message in the python console when connecting:

Info: Connecting ZeroMQ socket...
Info: Sub connected to: tcp://127.0.0.1:5572
Waiting for data...
{'FINISHED'}

And when disconnecting:

Nothing yet...
Info: Subscriber socket closed
{'FINISHED'}

But I don't get a message in the info editor 'sub connected to....' or 'subscriber socket closed' the way I do when I manually click 'connect socket' and 'disconnect socket'. Also, the UI interface of the add-on's panel does not change either, until I hover the mouse pointer over the panel. But when I run facsvatar, there is no data transfer to the model.

So I wonder whether you have any ideas on how to make this work.
I looked for how to simulate UI interaction with the addon's panel through python, but could not find anything useful.

By the way, the main idea of the bulk process is like this:

  • have a folder containing one csv file for every animation you need (say 100)
  • have a MBLab character ready and selected in Blender

Loop from within blender python script:

  • connect socket
  • rename first csv in folder to 'demo.csv'
  • call .bat script that loads the 3 conda environments + command 'python main.py'
  • time.sleep (enough time to send CSV data)
  • save .blend file
  • rename csv file to original name
  • disconnect socket
@NumesSanguis
Copy link
Owner

I try connect the socket from within Blender using bpy.ops.socket.connect_subscriber(). But somehow this does not actually connect the socket. It shows below message in the python console when connecting:

If it is saying "Waiting for data..." it is connected, but no data is being send to this socket.

Also, the UI interface of the add-on's panel does not change either, until I hover the mouse pointer over the panel. But when I run facsvatar, there is no data transfer to the model.

This is a limitation of Blender. I also noticed I sometimes have to hover over it for Blender to update it.

So I wonder whether you have any ideas on how to make this work.

I looked for how to simulate UI interaction with the addon's panel through python, but could not find anything useful.
I don't know exactly where the problem is, but here are some things you could try:

  1. Check if any FACSvatar data is being send to socket port 5550, which is the default value for FACSvatar-Blender add-on. You can test this by using the module "test_msg": https://github.com/NumesSanguis/FACSvatar/blob/v0.4.0/modules/test_msg/main.py
    The following command is from memory, so you might have to adjust it a bit:
    conda activate your_env_name
    cd modules/test_msg/
    python main.py --sub_port 5550
    
    You should see output here if data is correctly send to this port.
    If you do NOT see data here, it means the problem is somewhere in FACSvatar, and not in the Blender add-on. Maybe some port value needs to be changed.

Loop from within blender python script:

I don't know how your .bat file looks like, but renaming is probably not necessary.
You can supply additional arguments to main.py, which modify it's behavior.
I think you're looking for:

python main.py --csv_arg my_file_name.cv

You can check all the available commands with:

python main.py -h

Probably you want to be using v0.4.0 branch of FACSvatar, not the outdated master branch


Hope this will bring you further in getting it all to work!

@Animixer
Copy link
Author

Hi,

Thanks for the quick response!

If it is saying "Waiting for data..." it is connected, but no data is being send to this socket.

I would expect so too.
However, when I connect by clicking 'connect socket', I see this in the lower info area:
image

And I see this in the info editor:
image

But when I use bpy.ops.socket.connect_subscriber() I don't see any of these message, whether by issuing the command in my script or in the python console. So I get the idea that the command is not followed through somehow, if that makes any sense.

I don't know how your .bat file looks like, but renaming is probably not necessary.

Thanks for the tip. I think renaming is best for me, because I'm not sure how to update the --csv_arg in the .bat file each time.

Probably you want to be using v0.4.0 branch of FACSvatar, not the outdated master branch

I assume you mean the v0.4.0 branch of the add-on, right?

cheers!

@Animixer
Copy link
Author

Correction: when I use bpy.ops.socket.connect_subscriber() I see the following in the info editor:

image

But not the other messages.

@NumesSanguis
Copy link
Owner

NumesSanguis commented Apr 19, 2021

Did you try the test_msg module recommendation I gave? The socket works the same as the Blender add-on, but is easier to debug (find the problem). If the messages don't arrive there, there is a socket misconfiguration.

@Animixer
Copy link
Author

I have now; I didn't realize test_msg works the same as the add-on, so thanks :)

Unless I specify a subscriber port, it does not accept any data: INFO:root:No functions given, nothing to start

But if I give it the subscriber port that process_facstoblend publishes to, it receives the data and gives output.
So I think the add-on should receive the data as well, because it is subscribed to the same port.

@NumesSanguis
Copy link
Owner

Thank you for trying this out.

Unless I specify a subscriber port, it does not accept any data

That's correct. This module can work as a tester for publishing and receiving messages, but for that it needs to know which subscriber or publisher port.

But if I give it the subscriber port that process_facstoblend publishes to, it receives the data and gives output.
So I think the add-on should receive the data as well, because it is subscribed to the same port.

Okay, this is weird. Can you tell me which port you used for test_msg and what the value is in the interface of the FACSvatar Blender add-on?


Can you start Blender with a terminal? On which OS are you?
On Linux it would be the command ./blender, but for Windows I don't remember on the top of my head (cd path\to\Blender\install\location & blender.exe)

The terminal will show what data Blender receives. If there is not data here as well, the add-on is not receiving the data. If we do see data, then there is a problem using that data to animate a character.

@Animixer
Copy link
Author

Hi,

The port is 5572.

The terminal will show what data Blender receives.
I forgot to look there.... It says:

Info: Connecting ZeroMQ socket...
Info: Sub connected to: tcp://127.0.0.1:5572
Waiting for data...
Traceback (most recent call last):
  File "...blablabla\Roaming\Blender Foundation\Blender\2.83\scripts\addons\FACSvatar-Blender-master\facsvatar_ops.py", line 111, in timed_msg_poller
    sockets = dict(self.poller.poll(0))
  File "C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\modules\bpy_types.py", line 709, in __getattribute__
    properties = StructRNA.path_resolve(self, "properties")
ReferenceError: StructRNA of type SOCKET_OT_connect_subscriber has been removed

So I guess the add-on is not receiving the data.

Thanks! Hope this is any help!

@NumesSanguis
Copy link
Owner

Just to make sure, when you tried the test_msg module, you run it with python main.py --sub_port 5572? Not the 5550 I suggested above?

To make sure, this error:

Traceback (most recent call last):
  File "...blablabla\Roaming\Blender Foundation\Blender\2.83\scripts\addons\FACSvatar-Blender-master\facsvatar_ops.py", line 111, in timed_msg_poller
    sockets = dict(self.poller.poll(0))
  File "C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\modules\bpy_types.py", line 709, in __getattribute__
    properties = StructRNA.path_resolve(self, "properties")
ReferenceError: StructRNA of type SOCKET_OT_connect_subscriber has been removed

appears directly when you press the "connect" button? Not when you do something else like stopping the connection?

If it directly appears, then this error is indeed with the add-on. I don't know how to solve this just from this error message, so I will need to be trying some stuff. It may take some time before I have time to look into this.

@Animixer
Copy link
Author

Just to make sure, when you tried the test_msg module, you run it with python main.py --sub_port 5572? Not the 5550 I suggested above?

Yes. If run it with --sub_port 5550 nothing happens when I send data to it.

To make sure, this error: appears directly when you press the "connect" button? Not when you do something else like stopping the connection?

No, the error does not appear when I press the button in the add-on's interface.
It only appears when I run bpy.ops.socket.connect_subscriber() in the python console, or as part of a script. And yes, it directly appears then.

If it directly appears, then this error is indeed with the add-on. I don't know how to solve this just from this error message, so I will need to be trying some stuff. It may take some time before I have time to look into this.

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants