10
$\begingroup$

I have a script, that create a dialog with one text input:

import bpy

class OFPropConfirmOperator(bpy.types.Operator):
    bl_idname = "view3d.custom_confirm_dialog"
    bl_label = "Generite output folders"

    prop1 = bpy.props.StringProperty()

    @classmethod
    def poll(cls, context):
        return True

    def execute(self, context):
        #do some stuff here
        return {'FINISHED'}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)

    def draw(self, context):
        row = self.layout
        row.prop(self, "prop1", text="New name")


class OFPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_idname = "OF_my_panel"
    bl_label = "OF"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Tools"

    def draw(self, context):
        layout = self.layout
        layout.operator(OFPropConfirmOperator.bl_idname)

def register():
    bpy.utils.register_class(OFPropConfirmOperator)
    bpy.utils.register_class(OFPanel)

def unregister():
    bpy.utils.unregister_class(OFPanel)
    bpy.utils.unregister_class(OFPropConfirmOperator)

if __name__ == "__main__":
    register()

So, I have a button on the T-panel, that in the panel called OFPanel, this button opens the OFPropConfirmOperator` pop-up window. And everything works fine, but then the pop-up window opens, I need to click on the text field to start editing it. But I want it to work like in renaming markers: then a pop-up window opens, you can edit the text at once

$\endgroup$

2 Answers 2

6
$\begingroup$

Brecht Van Lommel says:

It’s quite hidden, but you can add this to the operator:

bl_property = "prop1"

bl_property

The name of a property to use as this operators primary property. Currently this is only used to select the default property when expanding an operator into a menu. :type: string

https://docs.blender.org/api/blender_python_api_master/bpy.types.Operator.html#bpy.types.Operator.bl_property

$\endgroup$
1
  • $\begingroup$ Works with string properties, but not float properties in 3.6.1 $\endgroup$ Aug 4 at 7:56
4
+200
$\begingroup$

Just rename the operator property name to type. Honestly, I don't know why this works, maybe some kind of super secret feature, I don't know. Credit for that idea goes to @p2or: Is there an addon for renaming an object with a keyboard shortcut?

enter image description here

import bpy

class OFPropConfirmOperator(bpy.types.Operator):
    """Generate Custom Output Folders"""
    bl_idname = "of.confirm_dialog"
    bl_label = "Generate Output Folders"

    type = bpy.props.StringProperty(
        default="Base", 
        #options={'SKIP_SAVE'}
        )
    geo = bpy.props.StringProperty(
        default="Geometry", 
        #options={'SKIP_SAVE'}
        )
    tex = bpy.props.StringProperty(
        default="Textures", 
        #options={'SKIP_SAVE'}
        )

    @classmethod
    def poll(cls, context):
        return True

    def execute(self, context):
        #do some stuff here
        return {'FINISHED'}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width=500)

    def draw(self, context):
        row = self.layout
        row.prop(self, "type", text="Base Folder")
        row.prop(self, "geo", text="Geometry Folder")
        row.prop(self, "tex", text="Texture Folder")
        row.separator()

class OFPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_idname = "OF_my_panel"
    bl_label = "OF Tools"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Tools"

    def draw(self, context):
        layout = self.layout
        layout.operator(OFPropConfirmOperator.bl_idname)

def register():
    bpy.utils.register_class(OFPropConfirmOperator)
    bpy.utils.register_class(OFPanel)

def unregister():
    bpy.utils.unregister_class(OFPanel)
    bpy.utils.unregister_class(OFPropConfirmOperator)

if __name__ == "__main__":
    register()
$\endgroup$
4
  • 1
    $\begingroup$ This doesn't work for me $\endgroup$
    – Crantisz
    Sep 17, 2018 at 6:36
  • $\begingroup$ Even in question from your link, there is a gif, there user clicked on the text input field to start edit it $\endgroup$
    – Crantisz
    Sep 17, 2018 at 6:59
  • 2
    $\begingroup$ Huh. What exactly does not work @Crantisz? It was added later, see Revision No. 2. Added a trusty gif too ;) $\endgroup$
    – brockmann
    Sep 17, 2018 at 8:45
  • 1
    $\begingroup$ hm. Now it works. Strange... Live bounty open, maybe someone knows about this issue. $\endgroup$
    – Crantisz
    Sep 17, 2018 at 9:17

You must log in to answer this question.

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