Simple export script

For all you people new to blender scripting like myself. I just got my script working and would like to share it. Hope this helps someone.

This code adds a panel to the object window with an export button. When clicked it exports data from the selected Mesh object to a text file. You will need to edit it. its very simple at the moment.


# -*- coding: utf-8 -*-
#
# vortX GE export object
#

import bpy
import os

# my OP ###

class ExportVXO(bpy.types.Operator):
  bl_idname = "export_vxo"
  bl_label = "Export VXO"
  
  @classmethod
  def poll(cls, context):
    return context.active_object != None
  
  def vertsToLine(self,verts):
    line = "vertex "
    v = verts.co
    line += str(v[0]) + " " + str(v[1]) + " " + str(v[2])
    return line[:] + "
"
  
  def normsToLine(self,verts):
    line = "normal "
    v = verts.normal
    line += str(v[0]) + " " + str(v[1]) + " " + str(v[2])
    return line[:] + "
"
  
  def outvxo(self,obj):
    me = obj.data
    # write the fvirts
    file = open("/home/lee/object.vxo", "w")
    file.write("# vortX GE object file v0.1

")
    file.write("# Vertex data
")
    for verts in me.vertices:
      file.write(self.vertsToLine(verts))
    file.write("
# Normal data
")
    for verts in me.vertices:
      file.write(self.normsToLine(verts))
    file.close()
  
  def execute(self, context):
    print("Run Export VXO")
    obj = context.object
    self.outvxo(obj)
    return {'FINISHED'}

# my PANEL

class OBJECT_PT_export_vxo(bpy.types.Panel):
  bl_label = "Export VXO object"
  bl_space_type = "PROPERTIES"
  bl_region_type = "WINDOW"
  bl_context = "object"
  
  def draw(self, context):
    layout = self.layout
    
    obj = context.object
    
    row = layout.row()
    row.label(text="Active object : " + obj.name)
    row = layout.row()
    row.operator("export_vxo", text="Export")