3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

SpaceClaim Python API: Undo/Redo Operations

    • Sterling Butters
      Subscriber

      Greetings, is it possible to access undo/redo operations from the python API? The record feature does not appear to pick up on these actions and seems like to basic of a feature to not be implemented in the API. Thanks in advance!

    • mjmiddle
      Ansys Employee

      from SpaceClaim.Api.V23 import Application
      from SpaceClaim.Api.V23.Scripting.Internal import TransactionHelper
      def Undo():
          TransactionHelper.EndCommand()
          Application.Undo(1)    # number of steps to undo
          #Application.Redo(1)    # number of steps to redo
          #Application.PurgeUndo(0)    # number of steps to keep
          TransactionHelper.BeginCommand("Script")
      Undo()

      # The Undo(), Redo(), PurgeUndo() must be done within the EndCommand()/BeginCommand() block and inside a function or else the BeginCommand() cannot resume GUI operation.

    • Sterling Butters
      Subscriber

      @mjmiddle Thanks! What argument is passed to the BeginCommand method in your example i.e. what is “Script”? Is it the name of the active .scscript file? I guess more generally, what command is being “begun” after the Application.Undo(1) operation?

    • mjmiddle
      Ansys Employee

      These are unsupported commands, and I gave you a workable method to do what has not been supported or documented. Just use the BeginCommand("Script") exactly as shown, with the string "Script" as the argument. If you try use the undo command outside of the Begin/EndCommand, you'll get an error:

      Cannot undo or redo when a command is being executed.

       

      The Begin/EndCommand allows it to halt the GUI mouse/keyboard event loop to do the command and then start the event loop again. Use the script as shown or you will run into problems.

    • Sterling Butters
      Subscriber

      @mjmiddle Thanks so much again! So glad this forum exists!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.