[Python] Not blocking the main thread

[Python] Not blocking the main thread

Anonymous
Not applicable
834 Views
1 Reply
Message 1 of 2

[Python] Not blocking the main thread

Anonymous
Not applicable

I need to get the following code working in Maya, Max and Motion Builder.

 

Get all the objects in the scene.
Move all objects
Get New position

 

This is a simplified version so id prefer if I not explain why im doing everything.

The problem I am encountering is that when I move all the objects in the scene, they are not actually moved until my code inside the script editor is done executing. I imagine this is because it is blocking the main thread as long as its running.

 

For example if you had something like
MoveAllObjectsBy50InX()
time.sleep(50)

 

None of the objects would actually get moved for 50 seconds. Until you have stopped running code in the script editor.

 

I can solve the problem in Maya by starting a new thread and waiting a second for the code to finish executing then check the position. Threading crashes max and mobu though.

 

Is there anyway to force max to update before continuing in my code? Or threading that works in Max?

0 Likes
835 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

I'm no expert on this but in Max, maybe you can try redrawing the viewport by adding this to your Python function:

time = MaxPlus.Core.GetCurrentTime()
MaxPlus.ViewportManager.RedrawViews(time)
return

 

Taken from the documentation examples. Hope this helps!

 

J-Small

0 Likes