Posts Tagged ‘file format’

Convert 3ds files to obj with Blender

Tuesday, January 24th, 2012

Blender

3DS is an aging binary interchange format for 3D models. OBJ is another aging, but ASCII-based format for 3D models.

Here is a simple Python script that converts one or more files from 3DS format to OBJ format using Blender:

# Convert 3ds to obj using Blender
#
# Run as follows:
#   blender -b dummy.blend -P bl_3ds2obj.py -- file.3ds ...
#
# dummy.blend is just an empty Blender file needed as an argument.
# Put one or more .3ds files on the end of the command.
# The .obj files will be created with the same name (and path) as
# the .3ds file, but with the .obj extension.
# The export creates a .mtl file for each .obj file also.

import bpy
import sys
import os.path

for i in range(1, len(sys.argv)):
    if sys.argv[i] == "--":
        break

for file in sys.argv[i+1:]:
    # Start with an empty scene
    bpy.ops.object.select_all(action="SELECT")
    bpy.ops.object.delete()

    # Read a .3ds file
    bpy.ops.import_scene.autodesk_3ds(filepath=file)

    # Write a .obj file
    outfile = os.path.splitext(file)[0]+".obj"
    bpy.ops.export_scene.obj(filepath=outfile)

 

Save the script code in a file named blender_3ds2obj.py.  You will also need a Blender file to use as a placeholder in the command line.  You can save an empty file from Blender, or use an existing one.  Assume it is called dummy.blend.

To convert 3DS files, use the following command:


blender -b dummy.blend -P bl_3ds2obj.py -- file1.3ds file2.3ds file3.3ds

Tack on as many 3DS files to the end of the command as you want.

Note:  This assumes that dummy.blend and bl_3ds2obj.py are in the same folder as your 3DS files.  If not, you will need to specify the proper path to each.