Start a new topic

Reset the loaded scene in python SDK

I build python SDK with Vortex studio.

I wonder there is any function or class to reset the loaded scene to initial state after some task.

1 Comment

Hi Bukun Son,


It can be done using the Key frame API. The key frame API is documented in the Vortex Documentation here.

https://www.cm-labs.com/vortexstudiodocumentation/Vortex_User_Documentation/Content/VortexStudioSDK/SDK_key_frames.html?Highlight=key%20frame


The documentation covers the C++ API so I am providing a code sample on how to use it with a python application. Note that the API is asynchronous and commands may not update the data structure right away.


#imports

from VxSim import*

#utility to run until a certain condition was reached
def runUntil(application, maxSteps, condition, x):
        steps = maxSteps
        while steps > 0 and condition(x) == False:
            application.update()
            steps = steps-1
...
...

# Application creation
application = VxApplication()            

# Get the key frame manager
keyFramesMgr = application.getContext().getKeyFrameManager()

# create a key frame list
# List works by name. 
keyFrameList = keyFramesMgr.createKeyFrameList("MyList", False)

# It can take a few updates to create the list
runUntil(application, 100, lambda keyFrameList: KeyFrameList.kInitialized == keyFrameList.getStatus(), keyFrameList)

# Load the scene and get to the point you want to return to
...

# Save a keyframe, simulation can be restored to that point
keyFrameId = keyFrameList.saveKeyFrame()

# The key frame will be saved, but it may take a few update to show up in the list
# This shouldn't be an issue as an application is typically running
# Should you need the key frame before it's ready, it's possible to wait for it
runUntil(application, 100, lambda keyFrameList: 1 == len(keyFrameList.getKeyFrames()), keyFrameList)

# Run the application and do some tasks
...

# Now that what was needed it done, you can return the simulation to a previous saved frame
keyFrameList.restore(KeyFrame(keyFrameId ))

# You are now back to the restored point
....

Hope this helps.

Regards,


Nicolas


Login to post a comment