You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey. What's wrong with my script? It works on selected objects in the text editor but when I load it into your button , it does nothing. Here's the script:
importbpyimportrandomimportmathdeffind_similar_object(selected_object, objects_to_compare, threshold_volume, threshold_center):
forobjinobjects_to_compare:
ifobj!=selected_object:
ifabs(selected_object.dimensions[0] *selected_object.dimensions[1] *selected_object.dimensions[2] -obj.dimensions[0] *obj.dimensions[1] *obj.dimensions[2]) <=threshold_volume:
center_dist= (selected_object.location-obj.location).lengthifcenter_dist<=threshold_center:
returnobjreturnNonedefassign_new_name(obj, new_name):
obj.name=new_namedefcalculate_center_of_geometry(obj):
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.context.view_layer.objects.active=obj# Store current object's location and origin pointoriginal_location=obj.location.copy()
original_origin=obj.location.copy() # Store original origin# Set the origin to the center of geometrybpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')
# Calculate the center of geometrycenter_of_geometry=obj.location.copy()
# Restore original originobj.location=original_origin# Restore original locationobj.location=original_locationreturncenter_of_geometrydefhas_high_vertex_count(obj, other_obj):
returnlen(obj.data.vertices) >len(other_obj.data.vertices)
defhas_bevel_modifier(obj):
returnany(mod.type=='BEVEL'formodinobj.modifiers)
defhas_subdivision_modifier(obj):
returnany(mod.type=='SUBSURF'formodinobj.modifiers)
defhas_hp_material(obj):
returnany(mat.name=="HP"formatinobj.data.materials)
defmain():
threshold_volume=0.01threshold_center=0.1selected_objects=bpy.context.selected_objectsfori, selected_objectinenumerate(selected_objects):
ifi<len(selected_objects) -1:
remaining_objects=selected_objects[i+1:]
similar_object=find_similar_object(selected_object, remaining_objects, threshold_volume, threshold_center)
ifsimilar_object:
similar_objects= [selected_object, similar_object]
random_name=''.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') for_inrange(10))
forobjinsimilar_objects:
assign_new_name(obj, random_name)
ifhas_high_vertex_count(similar_objects[0], similar_objects[1]) or \
has_bevel_modifier(similar_objects[0]) or \
has_subdivision_modifier(similar_objects[0]) or \
has_hp_material(similar_objects[0]):
assign_new_name(similar_objects[0], random_name+"_high")
assign_new_name(similar_objects[1], random_name+"_low")
else:
assign_new_name(similar_objects[1], random_name+"_high")
assign_new_name(similar_objects[0], random_name+"_low")
bpy.ops.object.select_all(action='DESELECT')
forobjinselected_objects:
obj.select_set(True)
if__name__=="__main__":
main()
Version Information:
Blender version 3.3.0
Addon 2.1.6
Script is supposed to auto-name selected meshes with a random name depending on which mesh is high poly and which is low poly in a group of meshes.
The text was updated successfully, but these errors were encountered:
Hey. What's wrong with my script? It works on selected objects in the text editor but when I load it into your button , it does nothing. Here's the script:
Version Information:
Script is supposed to auto-name selected meshes with a random name depending on which mesh is high poly and which is low poly in a group of meshes.
The text was updated successfully, but these errors were encountered: