Untitled
unknown
plain_text
a year ago
2.7 kB
13
Indexable
import bpy
def calc_max_distance(obj): # object scale must 1, 1, 1
return max(v.co.length for v in obj.data.vertices)
objects = bpy.context.selected_objects
ref = bpy.context.object
mesh = ref.data
ref_dis = calc_max_distance(ref)
if ref_dis == 0.0: zero_not_working
for ob in objects:
fac = calc_max_distance(ob) / ref_dis
ob.data = mesh
ob.scale = fac, fac, fac
# clear unused data-block
meshes = bpy.data.meshes
for mesh in meshes:
if mesh.users == 0: meshes.remove(mesh)
import bpy
def process_selected_objects():
# Store the currently selected objects
selected_objects = bpy.context.selected_objects
# Ensure there are selected objects to process
if not selected_objects:
print("No objects selected.")
return
# Loop through each selected object and perform an action
for obj in selected_objects:
# Set the object as active
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
print(f"Processing object: {obj.name}")
# Ensure there's an active object
if bpy.context.active_object is not None:
# Switch to Edit Mode if currently in Object Mode
if obj.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
print("Switched to Edit Mode.")
else:
print("Already in Edit Mode.")
else:
print("No active object to switch modes.")
continue
# Select all faces in edit mode
bpy.ops.mesh.select_all(action='SELECT')
# Fix Orientation
area_type = 'VIEW_3D'
areas = [area for area in bpy.context.window.screen.areas if area.type == area_type]
bpy.context.scene.tool_settings.use_transform_data_origin = True
with bpy.context.temp_override(area=areas[0]):
bpy.ops.transform.create_orientation(use=True)
bpy.ops.object.editmode_toggle()
transform_type = bpy.context.scene.transform_orientation_slots[0].type
bpy.ops.transform.transform(mode='ALIGN', orient_type='Face')
bpy.ops.transform.delete_orientation(0)
bpy.context.scene.tool_settings.use_transform_data_origin = False
# Switch back to object mode after operation
bpy.ops.object.mode_set(mode='OBJECT')
# Deselect the object after processing to avoid interference
obj.select_set(False)
# Reselect all objects at the end (optional)
for obj in selected_objects:
obj.select_set(True)
# Execute the function
process_selected_objects()Editor is loading...
Leave a Comment