Looking for an export script object position, rotation & custom properties

Thanks CoDEmanX, i will have a go at that & see how it goes.

Got it working 99.9% the way i want it to. CoDemanX tried what you suggested but was still coming out with similar results on the exported format. This may be a dirty way to do it but it works. I only have one last problem with the export code and it only happens with the second value in the loop that gets written to the file & can’t figure out why it’s doing it. I keep getting [] at the end of the value. This is what is being written out, note the []


[start]
Object:Sphere
X#:2.531625509262085
Y#:0.0
Z#:5.367858409881592
Xrot#:0.0
Yrot#:0.0
Zrot#:0.0
Class%=enemy[]
Health%=100[]


Object:Cube
X#:0.0
Y#:0.0
Z#:0.0
Xrot#:0.0
Yrot#:0.0
Zrot#:0.0
health=100[]
armour=25[]
ammo=75[]


[end]


Here is the whole script:


bl_info = {
    "name": "Object Location & Rotation1",
    "author": "Robert Hogg",
    "blender": (2,69,0),
    "version": (0,0,1),
    "location": "File > Import-Export",
    "description": "Export Object Location & Rotation1.",
    "category": "Import-Export"}


import bpy
from bpy_extras.io_utils import ExportHelper




class ExportMyFormat(bpy.types.Operator, ExportHelper):
    bl_idname = "export_my_format1.txt";
    bl_label = "Export .Txt";
    bl_options = {'PRESET'};
    filename_ext = ".txt";
    
    filepath = bpy.props.StringProperty("FILE_PATH")
    global a


    def execute(self, context):


        file = open(self.filepath,'w')
        file.write('[start]')
        file.write("
")
        for a in bpy.context.selected_objects:
            file.write('Object:'+a.name)
            file.write("
")
            file.write('X#:'+str(a.location[0]))
            file.write("
")
            file.write('Y#:'+str(a.location[2]))
            file.write("
")
            file.write('Z#:'+str(a.location[1]))
            file.write("
")
            file.write('Xrot#:'+str(a.rotation_euler[0]))
            file.write("
")
            file.write('Yrot#:'+str(a.rotation_euler[2]))
            file.write("
")
            file.write('Zrot#:'+str(a.rotation_euler[0]))
            file.write("
")
            
            objname = a.name
            objfields = bpy.data.objects[objname].event_settings
            
            fields = []
            values = []
            
            count = 0
        
            for i in objfields:
                file.write(str(bpy.data.objects[objname].event_settings[count].event_field +"="))
                file.write(str(bpy.data.objects[objname].event_settings[count].event_value))
                count = count + 1
                file.write(str(values)+"
")
                    
            file.write("
")
            
        file.write('[end]')
    
        
        return {'FINISHED'};
    
    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}
    


    
def menu_func(self, context):
    self.layout.operator(ExportMyFormat.bl_idname, text="My Model Format1(.txt)");


def register():
    bpy.utils.register_module(__name__);
    bpy.types.INFO_MT_file_export.append(menu_func);


def unregister():
    bpy.utils.unregister_module(__name__);
    bpy.types.INFO_MT_file_export.remove(menu_func);


if __name__ == "__main__":
    register()

looks pretty strange what you do there:


            count = 0
        
            for i in objfields:
                file.write(str(bpy.data.objects[objname].event_settings[count].event_field +"="))
                file.write(str(bpy.data.objects[objname].event_settings[count].event_value))
                count = count + 1
                file.write(str(values)+"
")

It should be more like this:

  
            ob = bpy.data.objects[objname]
            for e in ob.event_settings:
                file.write("%s=%s
" % (e.event_field, e.event_value))

If this still gives you unwanted [], then you need to provide more info about event_settings

Thanks heaps CoDEmanX. Works beautifully. :slight_smile:
Because i have only just started to learn how to script with python for blender & i understand how a for loop works, the only way i could find how to return the values of the “event_field” & “event_value” array was to use the number the values were stored in by using the “count” variable.
Cheers.
Can anyone recommend any good tutorials for scripting in Blender that go into a bit of detail?

Official API docs:
http://www.blender.org/documentation/250PythonDoc/

Wiki (note that some the scripts are dated!):
http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook

And search the forum for “how to learn python” or similar to find a bunch of links.

Thanks CoDEmanX, i will check them out. :slight_smile: