What I am confusing is way to make panell check box for custom operator class without adding many custom properties for scene etc.
eg now I have one Custom Operator. which clear morph values. like this
class WIF_OT_clearDazMorphs(bpy.types.Operator):
bl_idname = "object.clear_morphs"
bl_label = "Clear daz morph value"
bl_description = "Clear current rig(obj) morph values"
bl_options = {'UNDO'}
#flg_act:BoolProperty(
#name = "active morph only",
#description = "clear only active morphs",
#default = False)
def execute(self, context):
scn = context.scene
rig = context.active_object
flg = scn.daz_setting.daz_actonly
morphdic = getMorphs(rig, "ALL", activeOnly=self.flg_act)
print(flg)
for key in morphdic.keys():
rig[key] = 0.0
update_prop(context, rig)
return{'FINISHED'}
Then usually we may hope to add checkbox, to decide morphs which we clear. so I add new boolean property for the Class as "flg_act" (It is my first plan) but I can not find way to use the flg_act directry to show checkbox for UI layout.
After all, to get checkbox in panell which user change to set flg_act for this Operator. (and the Operator should be locate in panell as button)
I need to set new bpy.types.Scene.Property, when register class. (I learn there is many way to add new property (propertygroup with PointerProperty etc) but everytime I serch more simple way, to show checkbox for my Operator in panell.
Is not there more efficent way, which directly set the Operator class flag as check box in panell? or we must need to use bpy.types.Scene.newflag = BoolProperty(....) when register, then set the ID for layout? or I simply missing some basic things? (there is no need to add new boolproperty, because I already set boolproperty in the "WIF_OT_clearDazMorphs" then can directly show checkbox in layout along with the operator button?
So what I really hope to know is if there is another way, what I currently did to achive it,
I need to add row.prop to get checkbox. (act = bpy.context.active_object)
box.label(text = "Reset morphs value")
row = box.row()
row.prop(act, "daz_actonly",text = "active only")
row.operator("object.clear_dazmorph", text = "Clear morphs")
And to get it work, I need to add property for Scene or Object (about this case I prefer add new property for object)
Then I need to describe it in
def register():
from bpy.utils import register_class
bpy.types.Object.daz_actonly = BoolProperty(
name="daz_actonly",
description="clear active morphs only",
default = False
)
for cls in classes:
register_class(cls)
Though it work, but the more flag or checkbox for current add on, everytime I need to set new props for scene or object. Then I hope to know if there is way to add checkbox from Operator flag property. (current way not add new property for Operator class (I need not))
or if I can add new prop for the Panell , but I can not make it work, without add new prop for Scene or Object etc.. when register.
Or if there is way directly declare new property for panel, I may hope to know. (I could not edit it work as check box,, if someone can show real code, (it work more efficently, I really apreciate it.. teach me please)
BoolPropertyfor the panel and anotherBoolPropertyfor the operator, then pass the UI property value to the operator, see: https://blender.stackexchange.com/a/2516/31447 This way you can still call the operator from F3 menu and pass a custom value per call. – brockmann Dec 06 '20 at 15:25