WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 10 votes, 5.00 average. Display Modes
  #1  
Old 08-30-2013, 08:32 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
In the future, you might want to look at using the cPickle module for storing objects (lists, numbers, dictionaries, pretty much anything) in a text file and retrieving the same objects later on.

Here is an example where the rotation of the mainview of Vizard is stored in a text file (by pressing the d-key) and read from that file (by pressing the r-key):
Code:
import viz
import cPickle

viz.go()

def writeInfo():
	orientation = viz.MainView.getEuler()
	file_rot = open('MainView_rot.txt', 'w+')
	cPickle.dump(orientation, file_rot)
	file_rot.flush()
	file_rot.close()
	print 'Succesfully pickled:', orientation

def readInfo():
	try:
		file_rot = open('MainView_rot.txt', 'r')
		orientation = cPickle.load(file_rot)
		file_rot.flush()
		file_rot.close()
		print 'Succesfully unpickled:', orientation
	except IOError:
		print 'Could not read file!'
	
def onKeyDown(key):
	if key in 'dD':
		writeInfo()
	elif key in 'rR':
		readInfo()
	else:
		pass
	
viz.callback(viz.KEYDOWN_EVENT, onKeyDown)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
writing joystick position to a data file Saz Vizard 3 12-17-2008 05:18 AM
String within a string problem? Elittdogg Vizard 1 08-29-2008 01:35 PM


All times are GMT -7. The time now is 07:28 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC