layout of buttons ?

for panels there are commands to control the locations of buttons

but is there an equivalent for operator buttons

or may be do a mix may be?

or use a dialog operator panel for each set of variables

thanks

what kind of layout of buttons, and why not in a panel?

i’m trying to keep the auto mesh data to update not to add a new object

so by using the operator menu it is easy to do that
unless there is another way to do that with panel but don’t remember !

for operator with prop i cannot control the location of buttons like when doing a panel
panel would be nicer if possible somehow
i tried it and the panel appears before running the operator class in add menu
unless there is a way to not start the panel first somehow!

at worst i might be able to add a button calling a dialog panel to change variables!

right now i got like 10 prop for buttons and it is a little bit long in the tool pro panel!

would look better if possible to have like 2 buttons per lines

thanks

not sure what you mean but maybe this is what you are after:

import bpy
from bpy.props import *

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}

    prop1 = IntProperty()
    prop2 = IntProperty()
    prop3 = IntProperty()
    prop4 = IntProperty()
    prop5 = FloatProperty()
    prop6 = FloatProperty()
    prop7 = FloatProperty()
    prop8 = FloatProperty()
    prop9 = BoolProperty()
    prop10 = BoolProperty()
    prop11 = StringProperty()

    def execute(self, context):
        for i in range(1, 12):
            print(getattr(self, "prop%i" % i))
        return {'FINISHED'}
    
    def draw(self, context):
        layout = self.layout
        flow = layout.column_flow(columns=2)
        for i in range(1, 11):
            flow.prop(self, "prop%i" % i)
        layout.prop(self, "prop11")


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()


1 Like

very interesting never seen this one before!
can you add these examples in wiki i think it would help many other peopels!
or open a sticky thread at top of forum here!

i assume the get will get all the prop for this operator
are there other functions like this flow command and on which wiki page cna we find this or other examples

thjanks

beginning to get it to work with 2 buttons per line
which is ways smaller then before!

have to see what else can be done with this

but when i change one of the prop
i get the following error

i got rid of the error for adding ob

but it is not adding ob anymore?

ii there a difference between calling a function in the execute part
or the draw part of the class ?

thanks

if i add my new button operator in the draw part of the operator
it is refusing to add ob to scene

if i add my functioncall in the execute part then it works

is there a constraint here for the draw method to add ob ?

thanks

i assume the get will get all the prop for this operator

No? It only gets “prop1” to “prop11”. Did this only for convenience, could have added each prop individually.

are there other functions like this flow command and on which wiki page cna we find this or other examples

UILayout methods:
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.UILayout.html

-> row, column, column_flow, box, split

is there a constraint here for the draw method to add ob ?

You must not add operators to the redo panel!
It may be valid to have an op that works on context.active_operator.properties, but you shouldn’t call any other op from here.

Run your operator with draw method as usual, then adjust settings in the redo panel. Op is automatically re-run.

i look back at the max index for the loops
and it is way higher then i tought

like 200 X 50 or more and each loop as around 10 calculations
i mean if i put it in draw panel and this is repeated with the draw panel it may represent 50 or 100 000 calculations per seconds
which will make any PC sluggish !

so using the draw panel is there a way to execute a func only ounce may be

otherwise i’ll have to remove this draw panel and do it wiht the execute part where i can add an operator button i think!
at least it wont make the PC sluggish!

thanks

draw() is only called on property changes

if you wanna execute an operator after user has set several options, use invoke_props_dialog()

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    prop = bpy.props.StringProperty(name="Material", maxlen=63)
    mats = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)

    @classmethod
    def poll(cls, context):
        return (context.active_object is not None and
                context.active_object.type == 'MESH')    

    def execute(self, context):
        print(self.prop)
        return {'FINISHED'}
    
    def draw(self, context):
        layout = self.layout
        layout.prop_search(self, "prop", self, "mats", icon='MATERIAL')
        
    def invoke(self, context, event):
        self.mats.clear()
        for i in range(1, 7):
            self.mats.add().name = "Material %i" % i
        return context.window_manager.invoke_props_dialog(self)


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator('INVOKE_DEFAULT')


1 Like

i tought about it!

but i think because of lenght of loops and calculations time
i have to go back to a simple panel with a custom operator to do the calculations ounce
but have to delete old object and replace with a new one i guess
at least you dont have to wait long to change parameters

thanks