Vengadora
(Vengadora)
1
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: http://www.blender.org/api/blender_python_api_2_74_release/bpy.ops.group.html
There MUST be a way to achieve this… because otherwise, game devs wouldn’t be able to generate enemies automatically :no:
please halp!
CoDEmanX
(CoDEmanX)
2
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 = bpy.data.groups["My Group"] # get group by name
empty = bpy.data.objects.new("Your Group Instance", None)
empty.dupli_type = 'GROUP'
empty.dupli_group = grp
empty.location = (0, 0, 2)
scene.objects.link(empty)
scene.update()
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”)