2.5 tool panel list box ?

is there an example of a script showing how to add in tool panel a list box with other vars or buttons?

Thanks

Just a regular box?

props = self.properties
layout = self.layout

col = layout.column() #make column

box = col.box() #make box
box.prop(props, 'prop_name') #put in box

col.prop(props, '...') #out of box

No, you probably mean like “Mesh Tools”, “Object Tools”, and such, hold on…

Here is a little script I made that simply adds 4 buttons in the tool panel in it’s own box: http://www.pasteall.org/13584/python

So basically:

import bpy
from bpy.props import *

class VIEW3D_OT_Global_Shading(bpy.types.Panel): #make panel
    '''Tool Panel Box'''
    bl_label = "Tool Panel Box"
    bl_space_type = "VIEW_3D" #in 3D view
    bl_region_type = "TOOLS" #in tool panel

    def draw(self, context): #draw all the options and stuff
        layout = self.layout

        col = layout.column()
        col.label('Hello world.')

def register():
    bpy.types.register(VIEW3D_OT_Global_Shading)

def unregister():
    bpy.types.unregister(VIEW3D_OT_Global_Shading)

if __name__ == "__main__":
    register()

Running that code will add a box in the tool panel.

nice little examples for box and text ect…

but don’t see any list box or combo box or menu box

a box where you can select one of several values

if it exist yet !

a little bit like when adding a sub menu in the add menu

i don’t remember seeing one like that before !

but hope it can be done

note: i have to read the values for this menu box in the main part i guess or from a function
then be able to transfert theses to the menu inside some class

Thanks for the example i’ll keep theses in a note file for futur use

Okay, well there’s different ways to make a list/combo/menu box but I hope this is what you want. The comments should explain what’s going on.

Run this then check the tool shelf in the 3D view:

import bpy
from bpy.props import *

#For the non-operator menus, define their values like this:
bpy.types.Scene.EnumProperty(attr='method', name='Method', items=(
    ('1', 'One', 'The first item'),
    ('2', 'Two', 'The second item'),
    ('3', 'Three', 'The third item')), default='1')

#These are stored in the .blend

#And for one without a label before it make the first element the name
bpy.types.Scene.EnumProperty(attr='nameless', items=(
    ('0', 'Choose one', 'Choose one'),
    ('1', 'One', 'The first item'),
    ('2', 'Two', 'The second item'),
    ('3', 'Three', 'The third item')), default='1')

#For the operator menu this variable just stores the last operation called
last_method = 'None'

class myPanel(bpy.types.Panel):#This is the panel
    '''Panel'''
    bl_label = "Menu Examples"#Called this
    bl_space_type = "VIEW_3D"#in 3D view
    bl_region_type = "TOOLS"#in tool shelf

    def draw(self, context):
        global last_method#make this global to find the last operation

        layout = self.layout

        col = layout.column()
        col.label(' A menu that executes operators:', 'UI')
        col.operator_menu_enum('view_3d.my_operator', 'method', 'Operate')#Here the operator menu is displayed
        #'view_3d.my_operator' is the bl_idname of the operator called
        col.label(' Last: ' + last_method, 'QUESTION')
        
        col.separator();col.separator();col.separator()

        col.label(' A menu that changes a property:', 'UI')
        col.prop(context.scene, 'method')#Here is the property menu
        col.label(' Current: ' + context.scene.method, 'QUESTION')
    
        col.separator();col.separator();col.separator()

        col.label('...and one without a name:', 'UI')
        col.prop(context.scene, 'nameless') #'nameless' is the attr attribute in the enum defined at the top
        col.label(' Current: ' + context.scene.nameless, 'QUESTION')


class myOperator(bpy.types.Operator):#When an option in the operator menu is clicked, this is called
    '''Operator'''
    bl_idname = 'view_3d.my_operator'
    bl_label = 'Operator'
    
    #Define possible operations
    method = EnumProperty(items=(
        ('1', 'One', 'The first item'),
        ('2', 'Two', 'The second item'),
        ('3', 'Three', 'The third item')))

    def execute(self, context):
        global last_method#Make global so we can later draw it in the panel

        last_method = self.properties.method#Store the choosen operation
        return {'FINISHED'}

def register():
    bpy.types.register(myOperator)
    bpy.types.register(myPanel)

def unregister():
    bpy.types.unregister(myOperator)
    bpy.types.unregister(myPanel)

if __name__ == "__main__":
    register()

looks very nice thanks for theses examples
i’ll keep this on a python notefile !

Now i have to study how it is done but seems very cool

you even included some icons !

Thanks and happy 2.5

I’m trying to work on a script which add buttons in tool panel

but it looks like there may be more then one way may be to add buttons!

the script i have does not define a panel it simply add buttons to the tool panel
it works a little bit like the script for pipe add ons
so i’m adding a menu to the add menu then after selection do a function
and input slider buttons are added to the tool panel without defining a panel in the tool panel!

it uses buttons like this one

base1 = FloatProperty(name=“Base”,
description=“Base of Triangle”,
default=5.0, min=1, max=100.0)

but not certain why it ends up in the tool panel
why not some other panel ?

so do i have to redo my script and define a new panel in the tool panel to use the menu buttons or other button like labels ect… for instance like the script you did ?

Thanks & happy 2.5

As far as I know everything needs to be in a box – nothing can be added directly on the tool panel. If you can copy your script here I’ll look at it. If you’re just making an add mesh operator then why put it in the tool panel at all? Just add it to the add mesh menu. I don’t really know what you’re going for…

Here is code that adds a menu in the add mesh menu, like pipe joints:

from bpy.props import *

class AddTriangle(bpy.types.Operator):
    bl_idname = "mesh.triangle_add"
    bl_label = "Triangle"
    bl_options = {'REGISTER', 'UNDO'}

    #triangle code
    base1 = FloatProperty(name="Base", description="Base of Triangle", default=5.0, min=1, max=100.0)
    
    def execute(self, context):
        print('Add a triangle')
        return {'FINISHED'}

class INFO_MT_triangles_add(bpy.types.Menu):
    bl_idname = "INFO_MT_triangles_add"
    bl_label = "Triangles"

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_REGION_WIN'
        layout.operator("mesh.triangle_add", text="Triangle")

menu_func = (lambda self, context: self.layout.separator() & self.layout.menu("INFO_MT_triangles_add", icon='PLUGIN'))

def register():
    bpy.types.register(AddTriangle)
    bpy.types.register(INFO_MT_triangles_add)
    bpy.types.INFO_MT_mesh_add.append(menu_func)

def unregister():
    bpy.types.unregister(AddTriangle)
    bpy.types.unregister(INFO_MT_triangles_add)
    bpy.types.INFO_MT_mesh_add.remove(menu_func)

if __name__ == "__main__":
    register()

it’s almost done like the last script
and working ok to be added to the add ons

but still need to add some functions for special triangle calculation
like Cos sin and tan law’s

except i did not have the added class where the menu is defined
but it’s all the other buttons that i’m not ceetain how to add theses

let me test this a little bit and i’ll be back tomorrow

the script i have is already close to 1600 lines
with all the functions and i’ have to try to find a way to reduce the size somehow before i release it !
also it’s filled up with print line on console for debugging purposes so need to clean that up

but i’ll try to make a shorter version with only 2 functions to show how it works tomorrow
and load it up

Thanks & happy 2.5

Triangle script
here is a picture showing the screen and new tool panel with one of the script function

and also on bottom picture what i would like to add as buttons of general info on triangles

http://cid-348ad7d85dee0c79.photos.live.com/self.aspx/2.5newscript1/pic2.jpg

addons folder
sorry i did no test it yet but think this should work in the add ons folder too!
right now i’m more concern with adding buttons to complete the tool panel
and giving all info to user and completing all the different triangle function
for this script !

i’v redone a shorter version of the script which you can find here
you can run this in the text editor then select the add menu on top header
and then select last item = triangle
and in the sub menu select one triangle function
this add some buttons in tool panel which allow to adjust the size angle ect.
of the triangle
see picture showing the screen with the tool panel

#####################################

Problems i have now

1 - adding some new buttons
like check box with boolean var
label box and text box

2 - New menu in tool panel
moving the submenu into the tool panel would give a faster access to the different
triangle in my script!
as you said may be it would be worth to add the submenu inside the tool panel
but don’t knwo how this would work cause each time you select a different triangle
the buttons have to change !

3 - Try to simplify the functions
like the data shown for triangle is the same for all triangle
so this could be put in a function outside maybe !

i was unable to load up the short version of the script here
too long > 1000 words

so here is link to download the blend file

http://cid-348ad7d85dee0c79.photos.live.com/self.aspx/2.5newscript1/shorttriang1.blend

Thanks and happy 2.5 with triangles

would apprecaite a lot if anybody would help to complete this script so i can release this

Thanks for any help

Ricky, If you want to add more buttons, you just have to add properties to your operator, the ui is totally automatic if you don’t define your own draw function inside the operator. If you want your own custom look(I as user am always strongly against that), look e.g. into curve_simplify addon, which now should be in extensions, there is a draw function inside the operator.
good luck :slight_smile:

i can draw different panel buttons i’v seen some example of this before
with the draw function

but i got a few questions here

1-
how do you add a check box propertie button?
never seen this one before!
is there a doc page that show all the buttons that can be added with an example for each type of buttons available?
like int , float , check box ,menu , label ,text and may be more button type !

2- difference between my panel definition and the
panel from given example for adding menu in tool panel

it looks like there is more then one way to add a panel i think or may be not!

in my script i did where does it says that this has to be added to the tool panel?

3 - new added panel location in tool panel
it looks like the tool panel has 2 parts
the top and bottom part !

in the other panel for menu example i can see where it is added to the tool panel but not in my script !

for my script seems that buttons are added at the bottom part of the tool panel
but in the case of the menu script given it’s added to the top part of the tool panel

so why the difference and how to change or control this panel location ?

Thanks

1
The different types of properties you can make are all listed here: http://www.blender.org/documentation/250PythonDoc/bpy.props.html
Anything with Bool in it’s name is a checkbox.

2
It doesn’t have to be added to the tool panel. (?)

3
The position of boxes in the tool panel is stored in the .blend, perhaps this is why.

Hi !

I have expanded previous example that shows how you can put in a panel:

  • color picker
  • check boxes
  • menu (diferent kinds)

Please, note that it is bad done, I mean I save all properties on the Scene (custom properties panel of the scene) and then, those values are just showed in a toolshelf panel when I create the property with:


bpy.types.Scene.FloatVectorProperty(  attr = 'FloatVector' + subtype, default = [0.0, 0.0, 0.0], subtype= 'TRANSLATION')

At the end, a floatVector is just an array of 4 float numbers, but they can be shown as a color picker, distance, translation, etc. That’s the importance of the “subtype” parameter.

Ok, now the long code xD




import bpy
from bpy.props import *

#For the non-operator menus, define their values like this:
bpy.types.Scene.EnumProperty(attr=‘method’, name=‘Method’, items=(
(‘1’, ‘One’, ‘The first item’),
(‘2’, ‘Two’, ‘The second item’),
(‘3’, ‘Three’, ‘The third item’)), default=‘1’)

#These are stored in the .blend

#And for one without a label before it make the first element the name
bpy.types.Scene.EnumProperty(attr=‘nameless’, items=(
(‘0’, ‘Choose one’, ‘Choose one’),
(‘1’, ‘One’, ‘The first item’),
(‘2’, ‘Two’, ‘The second item’),
(‘3’, ‘Three’, ‘The third item’)), default=‘1’)

#For the operator menu this variable just stores the last operation called
last_method = ‘None’

subtypes = [‘COLOR’, ‘TRANSLATION’, ‘DIRECTION’, ‘VELOCITY’, ‘ACCELERATION’, ‘MATRIX’, ‘EULER’, ‘QUATERNION’, ‘AXISANGLE’,‘XYZ’, ‘COLOR_GAMMA’, ‘LAYER’]#, ‘NONE’]
for subtype in subtypes:
bpy.types.Scene.FloatVectorProperty( attr = ‘FloatVector’ + subtype, default = [0.0, 0.0, 0.0], subtype= subtype)

bpy.types.Scene.BoolProperty( attr = ‘MyBoolProperty’, default = True)

floatsubtypes = [‘UNSIGNED’, ‘PERCENTAGE’, ‘FACTOR’, ‘ANGLE’,‘TIME’, ‘DISTANCE’]
for subtype in floatsubtypes:
bpy.types.Scene.FloatProperty( attr = ‘Float’ + subtype, subtype= subtype)

stringsubtypes = [ ‘FILE_PATH’, ‘DIR_PATH’, ‘FILENAME’]
for subtype in stringsubtypes:
bpy.types.Scene.StringProperty( attr = ‘String’ + subtype, subtype= subtype)

class myPanel(bpy.types.Panel):#This is the panel
‘’‘Panel’’’
bl_label = “Menu Examples”#Called this
bl_space_type = “VIEW_3D”#in 3D view
bl_region_type = “TOOLS”#in tool shelf

def draw(self, context):
    global last_method#make this global to find the last operation

    layout = self.layout
    scene = context.scene

    col = layout.column()

col.label(’ A menu that executes operators:’, ‘UI’)

col.operator_menu_enum(‘view_3d.my_operator’, ‘method’, ‘Operate’)#Here the operator menu is displayed

#‘view_3d.my_operator’ is the bl_idname of the operator called

col.label(’ Last: ’ + last_method, ‘QUESTION’)

col.separator();col.separator();col.separator()

col.label(’ A menu that changes a property:’, ‘UI’)

col.prop(context.scene, ‘method’)#Here is the property menu

col.label(’ Current: ’ + context.scene.method, ‘QUESTION’)

col.separator();col.separator();col.separator()

col.label(’…and one without a name:’, ‘UI’)

col.prop(context.scene, ‘nameless’) #‘nameless’ is the attr attribute in the enum defined at the top

col.label(’ Current: ’ + context.scene.nameless, ‘QUESTION’)

    col.separator()
    col.label('just a bool property:')
    col.prop(scene, "MyBoolProperty", text = "the bool prop label")

    col.separator()        
    col.label('float Vector Properties:') 
    for sub in subtypes:
        col.prop(scene, 'FloatVector' + sub)

    col.separator()        
    col.label('Float Properties with different subtype') 
    for subtype in floatsubtypes:
        col.prop(scene, 'Float' + subtype, text = subtype)

    col.separator()        
    col.label('String Property') 
    for subtype in stringsubtypes:
        col.prop(scene, 'String' + subtype)

    # next fourth are the same property, just we use a different
    # way to show interface
    col.separator()        
    col.label('prop:') 
    col.prop(scene, 'nameless')

    col.separator()        
    col.label('prop (expand = True):') 
    col.prop(scene, 'method', expand = True)


    col.separator()        
    col.label('prop enum') 
    col.prop_enum(scene, 'method', "1")


    col.separator()        
    col.label('props_enum nameless:') 
    col.props_enum(scene, 'nameless')


    col.separator()        
    col.label('prop_menu_enum nameless:') 
    col.prop_menu_enum(scene, 'nameless', text = "prop_menu_enum")

    
    col.template_operator_search()

class myOperator(bpy.types.Operator):#When an option in the operator menu is clicked, this is called
‘’‘Operator’’’
bl_idname = ‘view_3d.my_operator’
bl_label = ‘Operator’

#Define possible operations
method = EnumProperty(items=(
    ('1', 'One', 'The first item'),
    ('2', 'Two', 'The second item'),
    ('3', 'Three', 'The third item')))

def execute(self, context):
    global last_method#Make global so we can later draw it in the panel

    last_method = self.properties.method#Store the choosen operation
    return {'FINISHED'}

def register():
bpy.types.register(myOperator)
bpy.types.register(myPanel)

def unregister():
bpy.types.unregister(myOperator)
bpy.types.unregister(myPanel)

if name == “main”:
register()



That's why I can not create a listbox for example, because on python code we only see "col.prop(ob, "materials", material, "material_active_index").. but we don't know how it is defined.

Cheers

i save that page very interesting will be usefull in futur

but how does it make it added in the tool panel i my little script?

see following example of class for a function
and how does the float properti goes to the tool panel?
is it the only panel it can be added may be ?



	
class Add4545Triang(bpy.types.Operator):
	
	'''Add a 45 D X 45 D Triang   mesh.'''
	
	bl_idname = "mesh.primitive_4545TrianRect_add"
	bl_label = "Add 45X45_Tri_BH"
	bl_options = {'REGISTER', 'UNDO'}
	
	base1 = FloatProperty(name="Base",
		description="Base of Triangle",
		default=10.0, min=1, max=100.0)
	
	def execute(self, context):
		base1 = self.properties.base1
	
		verts = []
		faces = []
		verts_new = []
		faces_new = []
		
		
		name="4545Triangle"
		print (name)
	
	
# Make rectangle triangle with base and height
	

			
			
			



i don’t see anything saying that it has to go inot tool panel ?
there must be something somewehre saying that’s where it ahs to go ?

Thanks

in the function if i add a float property
it can be written like this

base1 = BoolProperty(name=“boolean”,
description=“boolean prop”,
default=10.0, min=1, max=100.0)

by the way is there a way to change the default values here
with a variable value determined by another property before defining a property?

i tried it and it does not recognise it !

############

but how to write it for a boolean prop

bpy.props.BoolProperty(name="", description="", default=False, options={‘ANIMATABLE’}, subtype=‘NONE’)Returns a new boolean property definition.
Parameters:

  • options (set) – Enumerator in [‘HIDDEN’, ‘ANIMATABLE’].
  • subtype (string) – Enumerator in [‘UNSIGNED’, ‘PERCENTAGE’, ‘FACTOR’, ‘ANGLE’, ‘TIME’, ‘DISTANCE’, ‘NONE’].
    what are all these parameters any example on how to write it down in a function?

and don’t see this paramete in first line ?

an example would be nice to get an idea on how to write this
and the use of parameter !

Thanks

You must undersand that properties created inside the operator class has a short life. It only lives meanwhile operator is running. Once Operator finish, they are removed from memory, you can not access to them anymore.

That’s why I created all properties on the scene, because all properties added to the scene are “ID properties” and you can save/restore values to/from there.

That is: if you want that a property has a value readed before the property is created, that value need to be saved anywhere, on the scene, on the actual object, etc…

Your class will never be added to the tool panel, it always is added to the Operator panel that is bellow “Object Tools” on the “Tool Shelf” panel.

your fixed code:


from bpy import *
from bpy.props import *
    
class Add4545Triang(bpy.types.Operator):
    
    '''Add a 45 D X 45 D Triang   mesh.'''
    
    bl_idname = "mesh.primitive_4545TrianRect_add"
    bl_label = "Add 45X45_Tri_BH"
    bl_options = {'REGISTER', 'UNDO'}
    
    base1 = FloatProperty(name="Base",
        description="Base of Triangle",
        default=10.0, min=1, max=100.0)

    base2 = FloatProperty(name="Base2",
        description="hidden property that doesn't appear on Operator panel",
        default=10.0, min=1, max=100.0,
        options = {'HIDDEN'})

    
    theBoolean = BoolProperty(  name= "my bool", 
                                description = "my boolean value", 
                                default = False
                            )

    hiddenBoolean= BoolProperty(name = "second bool", 
                                description = "bool property hidden on Operator panel",
                                default = False,
                                options = {'HIDDEN'}
                            )

    def execute(self, context):
        base1 = self.properties.base1
    
        verts = []
        faces = []
        verts_new = []
        faces_new = []
        
        
        name="4545Triangle"
        print (name)
        return {'FINISHED'}

    
    
# Make rectangle triangle with base and height

bpy.types.register(Add4545Triang)
  • run it
  • On 3D view press Space -> search for “45”, click on your Add45x45 blah blah
  • look at the Operator Panel on Shelf Tool and change the “Base property”

You will see that two properties are hidden on the Operator :wink:

Note that if you press “A” key on 3D View, your operator will disappear from the “Operator Panel”, this is the new Blender behaviour, your Operator has dead !!

nice tricks nere !

theses hidden prop

i mean where can you change theses values if they are hidden ?

now you say that all vars prop are automatically added at the bottom of tool panel
by default or as you called it the operator panel

not the upper part of the tool panel!

cause the example for menu earlier is adding things to the upper tool panel part !
but it i indicated in the class definition!

2 - value of check button in tool panel UI

i defined one  and when i change it in the operator panel it works fine

but if i change it inside the execute function inside the script
it does not change the UI tool panel drawing of the check button
the panel is not updated is this a bug or normal?

3 - i’ll come back on the pre defining the max min value of a button before it is added
don’t know if there is a way here to do this

cause i would like to pre set some min max value from another button

like the curvature radius function of the dimensions of an object

Thanks

Écrivain code says:


class myPanel(bpy.types.Panel):#This is the panel
    bl_space_type = "VIEW_3D"#in 3D view
    bl_region_type = "TOOLS"#in tool shelf

That mean it is inheriting from a Panel behaviour on the VIEW_3D at the Tool Shelf

But your code say:


class Add4545Triang(bpy.types.Operator):

Behaviour is Inherited from an Operator not a Panel !! :stuck_out_tongue:

EDIT:
The main differences is that an Operator will be triggered by user actions or by a script, then it will run.
A panel is automatically shown when the context change (for example you toggle from object mode to edit mode and then Blender hide all panels related to Object mode, and show panels related to Edit mode).

If you want a Panel, you need to inherite from a Panel.
If you want an Operator, obviously you need to inherite from an Operator.

If you want both things, then you need to do both things at the same time. Create an Operator an register it on Blender, then Create a Panel and include the operator in the Panel as Écrivain posted above, now you can register your Panel. If you see some standars scripts that come with Blender, they uses both things, Operators and panels.

learning more and more and very interesting!

then what would be an operator definition?

are theses only input buttons ?
or can be other things too

and are there output buttons for operator ?

2 - vector operator

FloatVectorProperty

triple1 = FloatVectorProperty(name=“Vector XYZ”,
description=“Vector”,
default=(1.0,2.0,3.0), min=1, max=100.0)

is there a double float available or only triple ?

what are the other values that we can add like min or max
are theses triple also?
when i print this triple1 i get a text phrase instead of numbers
but i can print triple1[0]
is there a way to transfert this vector to another var?

Thanks