1
$\begingroup$

I have a script(Script A) that sets/adjusts a lot of render settings in the render panel, in Blender.

Script A:

...
def set_output_settings():
    update_filename()
    set_filetype()
    disable_overwrite()

def set_settings():
    set_output_settings()
    set_sampling_settings()
    set_dimension_settings()

set_settings()

It works beautifully on it's own, when executed from within Blender's text editor.

But then I have a UI script(Script B) to make this into an addon. Here, I call script A with the exec command. When I run script B, a panel with a button shows up, in the context menu. But when I push the button(to execute Script A), I get an error message:

Traceback (most recent call last):
  File "F:\06_MotionPath_Dev\MotionPath_Dev_001.blend\RenderAddon_UI", line 30, in execute
  File "F:\Scripts\RenderAddon\QuickRenderAddon.py", line 73, in <module>
    set_settings()
  File "F:\Scripts\RenderAddon\QuickRenderAddon.py", line 64, in set_settings
    set_output_settings()
NameError: name 'set_output_settings' is not defined

location: <unknown location>:-1

I can't figure out why. After all, script B works fine when run seperately.

I've tried rearranging the order of the functions, but it doesn't help. What's wrong with my script and how can I fix it?

Script B:

import bpy
import os

class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel for quick rendering options"""
    bl_label = "Quick rendering panel"
    bl_idname = "RENDER_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        # Create an row where the buttons are aligned to each other.
        layout.label(text="Quick Rendering:")

        row = layout.row()
        row.scale_y = 2.0
        row.operator("object.custom_rendering")

class CustomRenderOperator(bpy.types.Operator):
    """Render stuff, yee"""
    bl_idname = "object.custom_rendering"
    bl_label = "Preview render"

    def execute(self, context):
        filename = "F:\\Scripts\\RenderAddon\\QuickRenderAddon.py"
        exec(compile(open(filename).read(), filename, 'exec')) ######## Calling the other script
        return {'FINISHED'}


def register():
    bpy.utils.register_class(LayoutDemoPanel)
    bpy.utils.register_class(CustomRenderOperator)


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)
    bpy.utils.unregister_class(CustomRenderOperator)


if __name__ == "__main__":
    register()

It also works if I merge the two script files together. But I find that messy. Is it preferred to only have 1 script file/module per addon?

$\endgroup$
2

0

You must log in to answer this question.

Browse other questions tagged .