Script to export all object locations [help]

Hi,

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:

<object>
<name>
cube
</name>
<LocX>
0
</LocX>
<LocY>
0
</LocY>
<LocZ>
0
</LocZ>
<RotX>
0
</RotX>
<RotY>
0
</RotY>
<RotZ>
0
</RotZ>
<ScaleX>
1
</ScaleX>
<ScaleY>
1
</ScaleY>
<ScaleZ>
1
</ScaleZ>
<DimX>
2
</DimX>
<DimY>
2
</DimY>
<DimZ>
2
</DimZ>
</object>

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
Loc(0,0,0)
Rot(0,0,0)
Scale(1,1,1)
Dim(2,2,2)

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.

Thanks!
ZM

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?

@Xjazz,

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:

http://minimustard.com/screen_shot_3.jpg

My closest quick approximation in panda3D:

http://minimustard.com/panda_screen_shot.jpg

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:

Thanks!
ZM

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?

@mandoragon

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/blender.app, but that launches it with no console to be found.

Right, could you please follow this tutorial: http://blenderartists.org/forum/showpost.php?p=1267071&postcount=15

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!
ZM

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…