The goal: since you can’t use the standard “G” shortcut to set the absolute X, Y, or Z location/scale/rotation of an object (only move it relative), I thought to make a script and bind it to a hot key.
So I wanted to make a simple script that pops up a dialog to take a number entry and uses that to set the X/Y/Z whatever.
I got this far, but I can’t make the number entry field have focus when the dialog opens. (I’m not yet using the value to do anything, I know.) I set bl_property but it doesn’t seem to be working. Disclaimer: I know nothing about scripting in Blender and have cobbled this together from a few examples online and a little knowledge of python:
import bpy
from bpy.props import *
theFloat = 0.0
class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Simple Dialog Operator"
bl_property = "my_float"
my_float: FloatProperty(name="Some Floating Point")
def execute(self, context):
global theFloat
theFloat = self.my_float
return {'FINISHED'}
def invoke(self, context, event):
global theFloat
self.my_float = theFloat
return context.window_manager.invoke_props_dialog(self)
bpy.utils.register_class(DialogOperator)
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
What am I doing wrong? (And if there is an easier way to do this, I’m all ears. E.g. I don’t need to pop up a dialog – I’d be happy to just read in from the keyboard like the normal G action does. I just didn’t know any other way. Or maybe there is a scriptable way to focus the existing object position fields so my custom hotkey can just pop in to edit those directly, etc.)