I am trying to make a custom panel that includes the "Transform" panel that appears in edit mode.
I do not need to do anything special, I just want this panel added for convenience. I do not see any way to just copy the UI element, so I have been trying to use bmesh to emulate the same function. However, when using the code below, modifications made using the custom panel do not sync. Flipping between the "Item" toolbar and the custom panel moves the selected element back and forth between values. Additionally, when the custom panel is open, you cannot select any elements or use any gizmos.
import bpy
import math
import bmesh
bpy.app.debug = True
from bpy.props import EnumProperty
from bpy.types import Operator, Panel
from bpy.utils import register_class, unregister_class
class KazTools:
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "KazTools"
@classmethod
def poll(cls, context):
return (context.object is not None)
class PanelOne(KazTools, bpy.types.Panel):
bl_idname = "VIEW3D_PT_ktp1"
bl_label = "Panel One"
def draw(self, context):
l = self.layout
layout = self.layout
b = l.box()
g = b.grid_flow(row_major=True, columns=3, align=True)
s = g.split(factor=0.3)
s.label(text='')
s.label(text='X')
s = g.split(factor=0.3)
s.label(text='')
s.label(text='Y')
s = g.split(factor=0.3)
s.label(text='')
s.label(text='Z')
try:
i = bmesh.from_edit_mesh(context.object.data).select_history[-1]
assert isinstance(i, bmesh.types.BMVert)
o = context.object.data.vertices[i.index]
g.prop(o, "co", index=0, text='')
g.prop(o, "co", index=1, text='')
g.prop(o, "co", index=2, text='')
#This is probably the issue.
#I can't use prop on bmesh objects so don't know any other way.
i.co[0] = o.co[0]
i.co[1] = o.co[1]
i.co[2] = o.co[2]
#Each one of these has slightly different behavior but does not work
#i.to_mesh(context.object.data)
bmesh.update_edit_mesh(context.object.data)
#context.object.update_from_editmode()
except:
g.prop(context.object, "location", index=0, text='')
g.prop(context.object, "location", index=1, text='')
g.prop(context.object, "location", index=2, text='')
bpy.utils.register_class(PanelOne)
I have looked far and wide and am aware of similar questions like the one below but have not found any answers that work. Python code for Transform panel content in edit mode?
Has anyone been able to achieve this?
