2

I am currently working on a huge scene with modular building blocks and for the moment I have to export one object at the time which is extremely time consuming. Is it any way to select say 30 objects inside Blender and use the .obj exporter/some kind of script to export each object separate instead?

Jimmy Livefjord
  • 355
  • 2
  • 9
  • related http://blender.stackexchange.com/questions/5382/export-multiple-objects-to-obj?rq=1 (but that asks about all objects in the scene, not the selected only) – zeffii May 27 '15 at 09:01
  • I've written an Add-on, see http://blender.stackexchange.com/a/31852/3710, as usual you only have to enable selection only. – p2or Jun 05 '15 at 11:03

1 Answers1

4

certainly! but it's a little hacky. Run this from text editor for a few objects selected. Make sure to change the folder to a valid path.

import bpy
import os

folder = '/home/zeffii/Uploads/'

selected = bpy.context.selected_objects.copy()
bpy.ops.object.select_all(action='DESELECT')

for obj in selected:
    name = obj.name.replace('.', '_')
    obj.select = True
    fullpath = os.path.join(folder, name + '.obj')
    bpy.ops.export_scene.obj(
        filepath=fullpath, 
        check_existing=True, 
        axis_forward='-Z', 
        axis_up='Y', 
        use_selection=True, 
        use_animation=False, 
        use_mesh_modifiers=True, 
        use_edges=True, 
        use_smooth_groups=False, 
        use_smooth_groups_bitflags=False, 
        use_normals=True, 
        use_uvs=True, 
        use_materials=True, 
        use_triangles=False, 
        use_nurbs=False, 
        use_vertex_groups=False, 
        use_blen_objects=True, 
        group_by_object=False, 
        group_by_material=False, 
        keep_vertex_order=False, 
        global_scale=1, 
        path_mode='AUTO')
    obj.select = False

Most of those options in export_scene are default and you can remove those lines, or comment them out, but some of them may be useful if you want to change them later.

There's a nice Template for this in (with a slightly different approach - as in, it checks to see if the destination is valid first, which is handy if you aren't too familiar with paths): TextEditor -> Templates -> Python -> Batch Export


update:

https://gist.github.com/zeffii/529d435d5853e92dcc51

I'm not entirely sure how to inherit all the properties from the original exporter operator for objs. I could add them individually if you need specific props, else it would be wasted effort adding them all.

With the exporter code, you navigate to select a folder, don't have to type any thing, just hit the Export selected Objects as obj button at the end.

zeffii
  • 39,634
  • 9
  • 103
  • 186
  • Big thanks! I will try it out and i will mark this solved if it worked. – Jimmy Livefjord May 27 '15 at 12:21
  • Thanks but it didnt work, also i dont understand what the template is suppose to do, should i run that to check the validity of the filepath i write in some text inside the text editor? can you help me to write a script so that i can attach it to a shortcut instead? thanks! – Jimmy Livefjord May 27 '15 at 15:44
  • Yeah, I almost finished the add-on code for it, which would let you pick a folder from a panel instead. – zeffii May 27 '15 at 16:06
  • but in the meantime, you sould start blender from a console / prompt and try running the code, in order to get the error. ' it's not working ' is too vague – zeffii May 27 '15 at 16:15
  • I've added a version of the script which when Run, in TextEditor will add a menu item to File -> Export. see the update – zeffii May 27 '15 at 17:47
  • Thanks a ton for helping me with this! I really have no clue how to script and this will help me a lot in terms of time. I still havent tried the script, i will try it and if i get any errors i will paste it here as well. THANKS! – Jimmy Livefjord May 28 '15 at 15:28
  • Okay i cant get it to work am i doing something wrong here? here you can see the screenshot: https://www.dropbox.com/s/vp8k4hgn3d7aab2/error.jpg?dl=0 – Jimmy Livefjord May 28 '15 at 15:54
  • Funny, same idea :) Here you can find this as File Browser Add-on (user selection also implemented): http://blender.stackexchange.com/a/31852/3710. Feel free to improve it. – p2or Jun 05 '15 at 11:08