0
$\begingroup$

So, I have been trying to create an add-on and with help from the community and lots and lots of snippets and videos, I am up to version 1.2.

Over the last few versions I have had a few thousand people download the add-on, but now one person is having trouble with it.

For him, the panels open but show nothing and when he checks the Info, it shows an error.

enter image description here

Now I know for sure that the code it mentions in the error is slightly broken anyway.

It toggles the information text.

The error points to line 2935 ?

but this same script works for everyone else, why would this now happen to this person?.

He is using the same version of blender as I am (2.80) and is also using a Windows, so there should be no difference.

If someone could help me figure this out or have suggestions I would greatly appreciate it.

I could also post the full code if that helps or link to it here

$\endgroup$
2
$\begingroup$

Here is the error message followed by the section of code around line 2935:

Traceback (most recent call last):
  File "C:\Users\ryanl\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\Darkfall VFX Nodes1_2.py", line 2935, in draw
    icon="TRIA_DOWN" if obj.expanded else "TRIA_RIGHT",
AttributeError: 'NoneType' object has no attribute 'expanded'
def draw(self, context):
        layout = self.layout
        obj = context.object

        box = layout.box()

        row = box.row()
        row.prop(obj, "expanded", # Line 2935
            icon="TRIA_DOWN" if obj.expanded else "TRIA_RIGHT",
            icon_only=True, emboss=False)

It is possible that the user has put Blender into a state where context.object could be None by having no selected objects. For example, if a user deletes the selected object, there will be no selected object. It could also be that this is a side effect from another addon (one that deselects all objects, for example).

I am able to reproduce this error by starting with a new .blend file and deleting the default cube. I am also able to reproduce the error by running the following script in the text editor:

import bpy
bpy.context.view_layer.objects.active = None

You may want to handle the case where context.object is None. One way to handle this is by adding the poll class method to the panel. The draw method will only run if the poll method returns True.

    @classmethod
    def poll(cls, context):
        return context.object is not None

EDIT: I took a closer look at your script. The only reason an object needs to be selected is because the expanded property is stored inside of an Object. The object is not used elsewhere in drawing. I would consider a small redesign so that the property is stored somewhere else so that it is not necessary for the user to have an object selected. An example could be to store the property in the Scene object. Here is an example for how this could be done:

class Sub1Panel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "clonepanel"
    bl_idname = "OBJECT_PT_clone"
    bl_space_type = 'NODE_EDITOR'
    bl_label = "Clone Node"
    bl_region_type = "UI"
    bl_category = "Darkfall VFX Nodes"
    bl_options = {'DEFAULT_CLOSED'}
    bl_parent_id = 'OBJECT_PT_toolseffect'

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

        box = layout.box()
        row = box.row()
        row.prop(scene, "Sub11Panel_expanded ",
            icon="TRIA_DOWN" if scene.Sub11Panel_expanded else "TRIA_RIGHT",
            icon_only=True, emboss=False    
        )

        if scene.Sub11Panel_expanded:
            row.label("label")


def register():
    bpy.utils.register_class(Sub11Panel)
    bpy.types.Scene.Sub11Panel_expanded = bpy.props.BoolProperty(default=False)

def unregister():
    bpy.utils.unregister_class(Sub11Panel)
    del bpy.types.Scene.Sub11Panel_expanded 
$\endgroup$
4
  • $\begingroup$ Ah, ok I understand now thanks! @RLGUY So if no object is selected then that's why it does not show. Your suggestion of adding the Poll Class method will only remove the panels unless something is selected though right?. So instead of seeing the blank panels, they won't see any panels at all. I see why this is a rare problem because most users open a new project and switch to the compositor, thus the default cube is already selected. Adding the poll is a good idea but I still need to let them know not to delete the default cube.. Thanks again for the information!.. $\endgroup$ – Darkfall Sep 29 '19 at 21:13
  • 1
    $\begingroup$ No problem! I took a closer look at your script and noticed that with a small redesign, you could avoid the requirement of a user needing a selected object. I have added an edit to the end of the answer. $\endgroup$ – RLGUY Sep 30 '19 at 0:47
  • $\begingroup$ thanks that works for one panel "The Clone node" panel. How would I implement this for the other panels?.. do I just do the same thing? i need to change obj to scene then add the if scene.Sub11Panel_expanded: part. So I need to change the name?.. Also for the Register and unregister? I am a little confused, because Sub11panel is the Render Panel. $\endgroup$ – Darkfall Sep 30 '19 at 12:50
  • $\begingroup$ You can implement the other panels by registering more properties (one for each panel) and following the same pattern as the Sub1Panel example script. For example, you could register Sub1Panel_expanded, Sub2Panel_expanded, Sub3Panel_expanded, ... and use them as the expanded variable for the corresponding panel. $\endgroup$ – RLGUY Oct 1 '19 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.