Created
October 10, 2021 21:00
-
-
Save CheeryLee/91172f28a9db98e225f58232dc7d830f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
bl_info = { | |
"name": "Change curve extreme points radius", | |
"author": "Alexander Pluzhnikov", | |
"version": (1, 0), | |
"blender": (2, 80, 0), | |
"location": "View3D", | |
"description": "Change curve extreme points radius with UI dialog", | |
"category": "3D View" | |
} | |
class SetRadiusProps(bpy.types.PropertyGroup): | |
radius: bpy.props.IntProperty( | |
name = "Radius", | |
default = 1) | |
class OT_CurveExtremePointsRadius(bpy.types.Operator): | |
bl_label = "Change extreme points radius" | |
bl_description = "Change extreme points radius" | |
bl_idname = "curve.change_extreme_points_radius" | |
def execute(self, context): | |
splines = self.__get_active_splines() | |
props = bpy.context.scene.set_extreme_points_radius | |
if (len(splines) == 0): | |
self.report({ 'ERROR' }, 'No splines selected') | |
return {'CANCELLED'} | |
self.__change_radius(splines, props.radius) | |
return {'FINISHED'} | |
def invoke(self, context, event): | |
return context.window_manager.invoke_props_dialog(self, width = 200) | |
def draw(self, context): | |
layout = self.layout | |
props = bpy.context.scene.set_extreme_points_radius | |
layout.prop(props, "radius") | |
def __get_active_splines(self) -> list: | |
obj_data = bpy.context.active_object.data | |
splines = [] | |
for spline in obj_data.splines: | |
spline_found = False | |
for point in spline.bezier_points: | |
if spline_found: | |
break | |
if point.select_control_point: | |
splines.append(spline) | |
spline_found = True | |
continue | |
return splines | |
def __change_radius(self, splines: list, value: int): | |
for spline in splines: | |
points_count = len(spline.bezier_points) | |
spline.bezier_points[0].radius = value | |
spline.bezier_points[points_count - 1].radius = value | |
def show_change_curve_extreme_points_radius(self, context): | |
self.layout.operator("curve.change_extreme_points_radius") | |
def register(): | |
bpy.utils.register_class(SetRadiusProps) | |
bpy.utils.register_class(OT_CurveExtremePointsRadius) | |
bpy.types.Scene.set_extreme_points_radius = bpy.props.PointerProperty(type = SetRadiusProps) | |
bpy.types.VIEW3D_MT_edit_curve.append(show_change_curve_extreme_points_radius) | |
def unregister(): | |
bpy.utils.unregister_class(SetRadiusProps) | |
bpy.utils.unregister_class(OT_CurveExtremePointsRadius) | |
bpy.types.VIEW3D_MT_edit_curve.remove(show_change_curve_extreme_points_radius) | |
del(bpy.types.Scene.set_extreme_points_radius) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment