Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, July 10, 2021

.abc batch export and import script Blender

Simple blender python script i wrote to save some time. I hope it will be useful for someone. 

Export selected objects as individual alembic file


import bpy
import os
narray = bpy.context.selected_objects

    ##path to export the selected objects
path = "/home/user/"
print(narray)
for obj in narray:
    bpy.ops.object.select_all(action='DESELECT')
    sobj = bpy.data.objects[obj.name]
    sobj.select_set(True)
    
       ##remove . and replace it with _
    bname = path+sobj.name.replace(".", "_")+".abc"
    bpy.ops.wm.alembic_export(filepath=bname,selected=True)
    
Import alembic file from a folder

import bpy
import os
	## Folder path to import the files from
directory = "/home/user/"
files = os.listdir(directory)
print(files)
for file in files:
    bpy.ops.wm.alembic_import(filepath= directory+file,as_background_job = False)
    ##select all the objects in the scene
bpy.ops.object.select_all()
  ##join the selected objects
bpy.ops.object.join()