Developer Forum

Issue with importing USD files via bpy.ops.wm.usd_import and python

Hi,

I’m working on an add on and I’d like to import USDZ, USD, USDA, and USDC via the python library. I seem to run into an error but it’s failing silently. It just seems to just not import. If someone can help me track down an error or even how one properly imports this file type I’d appreciate it. Code is below. bpy.ops.import_scene.gltf() seems to not need to be run on an object whereas bpy.ops.wm.usd_import has me thinking it needs a scene or window to reference. Thanks.

bpy.ops.wm.usd_import(filepath=self.file_path, 
                import_cameras=True, 
                import_curves=True, 
                import_lights=True, 
                import_materials=True, 
                import_meshes=True, 
                import_volumes=True, 
                scale=1.0, 
                read_mesh_uvs=True, 
                read_mesh_colors=False, 
                import_subdiv=False, 
                import_instance_proxies=True, 
                import_visible_only=True,
                import_guide=False,
                import_proxy=True,
                import_render=True,
                set_frame_range=True,
                relative_path=True,
                create_collection=False,
                light_intensity_scale=1.0,
                mtl_name_collision_mode='MAKE_UNIQUE',
                import_usd_preview=True,
                set_material_blend=True)

The problem was that the usd_import call wasn’t in scope relative to blender. I had to move the call to init.py first. I also removed it from a separate thread in python.