UI scripting problem


First of all, I’m sorry If I couldnt explain my problem well, I’ll do my best, excuse my low understanding of the blender python scripting, and feel free to ask me if you wish.

I was scripting some ui panels for my rigs, and while experimenting, I run into some problems.
Doing some researchers, I found that there are two sides of the ui scripting, (panels and operators).

First let me tell you how I think an operator would work, and please correct me if I’m wrong. Logically I think an operator would need at least 2 things to work, most importantly the action, and a text, (and maybe some other things like icons and so).

But when I wanted to make some buttons using the operators, actually it was a bit confusing.

In the #LayoutPanel(bpy.types.Panel)# for example I made #row.operator(“object.button”, text=“button”)# for me I have no idea how the “object.button” works, I made an assumption that it could be a special blender thing for drawing buttons, but I found that isnt correct, because that part can be also used to execute an action, for example replacing “object.button” with will make it execute a mode toggle action.

Another problem, is how can I know those special writings to execute my actions? the edit mode toggle was an easy thing to guess cuz its “bpy.ops.object.posemode_toggle()”, whats about other actions that doesn’t have a “bpy.ops.object”?

My second problem is in the class that does the execution (if that’s correct), which has a funny name like “OBJECT_OT_Button”.
I also found that I can specify any action in the execution function, and it works as sweet as expected (which is confusing because we can already execute actions in the LayoutPanel class), but the more important thing, I have no idea how I can link an action in the “execution class” to one of my panels in the LayoutPanel class.

Again I’m so sorry if I sound too confusing, I only hope that you got my point, and Thanks in advance :).

edit: the main problem is solved, but if any body wishes to clarify or add anything, that would be great :slight_smile:

an operator is basically a tool
anything you do in blender (other than directly editing a property) is gonna be an operator.
so “object.button” needs to be the bl_idname of the operator you are trying to put in the button, like “transform.translate” or “object.editmode_toggle” etc…
or if you made an operator in your script, just copy/paste it’s bl_idname there.
the second part is just a user visible text (where you wrote “button”) so “Click” or “Translate” etc…

in the bpy.ops.object.posemode_toggle() the idname is “object.posemode_toggle”

anything between bpy.ops. and () is the idname. idname must contain a . in it.
If you want to see a bit more graphically you can check my tutorial on blender cookie, has a part about the bl_idname

Thanks a lot Bassam !!, thats really helpful, I kinda find the solution, I had to use more than one executing class, each one with a specific bl_idname that uses a specific action, and it worked , I have no idea if thats how I’m supposed to do it, but at least it worked ^_^.

hi bassam.any information about wires of emphaty.

if any one has anything to add or share anything useful feel free, I would be so happy !