0
$\begingroup$

the goal was to simply have a bool value to change whether or not to show a custom panel with additional settings or no, it is modifier specific the first thought was simply register it on bpy.types.Modifier but the BooleanProperty() always fails to register and regardless of that blender doesn't allow class inheritance for it's classes

github link: https://github.com/Valery-AA/AlxOverHaul
video showing no errors: https://youtu.be/kjtJcAo2zvw

The Menu in question:

Image of the custom menu in which the ui list is located in it shows a list of every modifier in all the selected objects and the check box next to the modifier name is the toggle options prop() with the little arrow pointing down is the sub-menu that is currently open just doesn't have any layout yet

The latest attempt consists of:

Property Group:

class Alx_PG_PropertyGroup_ModifierSettings(bpy.types.PropertyGroup):
    """"""
    object_name : bpy.props.StringProperty(name="", default="") #type:ignore
    object_modifier : bpy.props.StringProperty(name="", default="") #type:ignore
    show_options : bpy.props.BoolProperty(name="", default=False) #type:ignore

Registered as:

bpy.types.Object.alx_modifier_collection = bpy.props.CollectionProperty(type=AlxGeneralPanel.Alx_PG_PropertyGroup_ModifierSettings)

Used inside the draw_item function of bpy.types.UIList:

        LayoutBox = layout.row().grid_flow(columns=1)

        object_info = LayoutBox.row().box()
        object_info.scale_y = 0.5
        object_info.label(text=item.ObjectPointer.name)

        modifier_slots = LayoutBox.row().grid_flow(columns=1)

        for Collection_Modifier in item.ObjectPointer.alx_modifier_collection:
            modifier_header = modifier_slots.row()
            obj_modifier = item.ObjectPointer.modifiers.get(Collection_Modifier.object_modifier)
            icon_name = bpy.types.Modifier.bl_rna.properties['type'].enum_items.get(obj_modifier.type).icon

            modifier_delete_button : Alx_OT_Modifier_ManageOnSelected = modifier_header.operator(Alx_OT_Modifier_ManageOnSelected.bl_idname, icon="PANEL_CLOSE")
            modifier_delete_button.object_pointer_reference = item.ObjectPointer.name
            modifier_delete_button.create_modifier = False
            modifier_delete_button.remove_modifier = True
            modifier_delete_button.object_modifier_index = item.ObjectPointer.modifiers.find(Collection_Modifier.object_modifier)

            modifier_header.prop(obj_modifier, "name", text="", icon=icon_name, emboss=True)
            modifier_header.prop(Collection_Modifier, "show_options")
            options_panel = modifier_slots.row().panel_prop(Collection_Modifier, "show_options")
            options_layout : bpy.types.UILayout = options_panel[1]

            modifier_header.prop(obj_modifier, "show_in_editmode", text="", emboss=True)
            modifier_header.prop(obj_modifier, "show_viewport", text="", emboss=True)
            modifier_header.prop(obj_modifier, "show_render", text="", emboss=True)

        LayoutBox.row().separator(factor=2.0)

the issue with this attempt is that no matter what the checkbox won't go to True or False the property always resets instantly to the default value set inside the property group, it is clickable and it does change the value, just it instantly goes back to it's default
i would assume that the issue is sparked by the CollectionProperty and PropertyGroup but compared to the usual behaviour of throwing that the value can't be altered from a draw function context or that the PointerProperty value can't be change in the current context, there is simply nothing in the console whenever the button to open the menu is pressed, the button visually changes but it does nothing as if the bool was not altered at all

would there be any way to tell why the prop to the bool property changes only visually and a possible fix?

$\endgroup$
4
  • $\begingroup$ Can you share the whole addon? $\endgroup$
    – unwave
    Commented Apr 15 at 16:35
  • $\begingroup$ Don't you get RuntimeError: Error: Layout panels can not be used in this context spam for options_panel = modifier_slots.row().panel_prop(Collection_Modifier, "show_options")? $\endgroup$
    – unwave
    Commented Apr 15 at 17:55
  • $\begingroup$ Where do you look for errors? $\endgroup$
    – unwave
    Commented Apr 15 at 19:27
  • $\begingroup$ @ValyArhal Please don't just remove content like that previous edit as there are already answers to this question. Please be considerate because community members invested time and effort answering your question. Any reason you deleted your answer as well? $\endgroup$
    – Harry McKenzie
    Commented May 9 at 12:12

1 Answer 1

0
$\begingroup$

Defaulting

When you click on the property's checkbox to change its value it triggers AlxUpdateSceneSelectionObjectListLambda that creates the collection with the property from scratch.

There is no actual point in storing alx_modifier_collection. bpy.types.Modifier does not support custom properties and you cannot really attached persistent data to it. The user can rename the modifier and this breaks the link.

The persistent_uid inclusion can partially resolve the issue but only for the current session and newer versions of Blender needed.

Avoid using the Alx_PG_PropertyGroup_ModifierSettings proxy and use the modifier's properties directly. bpy.types.Modifier.show_expanded instead of show_options. And draw the extra UI dynamically deciding what that modifier would need.

The bug

A recent change.

Using layout panels in this context is not yet supported. Therefor, the fix is to raise an exception instead of crashing.

https://projects.blender.org/blender/blender/issues/117168

enter image description here

$\endgroup$
3
  • $\begingroup$ @ValyArhal There is a problem with you relying on the collection. See the updated post. $\endgroup$
    – unwave
    Commented Apr 17 at 0:06
  • $\begingroup$ If the end goal are generic presets why do you even need the collection with the current modifier names? And why do you need to recreate the collection on every update? $\endgroup$
    – unwave
    Commented Apr 17 at 6:16
  • $\begingroup$ And how would you decide which property group instance belongs to which modifier in case it gets renamed and the blend file reloaded? $\endgroup$
    – unwave
    Commented Apr 17 at 6:46

You must log in to answer this question.