5

I'm trying to get the dimensions (bounding box) from a linked object in python, but all the methods to commonly get the measures give me a zero vector.

bpy.data.objects['Linked_Object'].dimensions
# (0.0, 0.0, 0.0)

bpy.data.objects['Linked_Object'].bound_box
# ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0))

I imagine is because the object is an empty, so it does not have dimension. I suppose there is a way to access the underlying information of the linked object but I cannot find a way to do it.

I have to keep the object linked, I cannot make a local copy because it can be modified in the source file.

Any Ideas how to do it?

Thank you.

Jorge Frias
  • 185
  • 1
  • 6

1 Answers1

5

For a linked collection instance

Pertaining to 2.8x

Example below. Collection instance "Cube.001" is linked from library "Cube.blend" where it belongs to collection "Cube"

>>> C.object
bpy.data.objects['Cube.001']

>>> C.object.type
'EMPTY'

>>> C.object.library
bpy.data.libraries['CUBE.blend']

Notice the collection is linked too

>>> C.object.instance_collection
bpy.data.collections['Cube']

>>> D.collections['Cube'].objects[:]
[bpy.data.objects['Cube']]

The dimensions of the individual objects in the group can be found via

>>> for o in C.object.instance_collection.objects:
...     o.name, o.type, o.dimensions
...     
('Cube', 'MESH', Vector((2.0000009536743164, 2.0000009536743164, 2.0)))

which could be used to make a "virtual" bounding box for the collection.

How to have a boundary box around a whole group instance?

Similarly for linking the collection and instancing from local blend.

batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • 1
    Thank you very much! Just if there is someone with my low bpy skills: C = bpy.context and D = bpy.data (took me more than I'd like to admit). – Jorge Frias Jan 10 '20 at 15:52