2
$\begingroup$

I've been writing scripts for a couple of weeks and it's time for me to get more organized. I want to create multiple small scripts that I can call when needed. For example in my current project I need to append, switch mat, switch object, switch camera, and render. All of this can take up to 800 lines adding layers of complexity and making the script really hard to read. How do I break things up? I think I should use function like here: https://www.w3schools.com/python/python_functions.asp

But how do I split that up into multiple python files, and call them within my 'master' script in Blender?

This is what I have so far, I've made a function for my render settings, that I can call within the same file and which allow me to change samples and resolution when calling it:

def render_settings(res_multiplier = 1, samples = 10):
    print("CHANGING_RENDER_SETTINGS")
    bpy.context.scene.render.engine = 'CYCLES'
    bpy.context.scene.cycles.feature_set = 'EXPERIMENTAL'
    bpy.context.scene.cycles.device = 'GPU'
    bpy.context.scene.cycles.use_square_samples = True
    bpy.context.scene.cycles.samples = samples
    bpy.context.scene.render.resolution_x = 1000
    bpy.context.scene.render.resolution_y = 1000
    bpy.context.scene.render.resolution_percentage = res_multiplier*100

render_settings()

Edit: so if I save my_functions.py into the module folder of my Blender install I can call it by doing my_functions.render_settings() in any other python script I run from Blender. So I guess that answer my own question.

$\endgroup$
1
  • $\begingroup$ This is more of a general python question than a Blender question. I recommend reading about python project file organization online. For instance here: dev.to/codemouse92/… $\endgroup$
    – TLousky
    Oct 30, 2019 at 10:47

0

You must log in to answer this question.

Browse other questions tagged .