VRED play-pause animation with a key

VRED play-pause animation with a key

hobbotuk
Contributor Contributor
5,053 Views
24 Replies
Message 1 of 25

VRED play-pause animation with a key

hobbotuk
Contributor
Contributor

Hi!

 

I would like to play/pause an animation clip (if it not possible, play/pause the timeline with a key its ok too)

 

I have try it  using Python (Vsets let me play animations clips, but I dont know how to plause from them) but in Python I need to know if the animation is playing (to make an "if" to play it or to pause the animation), and I dont know how to use isPlaying() command

 

So, any kind of solution (by python or any other way) its ok for me!

 

some ideas?

 

Thanks!

 

 

 

 

 

 

5,054 Views
24 Replies
Replies (24)
Message 2 of 25

ir
Advocate
Advocate

This works for me:

 

def hvpDrive():
 playCAnimation("drive",0,340)

 

def hvpPause():
 pauseCAnimation("drive",True)
 vrLogWarning("Paused drive animation...")
 
def hvpCont():
 pauseCAnimation("drive",False)
 vrLogWarning("Executing drive animation...")

 
keyP = vrKey(Key_P)
keyP.connect(hvpPause)
keyC = vrKey(Key_C)
keyC.connect(hvpCont)

Message 3 of 25

Anonymous
Not applicable

Hi,

 

after i press pause and want to continue the animation, it jumps back to the beginning of the animation and restarts from there.

Is ther a way to continue the animation from where it stoped at pushing pause ?

 

Thank you,

Andreas

0 Likes
Message 4 of 25

marcus_fritzen
Autodesk
Autodesk

Hi,

 

actually it should resume from where it was paused.

 

/Marcus



Marcus Fritzen
Principal Engineer
0 Likes
Message 5 of 25

Anonymous
Not applicable

Hello, 

Is possible to use only one key to Play/Pause the animation? 

Because I can't find nothing about the script code for this

 

0 Likes
Message 6 of 25

marcus_fritzen
Autodesk
Autodesk

Sure, use only one function and remember the state with a boolean.



Marcus Fritzen
Principal Engineer
0 Likes
Message 7 of 25

Anonymous
Not applicable

Thanks for your reply!

I am new in this, so I don't understand so much.....

Please can you write the code???

 

If I want to play the animation should I write playCAnimation("name")

but if I want to pause/unpause the animation with only a key should I write isPlaying() ???

 

But what should I put into the parenthesis?

 

0 Likes
Message 8 of 25

marcus_fritzen
Autodesk
Autodesk

Here is some untested Python code. Maybe it helps. Keep in mind that it doesn't check if the animation has finished playing.

isPlaying = False
isPausing = False

def myPlayToggle():
    global isPlaying
    global isPausing
    if not isPlaying:
        playCAnimation("Test")
        isPlaying = True
    else
        isPausing =  not isPausing
        pauseCAnimation("Test", isPausing)


Marcus Fritzen
Principal Engineer
Message 9 of 25

Anonymous
Not applicable

If I want to "click" instead to use a key to play or pause the animation......what could be the script for this?

 

For example, for the key is this : keyP = vrKey(Key_P)

But, for a "click" with the mouse, what can I do?

 

Thanks

0 Likes
Message 10 of 25

Christian_Garimberti
Advisor
Advisor

Hi,
Create a variant set with the function myPlayToggle() in the script section.
Create a touchsensor on the geometry you want to use as "button"
Associate the script to the touchsensor.

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 11 of 25

Anonymous
Not applicable

thanks for your reply!

I was trying to use this script, but doesn't work........

isPlaying = False
isPausing = False

def myPlayToggle():
    global isPlaying
    global isPausing
    if not isPlaying:
        playCAnimation("Test")
        isPlaying = True
    else
        isPausing =  not isPausing
        pauseCAnimation("Test", isPausing)

 maybe something is missing....

0 Likes
Message 12 of 25

Christian_Garimberti
Advisor
Advisor

hi, in the script there is a an error...

after the else you have to put  :

isPlaying = False
isPausing = False

def myPlayToggle():
    global isPlaying
    global isPausing
    if not isPlaying:
        playCAnimation("My Clip")
        isPlaying = True
    else:
        isPausing =  not isPausing
        pauseCAnimation("My Clip", isPausing)

and, obviously, where you see "test" or "My Clip", you have to put the name of your clip

 

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 13 of 25

Anonymous
Not applicable

Good morning, 

Yes, I know that I have to put te name of my clip, and thanks for the else: 

but still doesn't work......

If I want to use only this script doesn't work, but, for example, if I put at the end :

 

keyP = vrKey(Key_P)

keyP.connect(myPlayToggle)

 

obviously works....but instead to use a key, I want to click with the mouse or use the Touch Sensor, so, what can I write here?????? 

 

Thanks!

 

 

 

 

 

 

0 Likes
Message 14 of 25

Christian_Garimberti
Advisor
Advisor

write the myPlayToggle() in the script section of a variantset

Annotazione 2019-02-07 104102.png

then connect the variantset with a touchsensor

this should works

 

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

Message 15 of 25

marcus_fritzen
Autodesk
Autodesk

Hi,

the script was only a hint how things could work and yes, there was a ":" missing behind "else".

Besides that, c.garimberti already wrote what you need to do. Create a VariantSet, put the myPlayToggle call into the script tab, create a touch sensor and attach the newly created VariantSet to it.

Cheers,

Marcus



Marcus Fritzen
Principal Engineer
Message 16 of 25

seiferp
Community Manager
Community Manager

Attached a demo file

Message 17 of 25

Anonymous
Not applicable

Thanks to all of you!!!!!!

It works! 

0 Likes
Message 18 of 25

Anonymous
Not applicable

Hi,

 

I tried to copy what you did here, but my plane stops spinning after a single revolution. I tried to change it post infinity mode to loop, but that doesn't work.

 

Thanks
Rob

 

 

0 Likes
Message 19 of 25

Christian_Garimberti
Advisor
Advisor

To run a clip on a infinite loop you have to put -1 on the cycle box in the clip panel.

Annotazione 2019-07-02 081044.png

 

Note: you can use the -1 only in recent release of Vred, but i don't remember in which version this feature it has been added.

 

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

Message 20 of 25

Anonymous
Not applicable

Thank you!

Could you also tell me how to reverse the rotation in a second switch?
Regards

Rob

0 Likes