vertex groups extension and accessing blender's ui

Hi
I was writing my (first) small scripts in my last freelance gig to optimize my workflow. I think it should be very handy for other people who work with realtime engines and need to optimize their vertex groups, so I was thinking to wrap it up into an add-on together with another vertex group script that i found on the internet.
but before publishing it i need some helper from other blender python experts.

The first thing that i needed was something to display how many vertex groups are currently in the active object. (correct me if Im wrong but i couldn’t find it anywhere displayed)
I was just displaying it in the report bar in the info header, which was easy but i thought it would make more sense to display it always in the statistics in the info header.
I was wondering if there is away to access the bpy.data.scenes[“scene”].statistics() function and to change it. or to access the header class - INFO_HT_header from outside and just to add it into the row.label
currently the only way i managed to achieve this is kind of a hack. I just copied the class from space_info.py using edit source into a new script and just added the 3 lines of code.


the second thing i wrote was something that calculates how many vertex groups are used by the influencing armature, and then displaying the names of the groups in report bar and console.

the third option is to clean empty groups and groups with zero vertexes which is actually a script that i found somewhere around. I thought to add it also under the vertex_group_specials option inside blender`s ui. but again the only solution i know is the same hack I used for the display number of vertex groups

would be nice to hear on proper and short solution, also if someone has more ideas for extending vgroups options please let me know.
I would also like to know what is the natural place to upload wip blender scripts? github?

Thanks for any help

Tal

  1. Count them!

  2. You basically need to iterate though all vertices and determine their weight before you can do that. Maybe see related addons, I remember some to adjust weights in N panel or draw weights in viewport

  3. You can append or prepend draw functions to menu type classes

import bpy

def draw_func_vgroup_count(self, layout):
    layout = self.layout
    ob = bpy.context.object
    if ob is None: return
    layout.label("Vertex groups: %i" % len(ob.vertex_groups))
    
def draw_func_vgroup_specials(self, layout):
    layout = self.layout
    layout.separator()
    layout.operator("object.select_all", text="Your Operator here")


def register():
    bpy.types.INFO_HT_header.append(draw_func_vgroup_count)
    bpy.types.MESH_MT_vertex_group_specials.append(draw_func_vgroup_specials)
    
def unregister():
    bpy.types.INFO_HT_header.remove(draw_func_vgroup_count)
    bpy.types.MESH_MT_vertex_group_specials.remove(draw_func_vgroup_specials)
    
if __name__ == '__main__':
    register()

Thanks CoDEmanX
that seem to make much more sense
I warped it up to an add-on and uploaded it together with another script into


https://developer.blender.org/T42655
its including
vertex group display, Find vertex groups not in armature (display in the info header), Remove zero vertex and Remove empty vertex groups with a threshold property.
I modified the last 2 from a script that I found around the internet (and cant find it again)

However I still have a few questions

Console writes me addon missing ‘bl_info’ gives bad performance!
I’m not sure why since i did write the bl_info

If I run the script from the text editor, then every time when i ran it it’s appending the vgroups display, and the vgroups options again and again. is there a way to avoid this? somehow to unregister() before the register()?
as an addon however it works fine.

is there a way to display the vgroups in the info header next to the statistics like i did before, and not as separated object?

Thanks for any info

a bl_info dict is require for addons, maybe it’s in the wrong scope, is incomplete or something?

Make it a proper addon and load as addon and it will not append it again and again, there’s a hacky way to avoid it if run from text editor, but i wouldn’t recommend using it.

You mean the empty space between the vgroup count and the statistics? No, that’s all hardcoded.

Hi
it seems that it is not allowed to access the ui with addons, and must be written in core blender?
https://developer.blender.org/T42655
does any one knows what is the a specific reason for it? and is it a problem if i publish it with a wiki page as an external addon?
it works fine and might be usefull for some people, but not sure if its necessary to be in core blender.

What do you mean that addons weren’t allowed to access UI? Most parts of the interface a Python scripted (the underlaying high-level function and low-level draw calls are written in C however).

sorry i meant adding operators. this is the feedback i got from the developers

operators to UI? That’s very possible, but you may also append or prepend to existing menus, headers etc. (= no control over order of items).