13
$\begingroup$

Let's say you have a single obj with a number of separate closed 3D geometries in it. For example's sake, imagine you have an obj called neighborhoodfirehydrants.obj that includes the model for all of the fire hydrants on a street, which themselves are closed, but as I said above, are all within the same obj file.

Now let's say you wanted to be able to process each of those fire hydrants one at a time, separately. To the user, it's very obvious to see visually that these faces can be subgrouped into separate "objects" but in the Blender world, it sees them all as one.

I'm looking for a way (script would be ideal) to iterate through a blender obj neighborhoodfirehydrants.obj and find each of the "objects" (fire hydrants) that make it up. I've been looking into using the looping tools, but that's not making sense in this context.

$\endgroup$

1 Answer 1

15
$\begingroup$

You could use Separate P (in Edit Mode) and select By loose parts.

enter image description here

enter image description here

The reverse operation would be Join Ctrl-J (in Object Mode) this would require all objects selected that you need to join to a single object.

In a script you could select the object by name and invoke the operator:

import bpy
object = bpy.data.objects['ObjectsName']
object.select = True
bpy.ops.mesh.separate(type='LOOSE')

After this you could set an individual origin to each separated object.

This can be accessed from the toolbar or from the menu:

Object -> Transform -> Origin to Geometry

To set the origin in a script you can select all objects and run:

bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')
$\endgroup$
2
  • $\begingroup$ Note that you need to be in EDIT mode for P to work correctly. In this example, you also need to have everything selected - any unselected meshes in your scene will not be evaluated by the Separate command. $\endgroup$
    – Thomas
    Commented Dec 13, 2013 at 17:09
  • $\begingroup$ Note: after this you may want to run Origin -> Origin to Geometry so each object gets its center pivot in a useful location. $\endgroup$
    – ideasman42
    Commented Dec 13, 2013 at 17:38

You must log in to answer this question.

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