File: cstartup.py

package info (click to toggle)
blender 2.49.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 89,664 kB
  • ctags: 113,718
  • sloc: ansic: 738,048; cpp: 231,960; python: 104,955; asm: 33,960; sh: 16,233; ml: 12,962; makefile: 4,477; perl: 3,474; fortran: 108; java: 8
file content (726 lines) | stat: -rw-r--r-- 23,638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# --------------------------------------------------------------------------
# Illusoft Collada 1.4 plugin for Blender
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2006: Illusoft - colladablender@illusoft.com
# 2008.05.08 modif. for debug mode by migius (AKA Remigiusz Fiedler)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------

debug = False #--- debug mode
debprn = False #--- print debug "print 'deb: ..."
_ERROR = False
_PERROR = False

import sys

try:
	import Blender
except NameError:
	print "Error! Could not find Blender modules!"
	_ERROR = True

__version__ = '0.3.162'

# Show the wait cursor in blender
Blender.Window.WaitCursor(1)

# indicates if the user can choose a file to import
useDefaultFile = True

defaultFileUrl = 'animation.DAE'
#defaultFileUrl = 'animation.DAE'
#defaultFileUrl = 'animated_letters.DAE'
#defaultFileUrl = 'animation_robot.DAE'
defaultExportUrl = ''

# Check if full version of python is installed.
try:
	import os
	import xml
except ImportError:
	print"Error! Could not find full version of Python..."
	_ERROR = True

if _ERROR:
	from sys import version_info
	version = '%s.%s' % version_info[0:2]
	print """
To run the collada importer and exporter you need to have
Python version %s installed in your system. It can be downloaded from:

http://www.python.org

Notes:
- The minor (third) version number doesn't matter, you can have either
Python %s.1 or %s.2 or higher.
- If you do have Python %s installed and still can't run the scripts, then
make sure Blender's Python interpreter is finding the standalone modules
(run 'System Information' from Blender's Help -> System menu).
""" % (version, version, version, version)
	Blender.Draw.PupMenu("Please install full version of python %t | Check the console for more info")
	raise StandardError()
else:

	# Try to load the Plugin modules
	try:
		import cutils
	except NameError:
		print "\nError! Could not find Collada Utils (cutils) module!"
		_ERROR = True

	try:
		import xmlUtils
	except NameError:
		print "\nError! Could not find XML module!"
		_PERROR = True

	try:
		import collada
	except NameError:
		print "Error! Could not find Collada(collada.py) module"
		_PERROR = True

	try:
		import translator
	except NameError:
		print "Error! Could not find Collada Translator (translator.py) module"
		_PERROR = True

	try:
		import helperObjects
	except NameError:
		print "Error! Could not find Collada helperObjects (helperObjects.py) module"
		_PERROR = True

	# Try to load extra python modules
	try:
		import math
	except NameError:
		print "Error! Could not find math module"
		_PERROR = True

	if _PERROR:
		Blender.Draw.PupMenu("Cannot load plugin modules.")
	else:
		# A List with al the modules (in the scriptsdir) to be reloaded
		modules = [cutils, xmlUtils, collada, helperObjects, translator]


def Main(doImp, scriptsLoc):
	global debug, __version__, doImport, scriptsLocation, defaultFilename, valsLoaded
	if _ERROR or _PERROR:
		return
	valsLoaded = False

	doImport = doImp
	if scriptsLoc == "":
		scriptsLoc = Blender.Get('scriptsdir')
		if not scriptsLoc: scriptsLoc = Blender.Get('uscriptsdir')
		if scriptsLoc:
			scriptsLocation = scriptsLoc+Blender.sys.sep+'bpymodules'+Blender.sys.sep+'colladaImEx'+Blender.sys.sep
		else:
			print 'Could not find a scripts path'
	else:
		scriptsLocation = scriptsLoc


	if not ReloadModules():
		print 'cannot reload all modules'
		return False
	# Clear the console
	cutils.ClearConsole()

	# set the debuglevel
	if debug:
		cutils.Debug.SetLevel('DEBUG')
	else:
		cutils.Debug.SetLevel('FEEDBACK')

	cutils.Debug.Debug('Illusoft Collada 1.4 Plugin v%s started'%(__version__),'FEEDBACK')
	# Create a Collada <-> Blender Translator
	if debug:
		print 'keep track of the time to execute this script' #---------
		startTime = Blender.sys.time()

		##fileurl = scriptsDir
		fileurl = ''
		if doImport:
			fileurl+= defaultFileUrl
		else :
			fileurl += defaultExportUrl
		if debprn: print 'deb: fileurl=',fileurl #-------

		useTriangles = False
		usePolygons = False
		bakeMatrices = False
		exportSelection = False
		newScene = True
		clearScene = False
		lookAt = False
		usePhysics = True
		exportCurrentScene = False
		exportRelativePaths = False
		useUV = False
		sampleAnimation = False
		onlyMainScene = False

		transl = translator.Translator(doImport,__version__,debug,fileurl, useTriangles, usePolygons, bakeMatrices, exportSelection, newScene, clearScene, lookAt, usePhysics, exportCurrentScene, exportRelativePaths, useUV, sampleAnimation, onlyMainScene)

		##transl = translator.Translator(doImport,__version__,debug,fileurl)
		##translator = Translator(False,__version__,debug,scriptsDir+defaultExportUrl)
		##translator = Translator(True,__version__,debug,scriptsDir+defaultExportUrl)
		# Redraw al 3D windows.
		if debprn: print 'deb: ---- the end ----' #-----
		Blender.Window.RedrawAll()

		# calculate the elapsed time
		endTime = Blender.sys.time()
		elapsedTime = endTime - startTime
		cutils.Debug.Debug('FINISHED - time elapsed: %.1f'%(elapsedTime),'FEEDBACK')

		# Hide the wait cursor in blender
		Blender.Window.WaitCursor(0)
	else:
		defFilename = Blender.sys.dirname(Blender.sys.progname)+Blender.sys.sep
		colladaReg = Blender.Registry.GetKey('collada',True)

		if not (colladaReg is None) and 'path' in colladaReg and Blender.sys.exists(colladaReg['path']):
			defFilename = colladaReg['path']
		elif not (doImport):
			defFilename += 'untitled.dae'

		defaultFilename = defFilename

		Blender.Draw.Register(Gui, Event, ButtonEvent)	# registering the 3 callbacks

def ReloadModules():
	# Loop through all the modules and try to reload them
	for module in modules:
		try:
			reload(module)
		except NameError:
			cutils.Debug.Debug('cannot reload module %s' %(module),'ERROR')
			return False
	return True

def FileSelected(fileName):
	global doImport, fileButton

	if fileName != '':
		# check if file exists
		if Blender.sys.exists(fileName) != 1 and doImport:
			cutils.Debug.Debug('File(%s) does not exist' % (fileName),'ERROR')
			return False

		# must the file to import end with .dae or .xml?
##		  if doImport:
##			  # Check if the file has a valid extension .DAE or .XML
##			  extension = fileName.rsplit('.',1)[1].lower()
##			  if extension != 'xml' and extension != 'dae':
##				  cutils.Debug.Debug('File(%s) is not a .dae or .xml file' % (fileName),'ERROR')
		fileButton.val = fileName
		##transl = translator.Translator(doImport,__version__,debug,fileName)
	else:
		cutils.Debug.Debug('ERROR: filename is empty','ERROR')

toggle = 0
fileButton = None
toggleTriangles = None
togglePolygons = None
toggleExportSelection = None
toggleClearScene = None
toggleNewScene = None
toggleBakeMatrix = None
toggleSampleAnimation = None
toggleLookAt = None
togglePhysics = None
toggleExportCurrentScene = None
toggleExportRelativePaths = None
toggleUseUV = None
toggleSampleAnimation = None
toggleOnlyMainScene = None
toggleApplyModifiers = None

def LoadDefaultVals():
	global toggleLookAt, toggleBakeMatrix, toggleSampleAnimation, toggleNewScene, \
	toggleClearScene, toggleTriangles, togglePolygons, toggleExportSelection, \
	scriptsLocation, doImport, defaultFilename, fileButton, valsLoaded, \
	togglePhysics, toggleExportCurrentScene, toggleExportRelativePaths, \
	toggleUseUV, toggleOnlyMainScene, toggleApplyModifiers

	if valsLoaded:
		return None

	colladaReg = Blender.Registry.GetKey('collada',True)
	if not (colladaReg is None):
		fileButton.val = colladaReg.get('path', '')
		fileParts = []
		filePath = "";
		fileParts = fileButton.val.split("\\");
		partCount = len(fileParts);
		if partCount > 0 :
			for i in range(partCount):
				if i == 0:
					filePath = fileParts[i];
				else :
					if i != partCount - 1:
						filePath = filePath + "\\" + fileParts[i];
					else:
						filePath = filePath + "\\";

		blenderFilename = Blender.Get('filename');
		fileParts = []
		fileParts = blenderFilename.split("\\");
		partCount = len(fileParts);
		if partCount > 0 :
			blenderFileOnlyName = fileParts[partCount -1];
			blenderFileOnlyName = blenderFileOnlyName.replace(".blend", ".dae");
			filePath = filePath + blenderFileOnlyName;
		else :
			filePath = filePath + "untitled.dae";


		if len(filePath) > 0 :
			fileButton.val = filePath;

		if doImport:
			toggleOnlyMainScene.val = colladaReg.get('onlyMainScene', False)
			toggleNewScene.val = colladaReg.get('newScene', False)
			toggleClearScene.val = colladaReg.get('clearScene', False)
		else:
			##toggleLookAt.val = colladaReg.get('lookAt', False)
			toggleBakeMatrix.val = colladaReg.get('bakeMatrices', False)
			toggleTriangles.val = colladaReg.get('useTriangles', False)
			togglePolygons.val = colladaReg.get('usePolygons', False)
			toggleExportSelection.val = colladaReg.get('exportSelection', False)
			togglePhysics.val = not colladaReg.get('usePhysics', True)
			toggleExportCurrentScene.val = colladaReg.get('exportCurrentScene', False)
			toggleExportRelativePaths.val = colladaReg.get('exportRelativePaths', True)
			toggleSampleAnimation.val = colladaReg.get('sampleAnimation', False)
			toggleUseUV.val = colladaReg.get('useUV', False)
			#TODO: "toggleOnlyMainScene" left out intentionally by the original plugin author?
			toggleApplyModifiers.val = colladaReg.get('applyModifiers', True)
	valsLoaded = True

def Gui():
	global toggleLookAt, toggleBakeMatrix, toggleSampleAnimation, toggleNewScene, \
	toggleClearScene, toggleTriangles, togglePolygons, toggleExportSelection, \
	scriptsLocation, doImport, defaultFilename, fileButton, togglePhysics, \
	toggleExportCurrentScene, toggleExportRelativePaths, toggleUseUV, \
	toggleOnlyMainScene, toggleApplyModifiers
	
	Blender.BGL.glClearColor(0.898,0.910,0.808,1) # Set BG Color1
	Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)
	Blender.BGL.glColor3f(0.835,0.848,0.745) # BG Color 2
	size = Blender.Window.GetAreaSize()
	Blender.BGL.glRectd(40,0,200,size[1])
	try:
		logoImage = Blender.Image.Load(scriptsLocation + 'logo.png')
		Blender.BGL.glEnable(Blender.BGL.GL_BLEND ) # Only needed for alpha blending images with background.
		Blender.BGL.glBlendFunc(Blender.BGL.GL_SRC_ALPHA, Blender.BGL.GL_ONE_MINUS_SRC_ALPHA)
		try:		Blender.Draw.Image(logoImage, 45, size[1]-30)
		except:		pass
		Blender.BGL.glDisable(Blender.BGL.GL_BLEND)
	except IOError: # image not found
		Blender.BGL.glColor3i(0.255,0.255,0.2)
		Blender.BGL.glRasterPos2i(45, size[1]-30)
		Blender.Draw.Text("Collada 1.4.0 Plugin for Blender", "large")

	Blender.BGL.glColor3f(0.255,0.255,0.2)
	Blender.BGL.glRasterPos2i(45, size[1]-40)
	Blender.Draw.Text("Version: %s"%(__version__),"small")

	# Write donation text
	donateText1 = "If this plugin is valuable to you or your company, please consider a donation at"
	donateText2 = "http://colladablender.illusoft.com to support this plugin. Thanks a lot!"
	Blender.BGL.glRasterPos2i(45, size[1]-60)
	Blender.Draw.Text(donateText1, "small")
	Blender.BGL.glRasterPos2i(45, size[1]-70)
	Blender.Draw.Text(donateText2, "small")

	# Write import / export text
	Blender.BGL.glColor3f(0.9,0.08,0.08)
	Blender.BGL.glRasterPos2i(45, size[1]-95)
	if doImport:
		importExportText = "Import"
	else:
		importExportText = "Export"
	Blender.Draw.Text(importExportText, "normal")

	Blender.BGL.glColor3f(0.255,0.255,0.2)

	# Create File path input
	yval = size[1]-130
	Blender.BGL.glRasterPos2i(45, yval)
	if fileButton is None or fileButton.val == '':
		fileName = defaultFilename
	else:
		fileName = fileButton.val
	Blender.Draw.Text('%s file:'%(importExportText),"normal")
	maxWidth = 400
	if size[0] - (105 + 35) > maxWidth:
		fileWidth = maxWidth
	else:
		fileWidth = size[0] - (105 + 35)
	fileButton = Blender.Draw.String('', 5, 105, yval-5, fileWidth, 20, fileName, 255)
	Blender.Draw.PushButton('...', 2, 105 + fileWidth, yval-5, 30, 20, 'browse file')

	Blender.Draw.PushButton("Cancel", 3, 45, 10, 55, 20, "Cancel")
	Blender.Draw.PushButton(importExportText + ' and Close', 4, 45+55+35, 10, 100, 20, importExportText + ' and close this screen')

	# Create Export Options:
	if not doImport:
		yval = yval - 50
		# Create Triangle / Polygons Options
		if not (toggleTriangles is None):
			toggleTrianglesVal = toggleTriangles.val
		else:
			toggleTrianglesVal = 0

		if not (togglePolygons is None):
			togglePolygonsVal = togglePolygons.val
		else:
			togglePolygonsVal = 0

		toggleTriangles = Blender.Draw.Toggle('Triangles',6,45, yval, 60, 20, toggleTrianglesVal, 'Export all geometry as triangles')
		togglePolygons = Blender.Draw.Toggle('Polygons',7,45+60 + 30, yval, 60, 20, togglePolygonsVal, 'Export all geometry as polygons')

		yval = yval - 40
		# Create Export Selection Option
		if not (toggleExportSelection is None):
			toggleExportSelectionVal = toggleExportSelection.val
		else:
			toggleExportSelectionVal = 0

		toggleExportSelection = Blender.Draw.Toggle('Only Export Selection',8,45, yval, 150, 20, toggleExportSelectionVal, 'Only export selected objects')

		yval = yval - 40
		# Create Bake Matrix Option
		if not (toggleBakeMatrix is None):
			toggleBakeMatrixVal = toggleBakeMatrix.val
		else:
			toggleBakeMatrixVal = 0

		toggleBakeMatrix = Blender.Draw.Toggle('Bake Matrices',11,45, yval, 150, 20, toggleBakeMatrixVal, 'Put all transformations in a single matrix')

		yval = yval - 40
		# Create Sample Anim
		if not (toggleSampleAnimation is None):
			toggleSampleAnimationVal = toggleSampleAnimation.val
		else:
			toggleSampleAnimationVal = 0

		toggleSampleAnimation = Blender.Draw.Toggle('Sample Animation',16,45, yval, 150, 20, toggleSampleAnimationVal, 'Export information for every frame of animation.')


		yval = yval - 40
		#Create Physics Option
		if not (togglePhysics is None):
			togglePhysicsVal = togglePhysics.val
		else:
			togglePhysicsVal = 0

		togglePhysics = Blender.Draw.Toggle('Disable Physics',13,45, yval, 150, 20, togglePhysicsVal, 'Disable Export physics information')


		yval = yval - 40
		#Create Physics Option
		if not (toggleExportCurrentScene is None):
			toggleExportCurrentSceneVal = toggleExportCurrentScene.val
		else:
			toggleExportCurrentSceneVal = 0

		toggleExportCurrentScene = Blender.Draw.Toggle('Only Current Scene',14,45, yval, 150, 20, toggleExportCurrentSceneVal, 'Only Export the current scene')

		yval = yval - 40
		#Create Relative Path's Option
		if not (toggleExportRelativePaths is None):
			toggleExportRelativePathsVal = toggleExportRelativePaths.val
		else:
			toggleExportRelativePathsVal = 0

		toggleExportRelativePaths = Blender.Draw.Toggle('Use Relative Paths',15,45, yval, 150, 20, toggleExportRelativePathsVal, 'Export paths relative to the collada file')

		yval = yval - 40
		#Create Relative Path's Option
		if not (toggleUseUV is None):
			toggleUseUVVal = toggleUseUV.val
		else:
			toggleUseUVVal = 0

		toggleUseUV = Blender.Draw.Toggle('Use UV Image Mats',15,45, yval, 150, 20, toggleUseUVVal, 'Use UV Image instead of the material textures. Use this if you did not use the Material Textures window. Note: If you reimport this file, they will have moved to the materials section!!')

		##yval = yval - 40
		# Create Lookat  Option
		if not (toggleLookAt is None):
			toggleLookAtVal = toggleLookAt.val
		else:
			toggleLookAtVal = 0

		##toggleLookAt = Blender.Draw.Toggle('Camera as Lookat',14,45, yval, 150, 20, toggleLookAtVal, 'Export the transformation of camera\'s as lookat')
		
		yval = yval - 40
		if not (toggleApplyModifiers is None):
			toggleApplyModifiersVal = toggleApplyModifiers.val
		else:
			toggleApplyModifiersVal = 0
		
		toggleApplyModifiers = Blender.Draw.Toggle('Apply modifiers',14,45, yval, 150, 20, toggleApplyModifiersVal, 'Apply modifiers, like mirroring, transformations, etc.')

		Blender.Draw.PushButton(importExportText, 12, 45+55+35+100+35, 10, 55, 20, importExportText)
	else: # IMPORT GUI
		yval = yval - 50
		# Create Import To new Scene Options
		if not (toggleNewScene is None):
			toggleNewSceneVal = toggleNewScene.val
		else:
			toggleNewSceneVal = 0

		if not (toggleClearScene is None):
			toggleClearSceneVal = toggleClearScene.val
		else:
			toggleClearSceneVal = 0

		if not (toggleOnlyMainScene is None):
			toggleOnlyMainSceneVal = toggleOnlyMainScene.val
		else:
			toggleOnlyMainSceneVal = 0

		if toggleOnlyMainSceneVal == 0:
			if toggleClearSceneVal == 0 and toggleNewSceneVal == 0:
				toggleNewSceneVal = 1

		newSceneText = 'Import file into a new Scene';
		newSceneTitle = 'New Scene'
		clearSceneText = 'Clear everything on the current scene'
		clearSceneTitle = 'Clear Scene'
		if toggleOnlyMainSceneVal == 0:
			newSceneText = 'Import file into a new Scenes'
			newSceneTitle = 'New Scenes'
			clearSceneText = 'Delete all the Blender Scenes'
			clearSceneTitle = 'Delete Scenes'
		toggleOnlyMainScene = Blender.Draw.Toggle('Only Import Main Scene',17,40, yval, 190, 20, toggleOnlyMainSceneVal, 'Only import the main scene from Collada')
		yval = yval - 40
		toggleNewScene = Blender.Draw.Toggle(newSceneTitle,9,40, yval, 90, 20, toggleNewSceneVal, newSceneText)
		toggleClearScene = Blender.Draw.Toggle(clearSceneTitle,10,40+90 + 10, yval, 90, 20, toggleClearSceneVal, clearSceneText)

	LoadDefaultVals()

def CalcElapsedTime(startTime):
	'''
	Calc elapsed time between now and start time.
	'''	
	return Blender.sys.time() - startTime	

def Event(evt, val):
	pass

def ButtonEvent(evt):
	global toggleLookAt, toggleBakeMatrix, toggleExportSelection,toggleNewScene, \
	toggleClearScene, toggleTriangles, togglePolygons, doImport, defaultFilename, \
	fileSelectorShown, fileButton, valsLoaded, togglePhysics, \
	toggleExportCurrentScene, toggleExportRelativePaths, toggleUseUV, \
	toggleSampleAnimation, toggleOnlyMainScene
	
	checkImportButtons = False
	if evt == 1:
		toggle = 1 - toggle
		Blender.Draw.Redraw(1)
	elif evt == 2: # browse file
		browseText = ''
		if doImport:
			browseText = 'Import .dae'
		else:
			browseText = 'Export .dae'
		Blender.Window.FileSelector(FileSelected,browseText,defaultFilename)
		Blender.Draw.Redraw(1)
	elif evt == 3:
		Blender.Draw.Exit()
	elif evt == 4 or evt == 12: # Ok, time to export/import
		#keep track of the time to execute this script
		startTime = Blender.sys.time()
		fileName = fileButton.val
		dirName = Blender.sys.dirname(fileName) + Blender.sys.sep
		exists = Blender.sys.exists(fileName)
		if exists == 1 and not doImport:
			overwrite = Blender.Draw.PupMenu( "File Already Exists, Overwrite?%t|Yes%x1|No%x0" )
			if not overwrite == 1:
				return False
		elif exists != 1 and doImport:
			Blender.Draw.PupMenu("File does not exist: %t|"+fileName)
			cutils.Debug.Debug('File(%s) does not exist' % (fileName),'ERROR')
			return False
		elif not Blender.sys.exists(dirName):
			Blender.Draw.PupMenu("Path is not valid: %t|"+dirName)
			cutils.Debug.Debug('Path is not valid: %s' % (dirName),'ERROR')
			return False

		if toggleTriangles is None:
			useTriangles = False
		else:
			useTriangles = bool(toggleTriangles.val)

		if togglePolygons is None:
			usePolygons = False
		else:
			usePolygons = bool(togglePolygons.val)

		if toggleBakeMatrix is None:
			bakeMatrices = False
		else:
			bakeMatrices = bool(toggleBakeMatrix.val)

		if toggleExportSelection is None:
			exportSelection = False
		else:
			exportSelection = bool(toggleExportSelection.val)

		if toggleNewScene is None:
			newScene = False
		else:
			newScene = bool(toggleNewScene.val)

		if toggleClearScene is None:
			clearScene = False
		else:
			clearScene = bool(toggleClearScene.val)

		if toggleOnlyMainScene is None:
			onlyMainScene = False
		else:
			onlyMainScene = bool(toggleOnlyMainScene.val)

		if toggleLookAt is None:
			lookAt = False
		else:
			lookAt = bool(toggleLookAt.val)

		if togglePhysics is None:
			usePhysics = True
		else:
			usePhysics = not bool(togglePhysics.val)

		if toggleExportCurrentScene is None:
			exportCurrentScene = False
		else:
			exportCurrentScene = bool(toggleExportCurrentScene.val)

		if toggleExportRelativePaths is None:
			exportRelativePaths = False
		else:
			exportRelativePaths = bool(toggleExportRelativePaths.val)

		if toggleUseUV is None:
			useUV = False
		else:
			useUV = bool(toggleUseUV.val)

		if toggleSampleAnimation is None:
			sampleAnimation = False
		else:
			sampleAnimation = bool(toggleSampleAnimation.val)
			
		if toggleApplyModifiers is None:
			applyModifiers = False
		else:
			applyModifiers = bool(toggleApplyModifiers.val)


		d = Blender.Registry.GetKey('collada',True)
		if d is None:
			d = dict()
		d['path'] = fileName

		if doImport:
			d['newScene'] = newScene
			d['clearScene'] = clearScene
			d['onlyMainScene'] = onlyMainScene
		else:
			d['useTriangles'] = useTriangles
			d['usePolygons'] = usePolygons
			d['bakeMatrices'] = bakeMatrices
			d['exportSelection'] = exportSelection
			d['lookAt'] = lookAt
			d['usePhysics'] = usePhysics
			d['exportCurrentScene'] = exportCurrentScene
			d['exportRelativePaths'] = exportRelativePaths
			d['useUV'] = useUV
			d['sampleAnimation'] = sampleAnimation
			d['applyModifiers'] = applyModifiers

		Blender.Registry.SetKey('collada',d, True)

		if doImport:
			importExportText = "Import"
		else:
			importExportText = "Export"

		try:
			transl = translator.Translator(doImport,__version__,debug,fileName, \
										useTriangles, usePolygons, bakeMatrices,\
										exportSelection, newScene, clearScene,  \
										lookAt, usePhysics, exportCurrentScene, \
										exportRelativePaths, useUV, sampleAnimation, \
										onlyMainScene, applyModifiers)
			
			cutils.Debug.Debug('Time to process and save data: %.1f' \
							% CalcElapsedTime(startTime), 'FEEDBACK')
			
			# Redraw all 3D windows.
			Blender.Window.RedrawAll()
			
			Blender.Draw.PupMenu(importExportText + " Successful %t")
		except:						
			Blender.Draw.PupMenu(importExportText + "ing failed%t | Check the console for more info")
			raise # throw the exception

		cutils.Debug.Debug('FINISHED - time elapsed: %.1f' % CalcElapsedTime(startTime), \
						'FEEDBACK')

		# Hide the wait cursor in blender
		Blender.Window.WaitCursor(0)
		if evt == 4:
			Blender.Draw.Exit()
		valsLoaded = False
	elif evt == 6: # Toggle Triangles
		if toggleTriangles.val:
			togglePolygons.val = 0
		Blender.Draw.Redraw(1)
	elif evt == 7: # Toggle Polygons
		if togglePolygons.val:
			toggleTriangles.val = 0
		Blender.Draw.Redraw(1)
	elif evt == 9: # Toggle Create new Scene
		if toggleNewScene.val:
			toggleClearScene.val = 0
		checkImportButtons = True
	elif evt == 10: # Toggle Clear current Scene
		if toggleClearScene.val:
			toggleNewScene.val = 0
		checkImportButtons = True
	elif evt == 17: # Toggle Only Main Scene
		checkImportButtons = True


	if checkImportButtons:
		if not toggleOnlyMainScene.val:
			if not toggleClearScene.val and not toggleNewScene.val:
				toggleNewScene.val = True
		Blender.Draw.Redraw(1)