Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# this script will scan the following specified folder for collada files, change it to wherever you are storing them
YourFolderPath = ''
# i.e. YourFolderPath = 'C:\\Users\\Martin\\Desktop'
# The .dae files in that folder will be iteratively imported into blender and rendered
# The images will be output to whatever folder path is specified in the output field within Blender
# They will be organised in folders, where each folder has the same name as the .dae file which was rendered
# If you wish, you can uncomment the following line and replace the output path with your own manually.
# bpy.context.scene.render.filepath = 'your output folder path here'
# Blender will freeze whilst it is rendering, it's automated so that shouldn't be an issue.
# if you want to check it is working, then check the output folder as it works.
# set up the scene to render as normal, including output resolution, samples, number of frames etc...
# to see the scripts text output as it runs:
# go to Window -> Toggle System Console
# this is useful to track the script as it goes
# built using Blender 2.81
import bpy
import os
outputPath = bpy.context.scene.render.filepath
def scanFolder(inputPath):
objList = []
for file in os.listdir(inputPath):
if file.endswith(".dae"):
objList.append(os.path.join(inputPath, file))
print("found:" + file)
return objList
def LoadOBJ(filePath):
bpy.ops.wm.collada_import(filepath=filePath)
imported_object = bpy.context.active_object
print(imported_object)
mat = bpy.data.materials.get("Head")
print(mat)
# Assign it to object
if imported_object.data.materials:
imported_object.data.materials[0] = mat
else:
imported_object.data.materials.append(mat)
bpy.ops.object.shade_smooth()
return imported_object;
def SetOutput(filePath):
name = bpy.path.display_name(filePath) + '\\'
bpy.context.scene.render.filepath = os.path.join(outputPath, name)
print(bpy.context.scene.render.filepath)
def ResetOutput():
bpy.context.scene.render.filepath = outputPath
def DoRender():
bpy.ops.render.render(animation=True)
if not( os.path.exists(YourFolderPath) and os.path.isdir(YourFolderPath) ):
YourFolderPath = os.path.dirname(bpy.data.filepath)
for daePath in scanFolder(YourFolderPath):
print(daePath)
# check collada path
if not( os.path.exists(daePath) ):
print("invalid collada directory")
break
# move to sub directory of output folder
SetOutput(daePath)
# make output folder
try:
os.mkdir(bpy.context.scene.render.filepath)
except OSError:
print("unable to create folder, it may already exist")
# check output folder
if not( os.path.exists(bpy.context.scene.render.filepath) and os.path.isdir(bpy.context.scene.render.filepath) ):
print("invalid output directory")
ResetOutput()
break
# load object
LoadOBJ(daePath) # sets active object to imported
# will block for duration of render
DoRender()
# delete
bpy.ops.object.delete() # deletes active object
# reset to base output folder
ResetOutput()
print("Complete :)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.