Example #1
0
def main():

    # This is to set the position if the popup
    GLOBALS['MOUSE'] = Window.GetMouseCoords()

    # hack so the toggle buttons redraw. this is not nice at all
    while GLOBALS['EVENT'] == EVENT_REDRAW:
        Draw.UIBlock(terain_clamp_ui, 0)
Example #2
0
def load_obj_ui(filepath, BATCH_LOAD=False):
    if BPyMessages.Error_NoFile(filepath):
        return

    global CREATE_SMOOTH_GROUPS, CREATE_FGONS, CREATE_EDGES, SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, CLAMP_SIZE, IMAGE_SEARCH, POLYGROUPS, KEEP_VERT_ORDER, ROTATE_X90

    CREATE_SMOOTH_GROUPS = Draw.Create(0)
    CREATE_FGONS = Draw.Create(1)
    CREATE_EDGES = Draw.Create(1)
    SPLIT_OBJECTS = Draw.Create(0)
    SPLIT_GROUPS = Draw.Create(0)
    SPLIT_MATERIALS = Draw.Create(0)
    CLAMP_SIZE = Draw.Create(10.0)
    IMAGE_SEARCH = Draw.Create(1)
    POLYGROUPS = Draw.Create(0)
    KEEP_VERT_ORDER = Draw.Create(1)
    ROTATE_X90 = Draw.Create(1)

    # Get USER Options
    # Note, Works but not pretty, instead use a more complicated GUI
    '''
	pup_block= [\
	'Import...',\
	('Smooth Groups', CREATE_SMOOTH_GROUPS, 'Surround smooth groups by sharp edges'),\
	('Create FGons', CREATE_FGONS, 'Import faces with more then 4 verts as fgons.'),\
	('Lines', CREATE_EDGES, 'Import lines and faces with 2 verts as edges'),\
	'Separate objects from obj...',\
	('Object', SPLIT_OBJECTS, 'Import OBJ Objects into Blender Objects'),\
	('Group', SPLIT_GROUPS, 'Import OBJ Groups into Blender Objects'),\
	('Material', SPLIT_MATERIALS, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)'),\
	'Options...',\
	('Keep Vert Order', KEEP_VERT_ORDER, 'Keep vert and face order, disables some other options.'),\
	('Clamp Scale:', CLAMP_SIZE, 0.0, 1000.0, 'Clamp the size to this maximum (Zero to Disable)'),\
	('Image Search', IMAGE_SEARCH, 'Search subdirs for any assosiated images (Warning, may be slow)'),\
	]
	
	if not Draw.PupBlock('Import OBJ...', pup_block):
		return
	
	if KEEP_VERT_ORDER.val:
		SPLIT_OBJECTS.val = False
		SPLIT_GROUPS.val = False
		SPLIT_MATERIALS.val = False
	'''

    # BEGIN ALTERNATIVE UI *******************
    if True:

        EVENT_NONE = 0
        EVENT_EXIT = 1
        EVENT_REDRAW = 2
        EVENT_IMPORT = 3

        GLOBALS = {}
        GLOBALS['EVENT'] = EVENT_REDRAW
        #GLOBALS['MOUSE'] = Window.GetMouseCoords()
        GLOBALS['MOUSE'] = [i / 2 for i in Window.GetScreenSize()]

        def obj_ui_set_event(e, v):
            GLOBALS['EVENT'] = e

        def do_split(e, v):
            global SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, KEEP_VERT_ORDER, POLYGROUPS
            if SPLIT_OBJECTS.val or SPLIT_GROUPS.val or SPLIT_MATERIALS.val:
                KEEP_VERT_ORDER.val = 0
                POLYGROUPS.val = 0
            else:
                KEEP_VERT_ORDER.val = 1

        def do_vertorder(e, v):
            global SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, KEEP_VERT_ORDER
            if KEEP_VERT_ORDER.val:
                SPLIT_OBJECTS.val = SPLIT_GROUPS.val = SPLIT_MATERIALS.val = 0
            else:
                if not (SPLIT_OBJECTS.val or SPLIT_GROUPS.val
                        or SPLIT_MATERIALS.val):
                    KEEP_VERT_ORDER.val = 1

        def do_polygroups(e, v):
            global SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, KEEP_VERT_ORDER, POLYGROUPS
            if POLYGROUPS.val:
                SPLIT_OBJECTS.val = SPLIT_GROUPS.val = SPLIT_MATERIALS.val = 0

        def do_help(e, v):
            url = __url__[0]
            print 'Trying to open web browser with documentation at this address...'
            print '\t' + url

            try:
                import webbrowser
                webbrowser.open(url)
            except:
                print '...could not open a browser window.'

        def obj_ui():
            ui_x, ui_y = GLOBALS['MOUSE']

            # Center based on overall pup size
            ui_x -= 165
            ui_y -= 90

            global CREATE_SMOOTH_GROUPS, CREATE_FGONS, CREATE_EDGES, SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, CLAMP_SIZE, IMAGE_SEARCH, POLYGROUPS, KEEP_VERT_ORDER, ROTATE_X90

            Draw.Label('Import...', ui_x + 9, ui_y + 159, 220, 21)
            Draw.BeginAlign()
            CREATE_SMOOTH_GROUPS = Draw.Toggle(
                'Smooth Groups', EVENT_NONE, ui_x + 9, ui_y + 139, 110, 20,
                CREATE_SMOOTH_GROUPS.val,
                'Surround smooth groups by sharp edges')
            CREATE_FGONS = Draw.Toggle(
                'NGons as FGons', EVENT_NONE, ui_x + 119, ui_y + 139, 110, 20,
                CREATE_FGONS.val,
                'Import faces with more then 4 verts as fgons')
            CREATE_EDGES = Draw.Toggle(
                'Lines as Edges', EVENT_NONE, ui_x + 229, ui_y + 139, 110, 20,
                CREATE_EDGES.val,
                'Import lines and faces with 2 verts as edges')
            Draw.EndAlign()

            Draw.Label('Separate objects by OBJ...', ui_x + 9, ui_y + 110, 220,
                       20)
            Draw.BeginAlign()
            SPLIT_OBJECTS = Draw.Toggle(
                'Object', EVENT_REDRAW, ui_x + 9, ui_y + 89, 55, 21,
                SPLIT_OBJECTS.val, 'Import OBJ Objects into Blender Objects',
                do_split)
            SPLIT_GROUPS = Draw.Toggle(
                'Group', EVENT_REDRAW, ui_x + 64, ui_y + 89, 55, 21,
                SPLIT_GROUPS.val, 'Import OBJ Groups into Blender Objects',
                do_split)
            SPLIT_MATERIALS = Draw.Toggle(
                'Material', EVENT_REDRAW, ui_x + 119, ui_y + 89, 60, 21,
                SPLIT_MATERIALS.val,
                'Import each material into a seperate mesh (Avoids > 16 per mesh error)',
                do_split)
            Draw.EndAlign()

            # Only used for user feedback
            KEEP_VERT_ORDER = Draw.Toggle(
                'Keep Vert Order', EVENT_REDRAW, ui_x + 184, ui_y + 89, 113,
                21, KEEP_VERT_ORDER.val,
                'Keep vert and face order, disables split options, enable for morph targets',
                do_vertorder)

            ROTATE_X90 = Draw.Toggle('-X90', EVENT_REDRAW, ui_x + 302,
                                     ui_y + 89, 38, 21, ROTATE_X90.val,
                                     'Rotate X 90.')

            Draw.Label('Options...', ui_x + 9, ui_y + 60, 211, 20)
            CLAMP_SIZE = Draw.Number(
                'Clamp Scale: ', EVENT_NONE, ui_x + 9, ui_y + 39, 130, 21,
                CLAMP_SIZE.val, 0.0, 1000.0,
                'Clamp the size to this maximum (Zero to Disable)')
            POLYGROUPS = Draw.Toggle('Poly Groups', EVENT_REDRAW, ui_x + 144,
                                     ui_y + 39, 90, 21, POLYGROUPS.val,
                                     'Import OBJ groups as vertex groups.',
                                     do_polygroups)
            IMAGE_SEARCH = Draw.Toggle(
                'Image Search', EVENT_NONE, ui_x + 239, ui_y + 39, 100, 21,
                IMAGE_SEARCH.val,
                'Search subdirs for any assosiated images (Warning, may be slow)'
            )
            Draw.BeginAlign()
            Draw.PushButton('Online Help', EVENT_REDRAW, ui_x + 9, ui_y + 9,
                            110, 21, 'Load the wiki page for this script',
                            do_help)
            Draw.PushButton('Cancel', EVENT_EXIT, ui_x + 119, ui_y + 9, 110,
                            21, '', obj_ui_set_event)
            Draw.PushButton('Import', EVENT_IMPORT, ui_x + 229, ui_y + 9, 110,
                            21, 'Import with these settings', obj_ui_set_event)
            Draw.EndAlign()

        # hack so the toggle buttons redraw. this is not nice at all
        while GLOBALS['EVENT'] not in (EVENT_EXIT, EVENT_IMPORT):
            Draw.UIBlock(obj_ui, 0)

        if GLOBALS['EVENT'] != EVENT_IMPORT:
            return

    # END ALTERNATIVE UI *********************

    Window.WaitCursor(1)

    if BATCH_LOAD:  # load the dir
        try:
            files = [
                f for f in os.listdir(filepath) if f.lower().endswith('.obj')
            ]
        except:
            Window.WaitCursor(0)
            Draw.PupMenu('Error%t|Could not open path ' + filepath)
            return

        if not files:
            Window.WaitCursor(0)
            Draw.PupMenu('Error%t|No files at path ' + filepath)
            return

        for f in files:
            scn = bpy.data.scenes.new(stripExt(f))
            scn.makeCurrent()

            load_obj(sys.join(filepath, f),\
              CLAMP_SIZE.val,\
              CREATE_FGONS.val,\
              CREATE_SMOOTH_GROUPS.val,\
              CREATE_EDGES.val,\
              SPLIT_OBJECTS.val,\
              SPLIT_GROUPS.val,\
              SPLIT_MATERIALS.val,\
              ROTATE_X90.val,\
              IMAGE_SEARCH.val,\
              POLYGROUPS.val
            )

    else:  # Normal load
        load_obj(filepath,\
          CLAMP_SIZE.val,\
          CREATE_FGONS.val,\
          CREATE_SMOOTH_GROUPS.val,\
          CREATE_EDGES.val,\
          SPLIT_OBJECTS.val,\
          SPLIT_GROUPS.val,\
          SPLIT_MATERIALS.val,\
          ROTATE_X90.val,\
          IMAGE_SEARCH.val,\
          POLYGROUPS.val
        )

    Window.WaitCursor(0)
Example #3
0
def write_ui(filename):
	
	if not filename.lower().endswith('.obj'):
		filename += '.obj'
	
	if not BPyMessages.Warning_SaveOver(filename):
		return
	
	global EXPORT_APPLY_MODIFIERS, EXPORT_ROTX90, EXPORT_TRI, EXPORT_EDGES,\
		EXPORT_NORMALS, EXPORT_NORMALS_HQ, EXPORT_UV,\
		EXPORT_MTL, EXPORT_SEL_ONLY, EXPORT_ALL_SCENES,\
		EXPORT_ANIMATION, EXPORT_COPY_IMAGES, EXPORT_BLEN_OBS,\
		EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_KEEP_VERT_ORDER,\
		EXPORT_POLYGROUPS, EXPORT_CURVE_AS_NURBS
	
	EXPORT_APPLY_MODIFIERS = Draw.Create(0)
	EXPORT_ROTX90 = Draw.Create(1)
	EXPORT_TRI = Draw.Create(0)
	EXPORT_EDGES = Draw.Create(1)
	EXPORT_NORMALS = Draw.Create(0)
	EXPORT_NORMALS_HQ = Draw.Create(0)
	EXPORT_UV = Draw.Create(1)
	EXPORT_MTL = Draw.Create(1)
	EXPORT_SEL_ONLY = Draw.Create(1)
	EXPORT_ALL_SCENES = Draw.Create(0)
	EXPORT_ANIMATION = Draw.Create(0)
	EXPORT_COPY_IMAGES = Draw.Create(0)
	EXPORT_BLEN_OBS = Draw.Create(0)
	EXPORT_GROUP_BY_OB = Draw.Create(0)
	EXPORT_GROUP_BY_MAT = Draw.Create(0)
	EXPORT_KEEP_VERT_ORDER = Draw.Create(1)
	EXPORT_POLYGROUPS = Draw.Create(0)
	EXPORT_CURVE_AS_NURBS = Draw.Create(1)
	
	
	# Old UI
	'''
	# removed too many options are bad!
	
	# Get USER Options
	pup_block = [\
	('Context...'),\
	('Selection Only', EXPORT_SEL_ONLY, 'Only export objects in visible selection. Else export whole scene.'),\
	('All Scenes', EXPORT_ALL_SCENES, 'Each scene as a separate OBJ file.'),\
	('Animation', EXPORT_ANIMATION, 'Each frame as a numbered OBJ file.'),\
	('Object Prefs...'),\
	('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object. May break vert order for morph targets.'),\
	('Rotate X90', EXPORT_ROTX90 , 'Rotate on export so Blenders UP is translated into OBJs UP'),\
	('Keep Vert Order', EXPORT_KEEP_VERT_ORDER, 'Keep vert and face order, disables some other options.'),\
	('Extra Data...'),\
	('Edges', EXPORT_EDGES, 'Edges not connected to faces.'),\
	('Normals', EXPORT_NORMALS, 'Export vertex normal data (Ignored on import).'),\
	('High Quality Normals', EXPORT_NORMALS_HQ, 'Calculate high quality normals for rendering.'),\
	('UVs', EXPORT_UV, 'Export texface UV coords.'),\
	('Materials', EXPORT_MTL, 'Write a separate MTL file with the OBJ.'),\
	('Copy Images', EXPORT_COPY_IMAGES, 'Copy image files to the export directory, never overwrite.'),\
	('Triangulate', EXPORT_TRI, 'Triangulate quads.'),\
	('Grouping...'),\
	('Objects', EXPORT_BLEN_OBS, 'Export blender objects as "OBJ objects".'),\
	('Object Groups', EXPORT_GROUP_BY_OB, 'Export blender objects as "OBJ Groups".'),\
	('Material Groups', EXPORT_GROUP_BY_MAT, 'Group by materials.'),\
	]
	
	if not Draw.PupBlock('Export...', pup_block):
		return
	'''
	
	# BEGIN ALTERNATIVE UI *******************
	if True: 
		
		EVENT_NONE = 0
		EVENT_EXIT = 1
		EVENT_REDRAW = 2
		EVENT_EXPORT = 3
		
		GLOBALS = {}
		GLOBALS['EVENT'] = EVENT_REDRAW
		#GLOBALS['MOUSE'] = Window.GetMouseCoords()
		GLOBALS['MOUSE'] = [i/2 for i in Window.GetScreenSize()]
		
		def obj_ui_set_event(e,v):
			GLOBALS['EVENT'] = e
		
		def do_split(e,v):
			global EXPORT_BLEN_OBS, EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_APPLY_MODIFIERS, KEEP_VERT_ORDER, EXPORT_POLYGROUPS
			if EXPORT_BLEN_OBS.val or EXPORT_GROUP_BY_OB.val or EXPORT_GROUP_BY_MAT.val or EXPORT_APPLY_MODIFIERS.val:
				EXPORT_KEEP_VERT_ORDER.val = 0
			else:
				EXPORT_KEEP_VERT_ORDER.val = 1
			
		def do_vertorder(e,v):
			global EXPORT_BLEN_OBS, EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_APPLY_MODIFIERS, KEEP_VERT_ORDER
			if EXPORT_KEEP_VERT_ORDER.val:
				EXPORT_BLEN_OBS.val = EXPORT_GROUP_BY_OB.val = EXPORT_GROUP_BY_MAT.val = EXPORT_APPLY_MODIFIERS.val = 0
			else:
				if not (EXPORT_BLEN_OBS.val or EXPORT_GROUP_BY_OB.val or EXPORT_GROUP_BY_MAT.val or EXPORT_APPLY_MODIFIERS.val):
					EXPORT_KEEP_VERT_ORDER.val = 1
			
			
		def do_help(e,v):
			url = __url__[0]
			print 'Trying to open web browser with documentation at this address...'
			print '\t' + url
			
			try:
				import webbrowser
				webbrowser.open(url)
			except:
				print '...could not open a browser window.'
		
		def obj_ui():
			ui_x, ui_y = GLOBALS['MOUSE']
			
			# Center based on overall pup size
			ui_x -= 165
			ui_y -= 140
			
			global EXPORT_APPLY_MODIFIERS, EXPORT_ROTX90, EXPORT_TRI, EXPORT_EDGES,\
				EXPORT_NORMALS, EXPORT_NORMALS_HQ, EXPORT_UV,\
				EXPORT_MTL, EXPORT_SEL_ONLY, EXPORT_ALL_SCENES,\
				EXPORT_ANIMATION, EXPORT_COPY_IMAGES, EXPORT_BLEN_OBS,\
				EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_KEEP_VERT_ORDER,\
				EXPORT_POLYGROUPS, EXPORT_CURVE_AS_NURBS

			Draw.Label('Context...', ui_x+9, ui_y+239, 220, 20)
			Draw.BeginAlign()
			EXPORT_SEL_ONLY = Draw.Toggle('Selection Only', EVENT_NONE, ui_x+9, ui_y+219, 110, 20, EXPORT_SEL_ONLY.val, 'Only export objects in visible selection. Else export whole scene.')
			EXPORT_ALL_SCENES = Draw.Toggle('All Scenes', EVENT_NONE, ui_x+119, ui_y+219, 110, 20, EXPORT_ALL_SCENES.val, 'Each scene as a separate OBJ file.')
			EXPORT_ANIMATION = Draw.Toggle('Animation', EVENT_NONE, ui_x+229, ui_y+219, 110, 20, EXPORT_ANIMATION.val, 'Each frame as a numbered OBJ file.')
			Draw.EndAlign()
			
			
			Draw.Label('Output Options...', ui_x+9, ui_y+189, 220, 20)
			Draw.BeginAlign()
			EXPORT_APPLY_MODIFIERS = Draw.Toggle('Apply Modifiers', EVENT_REDRAW, ui_x+9, ui_y+170, 110, 20, EXPORT_APPLY_MODIFIERS.val, 'Use transformed mesh data from each object. May break vert order for morph targets.', do_split)
			EXPORT_ROTX90 = Draw.Toggle('Rotate X90', EVENT_NONE, ui_x+119, ui_y+170, 110, 20, EXPORT_ROTX90.val, 'Rotate on export so Blenders UP is translated into OBJs UP')
			EXPORT_COPY_IMAGES = Draw.Toggle('Copy Images', EVENT_NONE, ui_x+229, ui_y+170, 110, 20, EXPORT_COPY_IMAGES.val, 'Copy image files to the export directory, never overwrite.')
			Draw.EndAlign()
			
			
			Draw.Label('Export...', ui_x+9, ui_y+139, 220, 20)
			Draw.BeginAlign()
			EXPORT_EDGES = Draw.Toggle('Edges', EVENT_NONE, ui_x+9, ui_y+120, 50, 20, EXPORT_EDGES.val, 'Edges not connected to faces.')
			EXPORT_TRI = Draw.Toggle('Triangulate', EVENT_NONE, ui_x+59, ui_y+120, 70, 20, EXPORT_TRI.val, 'Triangulate quads.')
			Draw.EndAlign()
			Draw.BeginAlign()
			EXPORT_MTL = Draw.Toggle('Materials', EVENT_NONE, ui_x+139, ui_y+120, 70, 20, EXPORT_MTL.val, 'Write a separate MTL file with the OBJ.')
			EXPORT_UV = Draw.Toggle('UVs', EVENT_NONE, ui_x+209, ui_y+120, 31, 20, EXPORT_UV.val, 'Export texface UV coords.')
			Draw.EndAlign()
			Draw.BeginAlign()
			EXPORT_NORMALS = Draw.Toggle('Normals', EVENT_NONE, ui_x+250, ui_y+120, 59, 20, EXPORT_NORMALS.val, 'Export vertex normal data (Ignored on import).')
			EXPORT_NORMALS_HQ = Draw.Toggle('HQ', EVENT_NONE, ui_x+309, ui_y+120, 31, 20, EXPORT_NORMALS_HQ.val, 'Calculate high quality normals for rendering.')
			Draw.EndAlign()
			EXPORT_POLYGROUPS = Draw.Toggle('Polygroups', EVENT_REDRAW, ui_x+9, ui_y+95, 120, 20, EXPORT_POLYGROUPS.val, 'Export vertex groups as OBJ groups (one group per face approximation).')
			
			EXPORT_CURVE_AS_NURBS = Draw.Toggle('Nurbs', EVENT_NONE, ui_x+139, ui_y+95, 100, 20, EXPORT_CURVE_AS_NURBS.val, 'Export 3D nurbs curves and polylines as OBJ curves, (bezier not supported).')
			
			
			Draw.Label('Blender Objects as OBJ:', ui_x+9, ui_y+59, 220, 20)
			Draw.BeginAlign()
			EXPORT_BLEN_OBS = Draw.Toggle('Objects', EVENT_REDRAW, ui_x+9, ui_y+39, 60, 20, EXPORT_BLEN_OBS.val, 'Export blender objects as "OBJ objects".', do_split)
			EXPORT_GROUP_BY_OB = Draw.Toggle('Groups', EVENT_REDRAW, ui_x+69, ui_y+39, 60, 20, EXPORT_GROUP_BY_OB.val, 'Export blender objects as "OBJ Groups".', do_split)
			EXPORT_GROUP_BY_MAT = Draw.Toggle('Material Groups', EVENT_REDRAW, ui_x+129, ui_y+39, 100, 20, EXPORT_GROUP_BY_MAT.val, 'Group by materials.', do_split)
			Draw.EndAlign()
			
			EXPORT_KEEP_VERT_ORDER = Draw.Toggle('Keep Vert Order', EVENT_REDRAW, ui_x+239, ui_y+39, 100, 20, EXPORT_KEEP_VERT_ORDER.val, 'Keep vert and face order, disables some other options. Use for morph targets.', do_vertorder)
			
			Draw.BeginAlign()
			Draw.PushButton('Online Help', EVENT_REDRAW, ui_x+9, ui_y+9, 110, 20, 'Load the wiki page for this script', do_help)
			Draw.PushButton('Cancel', EVENT_EXIT, ui_x+119, ui_y+9, 110, 20, '', obj_ui_set_event)
			Draw.PushButton('Export', EVENT_EXPORT, ui_x+229, ui_y+9, 110, 20, 'Export with these settings', obj_ui_set_event)
			Draw.EndAlign()

		
		# hack so the toggle buttons redraw. this is not nice at all
		while GLOBALS['EVENT'] not in (EVENT_EXIT, EVENT_EXPORT):
			Draw.UIBlock(obj_ui, 0)
		
		if GLOBALS['EVENT'] != EVENT_EXPORT:
			return
		
	# END ALTERNATIVE UI *********************
	
	
	if EXPORT_KEEP_VERT_ORDER.val:
		EXPORT_BLEN_OBS.val = False
		EXPORT_GROUP_BY_OB.val = False
		EXPORT_GROUP_BY_MAT.val = False
		EXPORT_APPLY_MODIFIERS.val = False
	
	Window.EditMode(0)
	Window.WaitCursor(1)
	
	EXPORT_APPLY_MODIFIERS = EXPORT_APPLY_MODIFIERS.val
	EXPORT_ROTX90 = EXPORT_ROTX90.val
	EXPORT_TRI = EXPORT_TRI.val
	EXPORT_EDGES = EXPORT_EDGES.val
	EXPORT_NORMALS = EXPORT_NORMALS.val
	EXPORT_NORMALS_HQ = EXPORT_NORMALS_HQ.val
	EXPORT_UV = EXPORT_UV.val
	EXPORT_MTL = EXPORT_MTL.val
	EXPORT_SEL_ONLY = EXPORT_SEL_ONLY.val
	EXPORT_ALL_SCENES = EXPORT_ALL_SCENES.val
	EXPORT_ANIMATION = EXPORT_ANIMATION.val
	EXPORT_COPY_IMAGES = EXPORT_COPY_IMAGES.val
	EXPORT_BLEN_OBS = EXPORT_BLEN_OBS.val
	EXPORT_GROUP_BY_OB = EXPORT_GROUP_BY_OB.val
	EXPORT_GROUP_BY_MAT = EXPORT_GROUP_BY_MAT.val
	EXPORT_KEEP_VERT_ORDER = EXPORT_KEEP_VERT_ORDER.val
	EXPORT_POLYGROUPS = EXPORT_POLYGROUPS.val
	EXPORT_CURVE_AS_NURBS = EXPORT_CURVE_AS_NURBS.val
	
	
	base_name, ext = splitExt(filename)
	context_name = [base_name, '', '', ext] # basename, scene_name, framenumber, extension
	
	# Use the options to export the data using write()
	# def write(filename, objects, EXPORT_EDGES=False, EXPORT_NORMALS=False, EXPORT_MTL=True, EXPORT_COPY_IMAGES=False, EXPORT_APPLY_MODIFIERS=True):
	orig_scene = Scene.GetCurrent()
	if EXPORT_ALL_SCENES:
		export_scenes = Scene.Get()
	else:
		export_scenes = [orig_scene]
	
	# Export all scenes.
	for scn in export_scenes:
		scn.makeCurrent() # If alredy current, this is not slow.
		context = scn.getRenderingContext()
		orig_frame = Blender.Get('curframe')
		
		if EXPORT_ALL_SCENES: # Add scene name into the context_name
			context_name[1] = '_%s' % BPySys.cleanName(scn.name) # WARNING, its possible that this could cause a collision. we could fix if were feeling parranoied.
		
		# Export an animation?
		if EXPORT_ANIMATION:
			scene_frames = xrange(context.startFrame(), context.endFrame()+1) # up to and including the end frame.
		else:
			scene_frames = [orig_frame] # Dont export an animation.
		
		# Loop through all frames in the scene and export.
		for frame in scene_frames:
			if EXPORT_ANIMATION: # Add frame to the filename.
				context_name[2] = '_%.6d' % frame
			
			Blender.Set('curframe', frame)
			if EXPORT_SEL_ONLY:
				export_objects = scn.objects.context
			else:	
				export_objects = scn.objects
			
			full_path= ''.join(context_name)
			
			# erm... bit of a problem here, this can overwrite files when exporting frames. not too bad.
			# EXPORT THE FILE.
			write(full_path, export_objects,\
			EXPORT_TRI, EXPORT_EDGES, EXPORT_NORMALS,\
			EXPORT_NORMALS_HQ, EXPORT_UV, EXPORT_MTL,\
			EXPORT_COPY_IMAGES, EXPORT_APPLY_MODIFIERS,\
			EXPORT_ROTX90, EXPORT_BLEN_OBS,\
			EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_KEEP_VERT_ORDER,\
			EXPORT_POLYGROUPS, EXPORT_CURVE_AS_NURBS)
		
		Blender.Set('curframe', orig_frame)
	
	# Restore old active scene.
	orig_scene.makeCurrent()
	Window.WaitCursor(0)