Convert 3ds files to obj with Blender

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.

Tags: , , , , ,

2 Responses to “Convert 3ds files to obj with Blender”

  1. Kyrylo Says:

    Thank you, it works fine, but it doesn’t export textures paths to mtl file, only materials. Dow you know some fix?

  2. ellery Says:

    Probably Blender can’t find the texture map file when it is exporting the obj file, so it leaves the texture out of the material. One solution is to add the texture map to the mtl file simply by adding a line like this to the material description (at the end of the mtl file):

    map_Kd path/to/texmap/tmap.jpg

    The better solution is to make sure the texture maps have short filenames and reside in the same folder as the 3ds files. The Blender obj exporter will export the texture map if it is present (in the same folder as the 3ds file), and it has a short filename. What is short? 3ds texture names are limited to the old Windows 8.3 format. There are only 12 bytes to store the texture name, which doesn’t leave room for a long filename or a directory path.

    If the texture map is exported successfully, the mtl file should contain a map_Kd line.

Leave a Reply