add group instance from python scripting

Hi there!

I have a group of meshes, and i know you can add an instance of that group from the add panel (

Shift + A -> Group Instance -> My Group

), but I can’t figure out how to do this from python scripting… the python API’s documentation is driving me nuts!!! :mad: all it has is how to add/remove new things into a group:

There MUST be a way to achieve this… because otherwise, game devs wouldn’t be able to generate enemies automatically :no:

please halp!

A group instance is basically an Empty object with duplication set to type Group and an object group assigned to the Group field.

You can automate that efficiently (no operators) like:

import bpy

scene = bpy.context.scene
grp =["My Group"] # get group by name

empty ="Your Group Instance", None)
empty.dupli_type = 'GROUP'
empty.dupli_group = grp
empty.location = (0, 0, 2)

If you prefer the operator, just hover the group in the Group Instance menu to see how to call it with Python:

bpy.ops.object.group_instance_add(name=“My Group”)