it’s part of a bigger addon, but I isolated the code in a small addon. ‘double middle click’ to open the menu.
example
"""TODO: same about rotation"""
bl_info = {
"name": " ABSOLUTE",
"author": "1COD",
"version": (1, 0, 0),
"blender": (2, 93, 0),
"location": "View3D",
"description": "children absolute coordinates double midle click",
"warning": "",
"wiki_url": "",
"category": "Menu"
}
import bpy
from mathutils import Vector, Matrix
class ABSOLUTE_properties(bpy.types.PropertyGroup):
def get_float(self):
ob = bpy.context.active_object
if not ob:
return
if self.get('abs', None):
return ob.matrix_world.translation
else:
return ob.location
def set_float(self, value):
self["Temp"] = value
def update_float(self, context):
ob = context.active_object
if not ob:
return
loc = self.Temp
if self.abs:
mw = ob.matrix_world
if ob.parent and ob.parent_type in {'VERTEX', 'VERTEX_3'}:
ob.location += ob.parent.matrix_world.to_quaternion().to_matrix().to_4x4().inverted()@(Vector(loc)-mw.translation)
else:
mw.translation = Vector(loc)
else:
ob.location = Vector(loc)
abs: bpy.props.BoolProperty()
Temp: bpy.props.FloatVectorProperty(subtype='XYZ',)
abs_location : bpy.props.FloatVectorProperty(
get=get_float,
set=set_float,
update=update_float,
subtype='XYZ',
name = "Position",
options={'ANIMATABLE'},
precision = 4
)
@classmethod
def register(cls):
bpy.types.Scene.acc = bpy.props.PointerProperty(type=cls)
@classmethod
def unregister(cls):
del bpy.types.Scene.acc
class ABSOLUTE_PT_child_coordinates(bpy.types.Panel):
bl_label = "absolute child coordinates menu"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "0data"
# bl_options = {'DEFAULT_CLOSED'}
bl_ui_units_x = 9
def draw(self, context):
layout = self.layout
object = context.object
scene = context.scene
layout.separator(factor=2)
layout.column().prop(scene.acc, "abs", text="Absolute Location")
layout.column().label(text='(enter x/y/z in 3 steps)')
label = "Absolute Loc (parented objects)" if scene.acc.abs else "Location"
layout.column().prop(scene.acc, "abs_location", text=label)
classes = (ABSOLUTE_properties, ABSOLUTE_PT_child_coordinates)
addon_keymaps = []
def register():
for cls in classes:
bpy.utils.register_class(cls)
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
km = wm.keyconfigs.addon.keymaps.new(
name='3D View', space_type='VIEW_3D')
kmi = km.keymap_items.new('wm.call_panel', 'MIDDLEMOUSE', 'DOUBLE_CLICK')
kmi.properties.name = "ABSOLUTE_PT_child_coordinates"
kmi.properties.keep_open = True
addon_keymaps.append((km, kmi))
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc is not None:
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
if __name__ == "__main__":
register()
the problem is that I can’t set 3 coordinates at once like over a normal location prop in the blender tool menu