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
for k in bpy.data.objects.keys():
        j =k
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

  • $\begingroup$ Related and consider using cam = scn.objects.get("Camera") or snc.camera will be None if not existent in scene. $\endgroup$ – batFINGER Sep 20 '18 at 3:52
  • $\begingroup$ @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. $\endgroup$ – user84592 Sep 20 '18 at 5:34
  • $\begingroup$ 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 $\endgroup$ – WhatAMesh Sep 20 '18 at 9:06
  • $\begingroup$ 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. $\endgroup$ – batFINGER Sep 20 '18 at 9:37