WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-14-2014, 07:07 AM
BSUGeek BSUGeek is offline
Member
 
Join Date: Oct 2014
Posts: 23
Question Help Printing to Different files

My scene is with an avatar out of view and he's walking around the room. When he walks into view I want my code to print his coordinates once to an xml file. When he's in view again I want to print his coordinates once to a separate xml file...etc, etc.

I'm having trouble getting the code to print to separate xml files while he's in view. any help would be greatly appreciated! below is my snippet of code.

Code:
#Checks If Avatar is visible
def dostuff():
	num = 1
	while(viz.MainWindow.isCulled(avatar, eye = viz.LEFT_EYE)==0):
			elapsed_time = viz.tick() - start_time
			x_pos = avatar.getPosition()[0]
			y_pos = avatar.getPosition()[1]
			z_pos = avatar.getPosition()[2]
			
		#Make a string out of the data. 
			dataTag1 = '<position>'
			XPosition = 'x position:  ' + str(round(x_pos))
			YPosition = '  y position:  ' + str(y_pos)
			ZPosition = '  z position:  ' + str(z_pos)
			dataTag2 = '</position>\n'
			dataTime1 = '<time>'
			time = str(round(elapsed_time))
			dataTime2 = '</time>\n'
			question_data = open('VRProject'+str(num)+'.xml','w')
			num = num + 1
			
			#Write the data to our file.
			question_data.write(declaration)
			question_data.write(dataTag1) 
			question_data.write(XPosition) 
			question_data.write(YPosition) 
			question_data.write(ZPosition) 
			question_data.write(dataTag2) 
			question_data.write(dataTime1) 
			question_data.write(time) 
			question_data.write(dataTime2)
			question_data.write(enddeclaration)
					
			#Flush the internal buffer.
			question_data.close()
	
vizact.ontimer(1,dostuff)
Reply With Quote
  #2  
Old 10-14-2014, 09:37 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Not sure what seem to be the problem, but I noticed that you want to write declaration to the question_data file. However, I don't see any variable called declaration. Furthermore, the write command is capable of writing multiple lines at the same time, so it would be more efficient to create one string, and writing that one string with a write statement.

Could you clarify what exactly seems to be the problem? Have you tried writing simple information to a .txt file instead of an .xml? I know they are basically the same, but I don't know of the write command handles .xml files well. Furthermore, the program could get stuck in a loop with the while command. Replace the while loop with an if statement. If that does not solve your problem, please specify your problem.
Reply With Quote
  #3  
Old 10-14-2014, 01:15 PM
BSUGeek BSUGeek is offline
Member
 
Join Date: Oct 2014
Posts: 23
Quote:
Originally Posted by Frank Verberne View Post
Not sure what seem to be the problem, but I noticed that you want to write declaration to the question_data file. However, I don't see any variable called declaration. Furthermore, the write command is capable of writing multiple lines at the same time, so it would be more efficient to create one string, and writing that one string with a write statement.

Could you clarify what exactly seems to be the problem? Have you tried writing simple information to a .txt file instead of an .xml? I know they are basically the same, but I don't know of the write command handles .xml files well. Furthermore, the program could get stuck in a loop with the while command. Replace the while loop with an if statement. If that does not solve your problem, please specify your problem.
Here's my full code. Right now when it runs it's making separate xml files for every second the avatar is in view. What i'm trying to do is everytime the avatar walks into view I want to write the coordinates to separate xml files but only once each time he's in view. and If a new avatar comes into view I want to it make another xml file. if that makes any sense...

Code:
import viz
import vizact
import vizshape
import vizproximity
import viztask

viz.setMultiSample(4)
viz.fov(60)
viz.go()

viz.MainView.move([0,0,-1])

#Create skylight
viz.MainView.getHeadLight().disable()
sky_light = viz.addLight(euler=(0,90,0))
sky_light.position(0,0,-1,0)
sky_light.color(viz.WHITE)
sky_light.ambient([0.9,0.9,1])

#Add the gallery model
gallery = viz.addChild('gallery.osgb')
#floor = viz.add('ground.osgb')

#Mark the time that the program was started.
start_time = viz.tick()

avatar = viz.addAvatar('vcc_male2.cfg',pos=[-2,0,0])
avatar.state(1)
#Create static drop shadow to avatar
shadow_texture = viz.addTexture('shadow.png')
shadow = vizshape.addQuad(parent=avatar,axis=vizshape.AXIS_Y)
shadow.texture(shadow_texture)
shadow.zoffset()

#Move avatar around the room with a sequence of walk, turn, and wait actions
#Create action to wait 10-15 seconds
RandomWait = vizact.waittime(vizact.randfloat(5,10))

#A list of painting locations
avatarMove = [[-3.7,6.5,270],[0,8,0],[3.7,6.5,90],[3.7,2.6,90],[3.7,1,130]]
actions = []
for loc in avatarMove:
    #Add an action to walk to the next painting, turn towards it, and wait a few seconds
    actions.append(vizact.method.playsound('footsteps.wav',viz.LOOP))
    actions.append(vizact.walkTo([loc[0],0,loc[1]],turnSpeed=250.0))
    actions.append(vizact.method.playsound('footsteps.wav',viz.STOP))
    actions.append(vizact.turn(loc[2],250.0))
    actions.append(RandomWait)

#Repeat the sequence of actions forever
avatar.addAction(vizact.sequence(actions,viz.FOREVER))

#Open a file to collect the data on this subject.
#The 'a' here means that we will be appending our new
#data to the existing data in this file.

#Checks If Avatar is visible
def dostuff():
	if (viz.MainWindow.isCulled(avatar, eye = viz.LEFT_EYE)==0):
		elapsed_time = viz.tick() - start_time
		x_pos = avatar.getPosition()[0]
		y_pos = avatar.getPosition()[1]
		z_pos = avatar.getPosition()[2]
				
		#Make a string out of the data. 
		declaration = '<inform sender = "VR" receiver = "Anamoly Alert System" Format = "xml" reply_with = "Anamoly Detected!" in_response_to = "Anamoly Alert" >\n'
		dataTag1 = '<position>'
		XPosition = 'x position:  ' + str(round(x_pos))
		YPosition = '  y position:  ' + str(y_pos)
		ZPosition = '  z position:  ' + str(z_pos)
		dataTag2 = '</position>\n'
		dataTime1 = '<time>'
		time = str(round(elapsed_time))
		dataTime2 = '</time>\n'
		enddeclaration = '</inform>'
			
		print 'I See You'
		num = viz.tick()
		question_data = open('VRProject'+str(round(num))+'.xml','a')
				
		#Write the data to our file.
		question_data.write(declaration)
		question_data.write(dataTag1) 
		question_data.write(XPosition) 
		question_data.write(YPosition) 
		question_data.write(ZPosition) 
		question_data.write(dataTag2) 
		question_data.write(dataTime1) 
		question_data.write(time) 
		question_data.write(dataTime2)
		question_data.write(enddeclaration)
						
		#Flush the internal buffer.
		question_data.close()
		#while(viz.MainWindow.isCulled(avatar, eye = viz.LEFT_EYE)==0):

vizact.ontimer(1,dostuff)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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
How are files associated/how should they be saved (python script + images) mhead10 Vizard 1 03-26-2012 10:58 AM
How to edit the skin tones of the complete characters' cfg files? vEsotu Vizard 3 09-23-2008 12:07 PM
Which software can be used to edit .cfg (CAL3D) files luakt Vizard 4 09-12-2008 07:18 AM
loading large wav files in vizard tommahhh Vizard 1 05-16-2005 03:23 PM
Including Files that Include Other Files vjosh Vizard 1 09-21-2004 04:44 PM


All times are GMT -7. The time now is 12:45 PM.


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