Play pause animation with a single variant (Setting a single hotkey) usign python

Play pause animation with a single variant (Setting a single hotkey) usign python

fabiodimperio
Participant Participant
1,519 Views
21 Replies
Message 1 of 22

Play pause animation with a single variant (Setting a single hotkey) usign python

fabiodimperio
Participant
Participant

Hi everybody!

I tried the script in "Script Editor":

 

isPlaying = False

isPausing = False

 

def myPlayToggle():

global isPlaying

global isPausing

 

if not isPlaying:

playCAnimation("Insieme")

isPlaying = True

 

else:

isPausing = not isPausing

pauseCAnimation("Insieme", isPausing)

 

Once I do double click on the Variant is not running.

And the promp write the message:

File "<string>", line 1, in <module>

NameError: name 'myPlayToggle' is not defined

 

Can someone help me?

I attach the sample file.

 

Thank you

fabiodimperio_0-1666691843194.png

0 Likes
Accepted solutions (1)
1,520 Views
21 Replies
Replies (21)
Message 2 of 22

__daniel.lincoln__
Autodesk
Autodesk

Hi, it looks like your script lost the original indentations from the example.

Just add the indentations back and it seems to work.

isPlaying = False
isPausing = False

def myPlayToggle():
    global isPlaying
    global isPausing

    if not isPlaying:
        playCAnimation("insieme")
        isPlaying = True

    else:
        isPausing = not isPausing
        pauseCAnimation("insieme", isPausing)
0 Likes
Message 3 of 22

fabiodimperio
Participant
Participant

I don't know if I am doing something wrong.. But it is not working yet

fabiodimperio_0-1666705436205.png

 

0 Likes
Message 4 of 22

__daniel.lincoln__
Autodesk
Autodesk
Did you press the 'Run' button in the Script Editor after adding the indentations?
0 Likes
Message 5 of 22

fabiodimperio
Participant
Participant

Yes. But nothing happens

0 Likes
Message 6 of 22

__daniel.lincoln__
Autodesk
Autodesk

It may work better after restarting VRED.example.gif

0 Likes
Message 7 of 22

fabiodimperio
Participant
Participant

Maybe is the vred version. I am using 2022.2. Do you think should be this? I tried to restart vred. Sometimes work. most of the times doesn't. 😞

0 Likes
Message 8 of 22

__daniel.lincoln__
Autodesk
Autodesk
It is working for me in 2022.2. Are you clicking in the render window to give it focus and then pressing the Hotkey?
0 Likes
Message 9 of 22

Christian_Garimberti
Advisor
Advisor

Hi Fabio, do you still have error, red lines, in the terminal after pushing the Run button on the script editor or after executing the variatset?

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 10 of 22

fabiodimperio
Participant
Participant

Yes I do. But nothing changes

0 Likes
Message 11 of 22

fabiodimperio
Participant
Participant

@Christian_Garimberti No errors yet. But doesn't work

0 Likes
Message 12 of 22

fabiodimperio
Participant
Participant
0 Likes
Message 13 of 22

fabiodimperio
Participant
Participant

Video Sample

0 Likes
Message 14 of 22

Christian_Garimberti
Advisor
Advisor

Could you share again your vpb file so we can test on it?

Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 15 of 22

fabiodimperio
Participant
Participant

sure!

0 Likes
Message 16 of 22

Christian_Garimberti
Advisor
Advisor

You have to put somewhere a resetCAnimation('ClipName').

If not, when the animation is ended, it plays no more.

To be sure all your animation are ready after loading the file, put it on the script editor.

If you want to reset while using, create a variantset

cgarimberti_0-1666785829648.png

Best

Chris

 

 

 

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 17 of 22

fabiodimperio
Participant
Participant

Thank you Chris! 😄 Now it works! One last question. I tried a variant set to stop the animation. It could be useful for me.

As you can see in the video, when I press play and pause it works properly, but if I try to stop the animation (reset), play doesn't work. I have to run again the script. 

Is there a way to avoid running again the script after stopping the animation?

0 Likes
Message 18 of 22

fabiodimperio
Participant
Participant
0 Likes
Message 19 of 22

Christian_Garimberti
Advisor
Advisor

Stop does not exists, the pause is the same thing and it is enough.

probably, when you execute the reset, you have to reset also your variables isPlaying and isPausing accordingly.

So when you write 

 

resetCAnimation('ClipName')

 

add also 

 

isPlaying = False

isPausing = False

 

Best

Chris

 

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Message 20 of 22

fabiodimperio
Participant
Participant

You mean in the var set or in the script editor?

0 Likes