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.