Smart batch orientation of local axes on multyple objects?

Hello

I have a structure composed of many cylenders (maybe later it will be more complexe shapes).

And the local axes orientation of each cylender is wrong (based on global).

I know how to set (reset) the orientation one by one on each cylenders

But I’m looking for a batch solution which will guess the best orientation for each cylenders.

Maybe based on the orientation of the longest edge ?

Or based on the normals of the caps ?

Or based on an average of the dimensions of the geometry (probably the best if the shapes are not consistent) ?

Do you know a script or an addon which can do that ?

Thanks for your help !

No, i doubt there is an addon or script for this. If you need the origins in a certain point you need it to do by hand.

Why you want to change the origin?

Hello thanks for your answer.

I need to orient the local axes to direction of the cylenders to be able to manipulate them in more efficient way than with the global axes. (I don’t want to move the origine)

Since I have a lot of cylenders I would like to automate this process.

I found these two addon which look great but still need to specify manually some informations, like edges or 3 points …

I guess if the script can compute the lengths of the edges it can take the longest one and then use it to align the local axes.

Or by computing the volume of the object and then extract the longest dimenstions and then orient the local axes.

But I’m not a programmer

You may just select one side of the cylinder and defne you own orientation like so:

Hello, thanks for your answer Okidoki

Yes, I already know that procedure.

My question is about to do it in batch of many objects (here cylinders)… → An automated way.

I don’t want to do it manually on thousands cylinders.

That’s why I’m looking for a script or an addon.

okay many vs thousend that’s a point :wink: … okay :thinking: first in edit mode: seperate by loose parts… then something to select on top/buttom n-gon or trianlge (assuming the sides are quad) the using this as orientation setting pivot point to center… could be possible as addon… (programming: yes; python yes; some little bit of blender scripting: yea… ahh n… a little tiny bit… so: no not realy yet)

Sorry, I asked similar question on another post.

Finally I made a little script which works well in my case

Here it’s the link to the other post :

https://blenderartists.org/t/transfer-the-normal-orientation-to-the-local-orientation/1396289/5?u=henrard.stephane

And here is the script :

import bpy

sel_objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']

for obj in sel_objs: 
    obj.select_set(False) 

while len(sel_objs) >= 1:         
    obj1 = sel_objs.pop() 
    obj1.select_set(True) 
    bpy.context.view_layer.objects.active = obj1
    bpy.context.scene.tool_settings.use_transform_data_origin = False
    bpy.context.scene.transform_orientation_slots[0].type = 'NORMAL'
    bpy.ops.object.mode_set( mode = 'EDIT' )
    bpy.ops.mesh.select_mode( type = 'FACE' )
    bpy.ops.mesh.select_all( action = 'DESELECT' )
    bpy.ops.mesh.select_face_by_sides(number=4, type='GREATER')
    bpy.ops.transform.create_orientation(name='tmp', use_view=False, use=False, overwrite=True)
    bpy.context.scene.transform_orientation_slots[0].type = 'tmp'
    bpy.ops.object.mode_set( mode = 'OBJECT' )
    bpy.context.scene.tool_settings.use_transform_data_origin = True
    bpy.ops.transform.transform(mode='ALIGN', orient_type='tmp', orient_matrix_type='tmp')
    bpy.context.scene.tool_settings.use_transform_data_origin = False
    bpy.context.scene.transform_orientation_slots[0].type = 'LOCAL'
    obj1.select_set(False)