input dialog box blender

2019-03-26 17:42发布

问题:

How to make a simple entry dialog box (like in the image) in blender and processing the text entered through python.I am unable to find any good tutorial on this.

回答1:

For the dialog box the answer from how to show a message from a blender script? might be a starting point.

But I think a better approach is integrating input into the panel like e.g.

To do this you have to add a StringProperty to your add-on and place it inside your panel (see Addon Tutorial for more information). The basic steps are:

def draw(self, context) :
    col = self.layout.column(align = True)
    col.prop(context.scene, "my_string_prop")

...

def register() :
    bpy.types.Scene.my_string_prop = bpy.props.StringProperty \
      (
        name = "My String",
        description = "My description",
        default = "default"
      )

...

def unregister() :
    del bpy.types.Scene.my_string_prop

...

You can access the string by context.scene.my_string_prop

There is another mode to integrate input. When you add for example a text to your scene you can change the parameters after the operator has been called and see the changes immediately:

Changing Location will move the newly created text object at another place. I haven't worked with this but it should be similar to the code above.