This Code works fine CodeManx:- https://blender.stackexchange.com/a/19158/78916, but how would I get this work in an AddonPreferences cutom boxex? I can get it to work but it references 'object' 'cube' I would like to have it reference a UI file! Not asking for a script but something I can read to get my head around building custom UI's for the AddonPreferences, driving me crazy to get anything other that this, reference wise. HardOps has a perfect example of what I want in a expand panel on the UI tab, those are perfect to what I want, but I've a hard time following the code in 'Hops' python! An Expand box/panel is what I want (I think) but I just cant get anything to work in AddonPreferences, where do I need to look and what to read?
1 Answer
Right guys, thanks for he pointers, batFINGER pointed me in the right direction, I did look at the link brockmann posted and have seen that link on my quest travels. I don't know if I've found the right direction as I've used WM for the toggle but had in my head that all when hovered would point back to preferences! BUT I've got the look that I was looking for, I was after changing the icons ref toggle state but cant get anything to work but happy as it is, achieved my goal, thanks for the help, here is my code/effort:-
import bpy
preference.py file that gets imported from _init.py
from bpy.props import ( StringProperty, BoolProperty, FloatProperty, )
from bpy.types import (AddonPreferences, )
class AddonPreferences use (bl_idname = package) if multiple file.
class PREFS_PT_MyPrefs(AddonPreferences): bl_idname = package
# prop listings strings
some_folder = StringProperty(
name="Assets Folder",
subtype='DIR_PATH',
)
# prop listings bools
bpy.types.WindowManager.prop_toggle1 = bpy.props.BoolProperty()
bpy.types.WindowManager.prop_toggle2 = bpy.props.BoolProperty()
# prop listings float
test_ing = bpy.props.FloatProperty(default=1.0)
# user prefs panel
def draw(self, context):
layout = self.layout
# prop 1
wm = context.window_manager
box = layout.box()
box.prop(wm, 'prop_toggle1', icon='TEXTURE', text='HEADER', expand=False, emboss=True)
if wm.prop_toggle1:
box.prop(self, "test_ing", text='TESTING')
# prop 2
box = layout.box()
box.prop(wm, 'prop_toggle2', icon='FILE' , text='HEADER', expand=False, emboss=True)
if wm.prop_toggle2:
box.prop(self, "some_folder", text='TESTING')
# keep adding prop toggles!!!
# Class registered on __init__.py file
def draw(self, context):
method to the class as usual. If you'd like to copy the hardops properties, right-click > edit source... $\endgroup$toggle : BoolProperty()
in addon prefs draw would belayout.prop(self, "toggle")
$\endgroup$