#!/usr/bin/env python import os import sys import bpy file_loc = sys.argv[4] #0: blender 1: --python 2: path to script 3: -- 4: actual filepath print("Path: ", file_loc) for o in bpy.data.objects: if o.type == 'MESH': o.select_set(True) else: o.select_set(False) # call the operator only one initial time bpy.ops.object.delete() #check for filetype extension = file_loc.split(".")[-1] # BLENDER 2.8 3DS IMPORT NOT YET AVAILABLE #if(extension == "3ds" or extension == "3DS"): # imported_object = bpy.ops.import_scene.autodesk_3ds(filepath=file_loc) if(extension == "obj" or extension == "OBJ"): imported_object = bpy.ops.import_scene.obj(filepath=file_loc) if(extension == "fbx" or extension == "FBX"): imported_object = bpy.ops.import_scene.fbx(filepath=file_loc) if(extension == "gltf" or extension == "GLTF" or extension == "glb" or extension == "GLB"): imported_object = bpy.ops.import_scene.gltf(filepath=file_loc) if(extension == "ply" or extension == "PLY"): imported_object = bpy.ops.import_mesh.ply(filepath=file_loc) if(extension == "stl" or extension == "STL"): imported_object = bpy.ops.import_mesh.stl(filepath=file_loc) if(extension == "abc" or extension == "ABC"): imported_object = bpy.ops.wm.alembic_import(filepath=file_loc, as_background_job=False) if(extension == "dae" or extension == "DAE"): imported_object = bpy.ops.wm.collada_import(filepath=file_loc) if(extension == "x3d" or extension == "X3D" or extension == "wrl" or extension == "WRL"): imported_object = bpy.ops.import_scene.x3d(filepath=file_loc) if(extension == "bvh" or extension == "BVH"): imported_object = bpy.ops.import_anim.bvh(filepath=file_loc) if(extension == "mdl" or extension == "MDL"): file_name = os.path.basename(file_loc) imported_object = bpy.ops.import_mesh.mdl(filepath=file_loc, files=[{"name":file_name}]) #zoom to object for area in bpy.context.screen.areas: if area.type == 'VIEW_3D': for region in area.regions: if region.type == 'WINDOW': override = {'area': area, 'region': region, 'edit_object': bpy.context.edit_object} bpy.ops.view3d.view_selected(override) #change view: zoom to object & hide overlays area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') if(extension != "bvh" and extension != "BVH"): area.spaces[0].overlay.show_overlays = False area.spaces[0].shading.type = 'MATERIAL' #bpy.ops.view3d.camera_to_view_selected() #area.spaces[0].region_3d.view_perspective = 'CAMERA'