Created
June 16, 2025 04:57
-
-
Save corpix/6b86321ff50947467f970bf9bd8f4254 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def get_formatted_length_from_bu(length_in_blender_units): | |
scene = bpy.context.scene | |
unit_settings = scene.unit_settings | |
if unit_settings.system == 'NONE': | |
return f"{length_in_blender_units:.4f} Blender Units" | |
system_conversions = { | |
'METRIC': { | |
'KILOMETERS': 0.001, 'METERS': 1.0, 'CENTIMETERS': 100.0, | |
'MILLIMETERS': 1000.0, 'MICROMETERS': 1000000.0, | |
}, | |
'IMPERIAL': { | |
'MILES': 0.000621371, 'FEET': 3.28084, | |
'INCHES': 39.3701, 'THOU': 39370.1, | |
} | |
} | |
system_map = system_conversions.get(unit_settings.system) | |
if not system_map: | |
return f"{length_in_blender_units:.4f} Blender Units" | |
conversion_factor = system_map.get(unit_settings.length_unit) | |
if not conversion_factor: | |
return f"{length_in_blender_units:.4f} Blender Units" | |
scaled_length = length_in_blender_units * unit_settings.scale_length | |
converted_length = scaled_length * conversion_factor | |
unit_name = unit_settings.length_unit.replace('_', ' ').title() | |
return f"{converted_length:.4f} {unit_name}" | |
def show_popup(message, title="", icon='INFO'): | |
def draw(self, context): | |
self.layout.label(text=message) | |
bpy.context.window_manager.popup_menu(draw, title=title, icon=icon) | |
def show_curve_length(): | |
active_object = bpy.context.active_object | |
if active_object and active_object.type == 'CURVE': | |
total_length_bu = 0.0 | |
for spline in active_object.data.splines: | |
total_length_bu += spline.calc_length() | |
formatted_message = get_formatted_length_from_bu(total_length_bu) | |
final_message = f"Length of '{active_object.name}': {formatted_message}" | |
show_popup(message=final_message, title="Curve Length") | |
else: | |
error_message = "No active curve object selected. Please select a curve." | |
show_popup(message=error_message, title="Error", icon='ERROR') | |
show_curve_length() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment