1
$\begingroup$

I am trying to re-center an object that I have imported into blender.

I have set the object origin to the Center of Mass of the object, now I want to translate the object so its' center of mass is exactly at the global (0,0,0) location.

How can I print the x,y,z coordinates of the object's center of mass? or is there a way to just directly translate the object center of mass to a given x,y,z point?

Thanks!!

$\endgroup$

3 Answers 3

1
$\begingroup$

Are you trying to place object in center of grid?

import bpy

bpy.ops.object.location_clear(clear_delta=False)

or something like this.

import bpy

ACT_OBJ  = bpy.context.active_object

ACT_OBJ.location = (0.0, 0.0, 0.0)

$\endgroup$
4
  • $\begingroup$ I think this is what I'm looking for..this translates the object location (origin) to the center of the grid (xyz= 0,0,0), correct? Just trying to understand the code $\endgroup$
    – Derek Eden
    Commented Feb 14, 2019 at 16:06
  • $\begingroup$ Yeah, it sends it back to xyz= 0,0,0. There’s prolly other ways to do it though. $\endgroup$
    – AFWS
    Commented Feb 14, 2019 at 16:15
  • $\begingroup$ excellent!! although I can achieve the same result with both, the second suggestion is what I was looking for..thanks $\endgroup$
    – Derek Eden
    Commented Feb 14, 2019 at 16:23
  • 1
    $\begingroup$ obj.matrix_world.translation = (0, 0, 0) will move obj to global origin regardless of parenting. $\endgroup$
    – batFINGER
    Commented Feb 14, 2019 at 16:27
0
$\begingroup$

In the end used the following code:

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME') #set origin to volume centroid
bpy.context.object.location #check origin location if needed for any purpose
bpy.ops.object.location_clear(clear_delta=False) #translate origin to global (0,0,0)
bpy.context.object.location #double check it worked
$\endgroup$
0
$\begingroup$

Set matrix_world translation

I want to translate the object so its center of mass is exactly at the global (0,0,0) location.

Following up on a comment above. To ensure object is at global origin set the translation of its matrix world to zero vectpr.

Setting an object's location to zero only ensures it is at global origin if it either has no parent, or its parent is also at the global origin.

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME') 
# set location to global origin.
context.object.matrix_world.translation = (0, 0, 0)
$\endgroup$

You must log in to answer this question.

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