0
$\begingroup$

Here is my non-symmetrical object : enter image description here

As you can see the left part (X negative, the black line) is not egal to the right part (X positive, red line). How can I get equal parts by translating my object with a python script ? Thank you in advance for your help.

$\endgroup$

2 Answers 2

1
$\begingroup$

you have to find the extreme values on x axis and calculate where should be the center :

import bpy

obj = bpy.context.object
max = -9999
min = 9999
for i in obj.data.vertices :
    if i.co[0] > max :
        max_ind = i.index
        max  = i.co[0]
    if i.co[0] < min :
        min_ind = i.index
        min  = i.co[0]

shift = (max-min)/2 - max
obj.location[0] +=shift
$\endgroup$
1
  • $\begingroup$ @reflyon you're welcome, the object should be centered like in the image ,because I forget to convert to world coordinates, i'll edit ! $\endgroup$
    – Chebhou
    Commented Mar 25, 2015 at 16:57
0
$\begingroup$

First set your object origin to center of bounding box, then move it to the location you want.

import bpy

bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')
bpy.context.object.location.x = 0
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .