I’d like to rotate different objects using sliders in my Python-Panel.
What I found was this command:
col.prop(ob, "rotation_euler", text="Rotation")
However, the objects all have Rotation Constraints and can only be rotated around one axis each. So, is there a similar command that only displays a slider for a single axis (e.g. the “X”-axis)?
The Panel will be used for a robot-movement Simulation/Testing environment.
.prop() has an optional parameter index. Pass it a 0 for X rotation component.
Here’s an example, that takes X and Z euler rotation angles and puts them in an aligned column:
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
obj = context.object
col = layout.column(align=True)
col.label("Rotation:")
col.prop(obj, "rotation_euler", index=0, text="X")
col.prop(obj, "rotation_euler", index=2, text="Z")
def register():
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()
You need to set the label text manually, it will otherwise use the overall property name (which is “Euler Rotation” in this case, it doesn’t show X or Z using .index).