0
$\begingroup$

i made an addon that uses custom properties to drive other properties within that file. but the thing is, it only works in that file. when i append the collection containing everything into another blend file, the custom properties dont drive the values even though the drivers are still there. i want to be able to use the custom properties in the addon to drive these other properties when i put it in a new file. below are the steps to replicate my issue

install this small test script as an addon

bl_info = \
    {
        #Info
        "name" : "Test",
        "author" : "Desper",
        "version" : (1, 0, 0),
        "blender" : (3, 3, 1),
        "location" : "View 3D > N-Panel",
        "description" :
            "Test",
        "category" : "Workflow",
    }

import bpy
from bpy.types import Panel

class Testing(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_label = "Test"
    bl_idname = "gp"
    bl_category = 'Test'
    
    def draw(self, context):
        layout = self.layout
        col = layout.column()
        row = col.row()
        row.prop(context.scene, 'subdiv', toggle=False, text='Viewport Subdivision')

classes=[Testing]

def register(): 
    for c in classes:
        bpy.utils.register_class(c)
    bpy.types.Scene.subdiv = bpy.props.BoolProperty(
        name='subdivision',
        default=False,    
)
def unregister():
    for c in classes:
        bpy.utils.unregister_class(c)

if __name__ == '__main__':
    register()

once thats installed, make sure you see this

enter image description here

-add a subdivision modifier to a primitive (or anything)

-copy the custom property as a new driver (right click > copy as new driver)

-paste the driver on the subdivision visibility in the viewport

-the custom prop should now control viewport subdivision of the cube

-put the cube in a new collection

-save the file and append the collection into another new file

-in the new file, the addon should still be there but the checkbox wont work even though the driver is still there

That's a smaller-scale version of what my issue is.

let me know if any other info or any files are needed!

EDIT: this is the error i get when trying to enable the addon when ``` bpy.context.Scene.subdiv = True

enter image description here

EDIT 2 : here is the blend file

$\endgroup$
10
  • $\begingroup$ try adding this in register: bpy.context.scene.subdiv = True because you didn't really create the variable, you just declared it $\endgroup$
    – Chris
    Commented Dec 7, 2022 at 16:50
  • $\begingroup$ My guess is because the driver references the scene of the source file, not the active scene. you can try to mess with the driver expression see blender.stackexchange.com/questions/28269/… $\endgroup$
    – Gorgious
    Commented Dec 7, 2022 at 16:59
  • $\begingroup$ @Chris tried that with both a capital s for scene and lowercase. got this error when trying to enable the addon both times $\endgroup$
    – desperrrr
    Commented Dec 7, 2022 at 17:04
  • $\begingroup$ i did this: [1]: i.sstatic.net/2cpeo.png and at least i got no error like you...can you show us your modified code? (lowercase pls) $\endgroup$
    – Chris
    Commented Dec 7, 2022 at 17:07
  • 1
    $\begingroup$ @Chris I think it's because you're running the script in the text editor inside Blender, the scene is available at this point. But when running it as an addon it executes when the file loads, and the context is not initialized yet. $\endgroup$
    – Gorgious
    Commented Dec 7, 2022 at 17:20

1 Answer 1

0
$\begingroup$

When appending part of a blend file to another, it makes a new scene making bpy.context.scene useless in one scene but working in the other. you just need to figure out which scene it doesn't work in and delete it or just not use it.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .