# Blender：How to convert different 3D format to blend by python script? [duplicate]

I have successfully made preview of blend 3D format. The /1/ below is my working script. Since customer has other formats, for example obj, Aveva made 3D format files. How could I make a conversion from obj or other format files to blend file format by python?

import bpy
import math

scn = bpy.context.scene
j=-1
for k in bpy.data.objects.keys():
if(k.startswith('Camera')):
j =k
break
print('j is: %s ', j)
cam = bpy.data.objects[j]
origin = bpy.data.objects.new('Empty',None)

step_count = 2

for step in range(0, step_count):
origin.rotation_euler[2] = math.radians(step * (360.0 / step_count))

scn.render.filepath = 'e:\\temp\\happy_shot_%d_wednes_Sep_7.png' % step

bpy.context.scene.render.resolution_x = 120
bpy.context.scene.render.resolution_y = 64

bpy.ops.render.render(write_still=True)

• Related and consider using cam = scn.objects.get("Camera") or snc.camera will be None if not existent in scene. – batFINGER Sep 20 '18 at 3:52
• @batFINGER Thanks for telling defects in my script. Right now, my questions is how to convert other 3D formats (obj for example) to blend format? so that I could use my script to make preview of 3D files in whatever original format. – user84592 Sep 20 '18 at 5:34
• Just hover above the button for the special imports and you will get command for it: obj -> bpy.ops.import_scene.obj(). You will probably have to also define the filepath somewhere and then you can automatically import it. There are some import addons that are either deactivated by default or have to additionally be downloaded and installed by you. There might be formats that can't be directly imported into blender, you will have to find scripts that convert them to a format that can be imported – WhatAMesh Sep 20 '18 at 9:06
• See link posted in first comment (along with the suggested improvements for your script). My answer in linked question: creates a new scene imports an obj and renders. An importer converts from that format to blender.The render creates the preview. For other operator importers see comment above, and the Import / Export category of addons to install those that are non default. – batFINGER Sep 20 '18 at 9:37