Complete beginner to scripting. I'm trying to create an add-on that would allow me to add a bezier curve with one single control point (vertex) at the 3d cursor.
This is what I have:
bl_info = {
"name": "Single Point Curve",
"category": "Object",
}
import bpy
class HalfBoolMirror(bpy.types.Operator):
"""Single Point Curve""" # blender will use this as a tooltip for menu items and buttons.
bl_idname = "single.point.curve" # unique identifier for buttons and menu items to reference.
bl_label = "Single Point Curve" # 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
bpy.ops.curve.primitive_bezier_curve_add(view_align=False, enter_editmode=True, location=bpy.context.scene.cursor_location, layers=(True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True))
bpy.ops.curve.handle_type_set(type='VECTOR')
bpy.context.object.data.show_handles = False
bpy.context.object.data.show_normal_face = False
bpy.ops.curve.de_select_last()
bpy.ops.curve.delete(type='VERT')
bpy.ops.curve.select_all(action='TOGGLE')
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
ctx = bpy.context.copy()
ctx['area'] = area
ctx['region'] = area.regions[-1]
bpy.ops.view3d.snap_selected_to_cursor(ctx, use_offset=False)
break
return {'FINISHED'} # this lets blender know the operator finished successfully.
def register():
bpy.utils.register_class(HalfBoolMirror)
def unregister():
bpy.utils.unregister_class(HalfBoolMirror)
if __name__ == "__main__":
register()
This gives me an error when trying to enable the addon in User Preferences. The error is
line 18 bpy.ops.curve.primitive_bezier_curve_add(view_align=False, enter_editmode=True, location=bpy.context.scene.cursor_location, layers=(True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True)) ^ TabError: inconsistent use of tabs and spaces in indentation
At some point I also got an error saying "incorrect location" or something at line 18. Unable to reproduce it now...
The script works as intended when running it in the script editor such as this:
import bpy
bpy.ops.curve.primitive_bezier_curve_add(view_align=False, enter_editmode=True, location=bpy.context.scene.cursor_location, layers=(True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True))
bpy.ops.curve.handle_type_set(type='VECTOR')
bpy.context.object.data.show_handles = False
bpy.context.object.data.show_normal_face = False
bpy.ops.curve.de_select_last()
bpy.ops.curve.delete(type='VERT')
bpy.ops.curve.select_all(action='TOGGLE')
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
ctx = bpy.context.copy()
ctx['area'] = area
ctx['region'] = area.regions[-1]
bpy.ops.view3d.snap_selected_to_cursor(ctx, use_offset=False)
break
But I can't get it to work as an Addon.