Ive tried. Wow have I tried. My script will not work

Been trying to create a very simple yet I think useful add on that will select the next point of a curve. I have the script working. Once I try to turn it into an addon everything stops working. I read the console like it tells me to but it does not really tell me the problem. I can only assume that when I am trying to create the class is when things stop working.

Here is the script that works fine when I click on run script

import bpy


o = bpy.context.object


sel =  [(i,x) for i in o.data.splines for x,j in enumerate(i.bezier_points) if j.select_control_point]


for i in sel:
    i[0].bezier_points[i[1]].select_control_point = False


for i in sel:
    if i[1]+1 < len(i[0].bezier_points):
        i[0].bezier_points[i[1]+1].select_control_point = True
    else:
        i[0].bezier_points[0].select_control_point = True

Now when I create it to an addon is when things become a problem.

bl_info = {
    "name": "Select Next Point",
    "category": "Curve",
}

import bpy


class SelectNextPoint(bpy.context.object):
    """My Select Next Point Script"""      # blender will use this as a tooltip for menu items and buttons.
    bl_idname = "curve.select_next_point"        # unique identifier for buttons and menu items to reference.
    bl_label = "Select Next Point"         # display name in the interface.
    bl_options = {'REGISTER', 'UNDO'}  # enable undo for the operator.

    def execute(self, context):        # execute() is called by blender when running the operator.

        # The original script
        o = bpy.context.object


        sel =  [(i,x) for i in o.data.splines for x,j in enumerate(i.bezier_points) if j.select_control_point]


        for i in sel:
            i[0].bezier_points[i[1]].select_control_point = False


        for i in sel:
            if i[1]+1 < len(i[0].bezier_points):
                i[0].bezier_points[i[1]+1].select_control_point = True
            else:
                i[0].bezier_points[0].select_control_point = True
        return {'FINISHED'}            # this lets blender know the operator finished successfully.
    

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


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


# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == "__main__":
    register()

Im sure its something really obvious but as I am new to this I would appreciate someone who knows what they are doing telling me what’s wrong with my add on code above.

Also when I try to go to Install From File in User Preferences the addon never shows for me to the click the checkbox. But maybe that’s because my code has an error.

Can anybody give me a hand?

Thanks so much.

:raised_hand:

You did not explain what the issue is. You say everything stops. It is really unclear.

Also what is the actual error during install?

OK. first off. Im Sorry. I was working with this banging my head against the desk and kind of just gave up posted it on here and hoped for someone to give an answer. I did not explain that the script just errors out. I started over. Used some of the templates adjusted some things. Reviewed a couple tutorials.


And after all that I was able to get something functioning.

bl_info = {
    "name": "Select Next Curve Vertex",
    "author": "James Erickson - ExcelledSoftware and JuhaW from blenderartists",
    "version": (1, 0),
    "blender": (2, 79, 0),
    "location": "VIEW3D > Tool Shelf > zzz",
    "description": "Selects the next point or vertex in a curve",
    "warning": "Only works with curves",
    "wiki_url": "",
    "category": "Selection",
    }


import bpy


def main(context):
		#main code below written by JuhaW from blenderartists.org

    o = bpy.context.object


    sel =  [(i,x) for i in o.data.splines for x,j in enumerate(i.bezier_points) if j.select_control_point]


    for i in sel:
        i[0].bezier_points[i[1]].select_control_point = False


    for i in sel:
        if i[1]+1 < len(i[0].bezier_points):
            i[0].bezier_points[i[1]+1].select_control_point = True
        else:
            i[0].bezier_points[0].select_control_point = True

		#end of normal code all below written by James Erickson

class SelectNextCurveVertex(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "myops.select_next_curve_vertex"
    bl_label = "Select The Next Vertex"


    def execute(self, context):
        main(context)
        return {'FINISHED'}
    
class SelectNextCurveVertexPanel(bpy.types.Panel):
    """Creates a Panel in the Tool Shelf"""
    bl_label = "Select Next Curve Vertex Panel"
    bl_idname = "select_next_vertex_id"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_category = "zz"
		# draw the panel
    def draw(self, context):
        layout = self.layout

        obj = context.object
				
				#add the labels and controls
        row = layout.row()
        row.label(text="Select Next Vertex", icon='CURVE_DATA')

        row = layout.row()
        row.label(text="Current Selected: " + obj.name)

        row = layout.row()
        row.operator("myops.select_next_curve_vertex")
        
        
        


def register():
    bpy.utils.register_class(SelectNextCurveVertex)
    bpy.utils.register_class(SelectNextCurveVertexPanel)


def unregister():
    bpy.utils.unregister_class(SelectNextCurveVertex)
    bpy.utils.unregister_class(SelectNextCurveVertexPanel)

    

# allow to run from text editor
if __name__ == "__main__":
    register()

The reason this was not working before was because I did not properly set up a new panel.
This one can be installed as an addon as well.

I had an original request on this that I will post this script / addon.

Thanks so much for everyone’s help. Special thanks to JuhaW for getting me started.

You might want to name “main” to a more descriptive function name, also main has a special meaning in Python. I also recommend getting into habit of naming your classes properly, this might be an issue in 2.8.

See this

https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons