I am teaching a 3D class and my students are still in that phase where they just can’t live without an UNDO. So, I figured, I would give it a shot.
Since edit mode has a basic kind-of undo, I thought I would just tackle object position, rotation, and scale for starters. Actually, I have begun just by working on Z location while I get the concept worked out and figure out python. So far I have the script writing the Selected Object’s LocZ to a text file and retrieving it with buttons. I figure I can get Blender to basically write a history of the objects attributes to a file and then go get the attributes when I want to go back in time. This could even remain an object specific undo History. That’s about it. Anyone care to help me out?
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
#"VirtualUndo" version A1.0
# by Michael Thoenes and
# "your name here"
#
# Thanks to: Bradley Berthold *nikolatesla20*
# for his Blender 2.14 GUI WIZARD script
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This is an experiment to create a type of UNDO
# for Blender. The script writes the Z Location
# of the selected object to a text file "Undo.txt" with a
# button press.(File currently is written in folder where
# Blender was Launched).The stored Z-Location can be retrieved
# with another button press.
#
# By the way , I have no I dea what I am doing! Please Help!
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Things to do.
#
# 1. Make the script loop so the stored value can be updated
# in the text file
# 2. Make this work for othe selected objects
# 3. Include the Loc/Rot/Size data in the List
# 4. Make the recording automatic, triggered by action on the
# Selected object perhaps
# 5. Record Multiple instances of previous object attributes
# to allow for multiple undos
# 6. Expand this beyound objects
# 7. Add file path selection for Undo.txt
# 8. Make a small unobtrusive GUI
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
###########################################################
# You need to have Object selected before you start the script
#
# Alt-P to run script, X to Exit
###########################################################
import Blender
from Blender.BGL import *
from Blender.Draw import *
# Get selected object
obj = Blender.Object.getSelected() [0]
# Converts obj.Loc to string for use in write(Zlocation)
Zlocation = repr(obj.LocZ)
# These are you button object global variables!
#Here is the main Draw() routine. All your drawing
#Should be done in this function.
def Draw():
# You must use the global keyword here to allow you to modify
# a variable outside the scope of the function.
global Button1
global Button2
# Change this color according to what you like ;)
glClearColor(0.4,0.5,0.6 ,0.0)
glClear(GL_COLOR_BUFFER_BIT)
Blender.Draw.Button("Store LocZ - writes LocZ to text file",1,40.0,50.0,300,30)
Blender.Draw.Button("Reset LocZ - Click in 3D window to update ",2,40.0,10.0,300,30)
glColor3d(0,0,0)
glRasterPos2i(40, 120)
Text("VirtualUndo Ver. A1.0 ( LocZ Undo Experiment )")
glColor3d(0,0,0)
glRasterPos2i(40, 100)
Text("Press XKEY to Exit")
# Here is the main Window Event function.
# Right now it only has a exit key defined.
def Events(eventnum,eventmod):
if eventnum==Blender.Draw.XKEY:
Blender.Draw.Exit()
# These are the button Events handlers.
def ButEvent(butnum):
if butnum==1:
# EVENT HANDLER FOR Button1
# Put your code in here to respond to the event
print "Store LocZ=", obj.LocZ
out_file = open("Undo.txt", "w")
out_file.write(Zlocation)
out_file.close
if butnum==2:
# EVENT HANDLER FOR Button2
# Put your code in here to respond to the event
in_file = open("Undo.txt", "r")
text = in_file.read()
in_file.close()
print "Reset LocZ= ", text
# Convert the variable text type string to type float
obj.LocZ = float(text)
# The Main Blender.Draw.Register() Call...
Blender.Draw.Register(Draw,Events,ButEvent)
Here’s the blend