Instant Add Object from python cancelled

edit: I meant the title to be “add instance group”, my bge days poked through but I’m talking about addon-style scripting!


This is a crazy simple thing to do, but I don’t understand why blender is coughing at me. The scenario is you have a group and you want to add it to the scene. Via the interface, you hit shift-a, go under group, and click the one you want – no problem. But through python, with the same command, for me it’s either ‘CANCELLED’ or simply crashes blender.

I’ve simplified the scenario to the most straightforward file as possible in the attached blend, and below is the code/behavior:

(there is a group named ‘g’, consisting only of the default cube)

bpy.ops.object.group_instance_add(name="Group", group='g', view_align=False, location=(0.0145764, -0.0171438, -0.040683), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
# the above returns "CANCELLED", but is the same line as the info bar if done via interface

# the above immediately crashes blender

# the above also immediately crashes blender

Am I missing something more fundamental? The documentation doesn’t indicate anything else is needed, and I didn’t see any other threads with anyone having issues.

If anyone could just send me a line of code how to do this properly, that’s all I need – or if the case may be, just say that it’s significantly more complicated that I thought. Thanks!

Attachments (75.9 KB)

Don’t use bpy in BGE. Use the search tool for the BGE api

Sorry I didn’t specify, this isn’t the bge it’s for an addon. I’m working with linked libraries to speed up my workflow :slight_smile:

it shouldn’t crash for sure, better report to the bug tracker!

you can try to replace the operator by low-level code:

scene = bpy.context.scene

ob ="Empty", None)
ob.dupli_type = 'GROUP'
ob.dupli_group ="g")
ob.location = scene.cursor_location

Yup, that works in at least my primitive scene! I’ll try implementing it as a function in my other script to see if everything still works… Thanks a million :slight_smile:

Any chance if you can tell for sure I was at least using the operator group_instance_add correctly? (what does the sample blend do for you, crash, work, paint rainbows?) Regardless if I was using it properly or not, you’re right that it shouldn’t crash blender – but if the function itself simply isn’t working under proper use, that’s important to report too.

your sample blend does crash my 2.67 instantly as well, not sure why though. The line as given by the op log does not work unless i change name to “g” - that seems to work?! Really strange…

Did you report to the bug tracker already?

Note yet, I’ll do a check to see if anything like it has already been reported, if not I’ll add it and post back here

update, I confirm the behavior you mentioned – and I also saw that if I simply run


It works fine, no crashing. However, it still shouldn’t crash with what I assume must be the improper use above.

I totally agree! Seems like a tricky bug

Bug posted on tracker. But again, there is at least one way it works properly as in the previous post – it just doesn’t match the documentation precisely and is inconsistent with the info log of UI actions. And nothing should ever just spontaneously crash :slight_smile:

>> link:

And apparently already fixed, thanks to Campbell Barton!


And he suggests to use the low-level approach :slight_smile: