Maya + Blender droppers

Community Forums/Developer Stations/Maya + Blender droppers

jhocking(Posted 2008) [#1]
I used to use Droplet for this, but it occurred to me that I could just use Maya or Blender as a dropper. I've had these scripts for a while now, and I never mentioned them because they were so simple and I thought the concept was obvious. After a recent conversation though I guess it isn't obvious, so here they are, one for Maya and one for Blender:
(no MaxScript because I don't have 3ds max, sorry; it'd only take like ten minutes for someone to bang out a dropper script.)

These scripts save out a text file with information about every object in the scene (XYZ coordinates for position and rotation.) Then I just have my game read those text files and place entities around the scene according to the saved coordinates. So like to place particle emitters in my level (just choosing one example at random) I position spheres in Maya where I want my emitters to be, save out the positions of the spheres, and then have my game place an emitter at each saved position.

Incidentally, I just noticed they are only saving position and rotation, not the object's name; I could have sworn I added that in, I guess I'll have to do that later (holidays and all right now :P) Anyway, select the objects in the scene you want to save data about and then run the script. For now, because object names are not being saved, just have a separate text file for each type of object in your scene (man I really do need to add names to the droppers.)

It's important to note that the script for Maya doesn't create a new text file from scratch, it requires you to manually create a text file for it to overwrite. Of course, now that Maya supports Python I could rewrite the script in Python and take advantage of Python's file commands...

plash(Posted 2008) [#2]

Name-exporting and specific to objects that begin with "exp_" instead of selected objects, easily changed..

Name: 'Dropper'
Blender: 246
Group: 'Export'
Tooltip: 'Saves object info to text file'

import Blender
import bpy
import string

def write(filename):
	out = file(filename,"w")
	sce =
	for obj in sce.objects:
				out.write("<name=" +[4:] + ">")
				out.write(str(round(obj.LocX, 4)) + ",")
				out.write(str(round(obj.LocY, 4)) + ",")
				out.write(str(round(obj.LocZ, 4)) + ">")
				out.write(str(round(obj.RotX, 4)) + ",")
				out.write(str(round(obj.RotY, 4)) + ",")
				out.write(str(round(obj.RotZ, 4)) + ">")
Blender.Window.FileSelector(write, "Export objects")

jhocking(Posted 2008) [#3]
Hey thanks! I figured adding names was easy, I just hadn't bothered to yet.

ADDITION: Just updated both files to export the object names. Doing that in MEL was even easier than I figured; at first I tried to lookup the attribute in the documentation, but in the end I just took a guess and happened to be right.

Incidentally, I didn't do the exporting prefix in the name because I actually prefer selecting the objects I want to export; putting them on display layers makes it easy to separate the dynamic entities from the rest of the scene. Obviously, just edit the script to whatever you want.

jhocking(Posted 2009) [#4]
I just noticed the bit you added about, what does that do?


Also, on another forum where I mentioned these scripts someone made this suggestion:

Instead of:
for obj in
if obj.sel:
# etc.

you should use:
for obj in Blender.Object.GetSelected():
# etc.

so you can remove bpy dependency and you resolve some runtime error problems.

Do you have any idea what difference that makes? Like, what advantage is there to removing the bpy dependency, and what runtime errors is he talking about?

plash(Posted 2009) [#5]
I don't know about the errors, but I think GetSelected() only grabs the objects that are selected, I modified it to export every object, regardless if it was selected or not.