Script to export all object locations [help]


I am working on using blender as part of a pipeline for game work flow to go from prototyping in blender to building in Panda3D.

One thing that would speed up the process is if I could export a text file from blender that was possibly xml and had something like the following:


Then do that for all objects in a scene. If anyone has an example of a system similar to this working, hell it could be structured:
Object: Cube

Whatever, doesn’t matter to me, I would just like to see an example I can play with and bastardize if someone can help, it would be much appreciated. I need to also get all light/camera info as well.


yeah, something like that would be immensely helpful to me also, but unfortunately I’ve no idea where to even begin, as I’m fairly new to blender

How these objects are set to that scene?
Is the scene build-up from the x*x size tiles, which are set side by side?


I’m not sure what the first part of your question is…but I’ll show you a real world example of my problem…scene from BGE:

My closest quick approximation in panda3D:

So, the background of my scene is just one mesh, but I need a script to give me camera/light locations as well. Obviously the location won’t translate perfectly to Panda, however, if they are all relative to eachother, I can parse and build the .py to use in panda appropriately. I just need that relative location, and an automated way of doing it.

I hope that helps, it’s kind of hard to explain how I’m building it without writing an essay :slight_smile:


Do you want all objects in a scene or only those selected? Im just looking at the api, and it has everything you want… So I may be able to get everything you want printed in the terminal but I have no idea about how to get it in a txt file in python, but it would just mean copy and paste for you… is that ok?


I’d like to get everything in the scene, that way I can just omit objects that I don’t need, instead of reloading the scene to find things I missed. Also, I’m not actually sure how to view the terminal for blender on mac, do I just have to launch it from the terminal (never had a need to). But that copy/paste would be fine if you could explain how to do it.

When windows opens blender we have a consol/terminal where all the debugging comes back through…

What mac Os are you on atm?

10.5.8 I have tried doing an open /Applications/blender/, but that launches it with no console to be found.

Right, could you please follow this tutorial:

Im on my mac atm and it works. Tell me how you do…

Im just writing the script for you now, done half…

Awesome tip, got a console now :slight_smile:

Thanks much!

See how you find this, not sure exactly what dim was, Im guessing dimensions so maybe the bounding box or something of it…

Anyways heres the code:

import Blender

objects = Blender.Scene.GetCurrent().getChildren()

for s in objects:
	print 'Type:', s.getType(), '
' 'Object Name:', s.getName()
	print 'Scale:', s.getSize(), '
' 'Loc:', s.getLocation() 
	print 'RotX:', s.RotX, 'RotY:', s.RotY, 'RotZ:', s.RotZ, '

And heres an example of it working with the output:

Please tell me what you think and how it works for you

Thanks so much mandoragon! That works awesome! I know enough python to be able to get this out to a text file, I think, but the console window will be great for debugging my mistakes as I figure out blender’s functions.

You’re a hero!

For Laethyn and others who might be searching for this in the future, here’s what I did:

import Blender
import bpy

def write(filename):
    out = file(filename, "w")
    objects = Blender.Scene.GetCurrent().getChildren()
    for s in objects:
        out.write('Type:' + s.getType() + '
' 'Object Name:' + s.getName() + 
' 'Scale:' + str(s.getSize()) + '
' 'Loc:' + str(s.getLocation()) + 
' 'RotX:' + str(s.RotX) + 'RotY:' + str(s.RotY) + 'RotZ:' + 
        str(s.RotZ) + '

Blender.Window.FileSelector(write, "Export")

Works great! I used the terminal window for debugging a few of syntax errors I made, but now I can just open blender normally and run this without forcing a resolution.

(edited to not break the div)

Glad I could help, maybe you should add this to the python script respository…