Add an object in Python, but let user modify settings?

Adding an object manually (Add/Mesh/Cone for example) gives the user the ability to set various parameters of the cone (Vertices, Radii, Depth…) interactively.

But calling bpy.ops.mesh.primitive_cone_add() doesn’t seem to give the user those same options.

Is there a way to add a cone (and other primitives) from an operator and still have it allow the user to modify those parameters of the new object?

Here’s a simple Add-On that attempts to do this, but the Cone does not offer the same parameters as when created from Add/Mesh/Cone.

bl_info = {
  "version": "0.1",
  "name": "Create Cone",
  'author': 'Bob',
  "category": "Blender Experiments"
  }

import bpy
from bpy.props import *

class CREATE_OT_cone(bpy.types.Operator):
    bl_idname = "create.cone"
    bl_label = "Create Cone"
    bl_description = ("Add a new primitive cone")

    def execute(self, context):
        bpy.ops.mesh.primitive_cone_add()
        return{'FINISHED'}

class CreateConePanel(bpy.types.Panel):
    bl_label = "Add Cone"

    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Add Object"

    def draw(self, context):
        row = self.layout.row()
        row.operator("create.cone")

def register():
    print ("Registering ", __name__)
    bpy.utils.register_module(__name__)

def unregister():
    print ("Unregistering ", __name__)
    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    register()

Does this require using “invoke” or “modal” or a special return type (“RUNNING_MODAL”)?

I am not even sure if this is possible with Python what you want to do here.

The create buttons from the Blender menu calls a internal WM operator in a C file. And this one invokes to call the Operator panel where you can adjust the settings. Your self made class does not contain to call this Operator panel. It just creates the primitive.

You could simply use the Blender internal way. Then you just need a button. And not the class anymore. Depends of course what you want to achieve.

bl_info = {
  "version": "0.1",
  "name": "Create Cone",
  'author': 'Bob',
  "category": "Blender Experiments"
  }

import bpy
from bpy.props import *

class CreateConePanel(bpy.types.Panel):
    bl_label = "Add Cone"

    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Add Object"

    def draw(self, context):
        row = self.layout.row()
        row.operator("mesh.primitive_cone_add", text="Cone", icon='MESH_CONE')

def register():
    print ("Registering ", __name__)
    bpy.utils.register_module(__name__)

def unregister():
    print ("Unregistering ", __name__)
    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    register()

Have a look at the space_view3d_toolbar.py file in the \Release\2.76\scripts\startup\bl_ui path for more primitive add code.