2

Can't find the way to move model to the center via Python API. When model is imported

object.location = (0, 0, 0). 

I tried to use

object.dimensions 

to shift model, but when model has empty spaces around - it does't work. How can I get this data or it may be a better way to do this?

p2or
  • 15,860
  • 10
  • 83
  • 143
  • Welcome Vladimir! If you import a model, the origin is typically at (0,0,0), that means to set the location to the center has no effect. I assume you want to reposition the origin first, right? – p2or Jan 28 '15 at 18:51
  • Yes, I think. In general whole problem - is render an image. So I need to put model on camera view. At first I want to move model to the center, where camera already is. – Vladimir Solovyov Jan 28 '15 at 19:00
  • Perhaps there is another way to solve main problem? – Vladimir Solovyov Jan 28 '15 at 19:02
  • Do you have tried this: bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN') ? – p2or Jan 28 '15 at 19:12
  • Oh, thank you! Just used it with "move 3d cursor to the center" and "move selected object to the center". It works :) – Vladimir Solovyov Jan 28 '15 at 19:21

1 Answers1

3

If you import a model, the origin is typically at (0,0,0) - setting the location to the center has no effect. The trick is to set the geometry to the origin via origin_set operator:

bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN')

Related: How to place objects on the center of the ground plane via python?

p2or
  • 15,860
  • 10
  • 83
  • 143