Skip to content

API Usage

Erica M. ("Loonatic") edited this page Jul 18, 2024 · 1 revision

Importing Via API

You can use the Blender API to import egg files through Python.

A simple script that walks down a given directory & recursively imports Egg files into the scene:

import bpy
import os, subprocess, sys, re


def addEggFile(modelFilePath):
    mFilePath = os.path.dirname(modelFilePath)
    mFileName = os.path.basename(modelFilePath)
    file_list = [dict(name=mFileName)]
    bpy.ops.import_scene.egg(
        filepath=mFilePath,
        directory=mFilePath,
        files=file_list
    )

target_dir = "path/to/eggfiles"

os.chdir(target_dir)
allFiles = []
inputFile = ".egg"

for root, _, files in os.walk(os.getcwd()):
    for file in files:
        if not file.endswith(inputFile):  # Input file
            continue
        file = os.path.join(root, file)
        allFiles.append(file)

for file in allFiles:
    addEggFile(file)
Clone this wiki locally