View Single Post
  #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