I am still really new to Python and I am working through some new things. I would like to create a Pop up dialog box that the user can input some text. I would like to then use that Text for something else, for example changing the Name of the default cube.
I have read through some posts and I see that creating the pop up dialog box is pretty simple but I am not sure how I can then use the user's defined text for the object name.
Here is what I have so far (which is just the pop up dialog box which works fine) I need to know how I can then use the text that the user inputs into that Dialog box and use it to change the name of the cube.
import bpy
class WM_OT_myop(bpy.types.Operator):
"""Tooltip"""
bl_idname = "wm.myop"
bl_label = "Simple Object Operator"
text = bpy.props.StringProperty(name="Name", default="")
def execute(self, context):
bpy.data.objects['Cube'].name = #rename cube to User Input?
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
def register():
bpy.utils.register_class(WM_OT_myop)
bpy.ops.wm.myop('INVOKE_DEFAULT')
def unregister():
bpy.utils.unregister_class(WM_OT_myop)
if __name__ == "__main__":
register()
Edit, Thanks to @Matt's explanation I made an addition:
text = self.text
here is the full script:
import bpy
class WM_OT_myop(bpy.types.Operator):
"""Tooltip"""
bl_idname = "wm.myop"
bl_label = "Simple Object Operator"
text = bpy.props.StringProperty(name="Name", default="")
def execute(self, context):
text = self.text
bpy.data.objects[0].name = text
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
def register():
bpy.utils.register_class(WM_OT_myop)
def unregister():
bpy.utils.unregister_class(WM_OT_myop)
if __name__ == "__main__":
register()
# test call
bpy.ops.wm.myop('INVOKE_DEFAULT')
context.object.name = text
in execute to rename the active object. As it is it renames the alphabetically first named object of all objects each time. $\endgroup$