Select UV groups

I’m almost done with my Select UV groups operator. Just don’t know where to put it in the GUI yet.or how to do that.

This is how to use it:

  1. in editmode, select one or more faces
  2. click the button
  3. it will grow the selection from the selected faces, to select all connected faces until it finds a seam. This can be really handy when UV mapping.

I’d like to add a button for it, on the uv mapping panel in editmode. How do I get it there?

Here’s the code (I still need to clean it up, fix the labels, etc):


import bpy
# version 1.3.0
# tested on 31315


class OBJECT_PT_selectuvgroups(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_context = "EDIT_MESH"
    bl_label = "Select UV Groups "
    
    display = 0
    
    def draw_header(self, context):
        layout = self.layout
        layout.label(text="", icon="PHYSICS")
    
    def draw(self, context):
        layout = self.layout
        row = layout.row()
        split = row.split(percentage=0.5)
        colL = split.column()
        colR = split.column()
        
        if self.display == 0:
            colL.operator("pipo", text="Ping")
        else:
            colR.operator("pipo", text="Pong")

#get list of selected faces. 
def getSelectedFaces(mesh):
    return [f for f in mesh.faces if f.select]

#make sure only these faces are selected. The other faces are deselected.
def setSelectedFaces(mesh, faceList):
    for face in mesh.faces:
        face.select = (face in faceList)
    
                

class OBJECT_OT_selectuvgroups(bpy.types.Operator):
    bl_label = "PingPong operator"
    bl_idname = "pipo"
    bl_description = "Move the ball"
    
    def invoke(self, context, event):
        self.report("INFO", "Doing select action")
        obj = context.active_object
        
        
        if obj:
            if obj.mode == 'EDIT':
                #set mode to object mode temporarily
                bpy.ops.object.mode_set()
                mesh = obj.data
                if mesh:
                    
                    #store currently selected faces
                    initial_selected = getSelectedFaces(mesh)
                    edge_dict = {}
                    face_dict = {}
                    eventually_selected = []
                    
                    #build edge lookup table (tuple to edge)
                    for edge in mesh.edges:
                        edge_dict[edge.vertices[0], edge.vertices[1]]=edge
                        edge_dict[edge.vertices[1], edge.vertices[0]]=edge
                    #build face lookup table (edge to face)
                    for face in mesh.faces:
                        for edge_tup in face.edge_keys:
                            edge = edge_dict[edge_tup]
                            if not edge in face_dict:
                                face_dict[edge] = []
                            face_dict[edge].append(face)
                            
                    #grow-select from these faces
                    for face in initial_selected:
                        #only do that if its not selected already by the grow algorithm
                        if not face in eventually_selected:
                            eventually_selected.append(face)
                            for edge_tup in face.edge_keys:
                                edge = edge_dict[edge_tup]
                                if not edge.use_seam:
                                    initial_selected.extend(face_dict[edge])
                    
                    setSelectedFaces(mesh, eventually_selected)
                    self.report("INFO", "selected %d faces" % len(eventually_selected))
                bpy.ops.object.mode_set(mode='EDIT')
            else:
                self.report("INFO", "wrong mode")
        return{"FINISHED"}

def select_uv_groups_button(self, context):
    self.layout.operator(OBJECT_OT_selectuvgroups.bl_idname, text="Select UV Groupa")
    

def register():
    bpy.types.VIEW3D_PT_tools_meshedit.append(select_uv_groups_button)
    
    
def unregister():
    bpy.types.VIEW3D_PT_tools_meshedit.remove(select_uv_groups_button)

if __name__ == "__main__":
    register()

There is a menu append function…

You could probably add it to the toolbox in the UV window as well…

I’;d have to look up how… but I see you have the “ping pong” move the ball example in your script… you should probably rename that stuff! Where you got those examples shows has another example of drawing to a toolbox IIRC

You probably don’t know this or you wouldn’t have written the script, but ctrl L is “select linked” which will select a UV island in teh UV/image editor…

Also, in the uv editor oif you hit ctrl-tab (or look at the header buttons) you’ll see that you can select by “island” too…

Oh, and in edit mode when you’re in face select it aready limits “select connected” to the seams!

lol, didn’t know the functionality I implemented was already there :o

anyway, it would be nice to have an overview the names for all the different panels, so that you can easily put the button for your tools in the desired position.