0

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

desperrrr
  • 634
  • 4
  • 17
  • try adding this in register: bpy.context.scene.subdiv = True because you didn't really create the variable, you just declared it – Chris Dec 07 '22 at 16:50
  • 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 https://blender.stackexchange.com/questions/28269/how-can-a-blender-driver-python-script-access-scene-properties-like-fps – Gorgious Dec 07 '22 at 16:59
  • @Chris tried that with both a capital s for scene and lowercase. got this error when trying to enable the addon both times – desperrrr Dec 07 '22 at 17:04
  • i did this: [1]: https://i.stack.imgur.com/2cpeo.png and at least i got no error like you...can you show us your modified code? (lowercase pls) – Chris Dec 07 '22 at 17:07
  • thats exactly what i got. i'll update the question to share the blend file – desperrrr Dec 07 '22 at 17:14
  • 1
    @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. – Gorgious Dec 07 '22 at 17:20
  • @Gorgious so what im getting from that is i cant use bpy.context and im fine with that if thats the case. i just dont know another way to do it – desperrrr Dec 07 '22 at 17:49
  • @Gorgious: yeah, that makes sense... ;) – Chris Dec 07 '22 at 18:05
  • Please check if there are 2 scenes after appending the collection from an other file. It should be so. You can edit driver with RMB and change the value of Prop: to the old (first) scene. – relaxed Dec 07 '22 at 18:31
  • wow i did not see that. it did make 2 scenes. once i figure out how to make it not create a new scene when i append a collection i will write an answer – desperrrr Dec 07 '22 at 18:58

1 Answers1

0

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.

desperrrr
  • 634
  • 4
  • 17