0
$\begingroup$

This has surely been asked before but I think I don't know the correct terms to search for. What I want is in my custom panel, sliders for changing the active camera's location and rotation. Basically, I get this easily with:

def draw(self, context):
    layout = self.layout
    scene = context.scene

    cam = context.scene.camera

    layout.label(text="Location:")
    layout.prop(cam, "location", slider=True, index=0, text="X")
    layout.prop(cam, "location", slider=True, index=1, text="Y")
    layout.prop(cam, "location", slider=True, index=2, text="Z")
    layout.label(text="Rotation:")
    layout.prop(cam, "rotation_euler", slider=True, index=0, text="X")
    layout.prop(cam, "rotation_euler", slider=True, index=1, text="Y")
    layout.prop(cam, "rotation_euler", slider=True, index=2, text="Z")

However, this ends up in a slider with no limits (limits are number ranges of computer, I think), so a slight change in the slider will result in massive change in position/rotation of camera.

Actually, what I really want to achieve is a copy of the sliders like they appear in the "Item" tab when I select the camera. Anyone able to help me there with links to other threads or questions or a direct solution?

$\endgroup$
0
1
$\begingroup$

Ok, found it. Replace all the stuff below the cam definition with:

layout.use_property_split = True

col = layout.column()
row = col.row(align=True)
row.prop(cam, "location")

col = layout.column()
row = col.row(align=True)
row.prop(cam, "rotation_euler")
$\endgroup$
1
  • $\begingroup$ cool, I didn't know you could do that! $\endgroup$ – ChameleonScales May 20 '20 at 11:25
1
$\begingroup$

If you want the properties to be identical to the original ones, you should set Slider to False or simply not include Slider at all.

A Slider is a bar that fills the field from left to right. When disabled, the field has 2 arrows on both sides instead.

If you use a slider you have to include min and max values or else they will be determined by Blender and be huge.

Edit: Code would look like:

def draw(self, context):
    layout = self.layout

    cam = context.scene.camera

    col = layout.column(align=True)
    col.label(text="Location:")
    col.prop(cam, "location", index=0, text="X")
    col.prop(cam, "location", index=1, text="Y")
    col.prop(cam, "location", index=2, text="Z")
    col = layout.column(align=True)
    col.label(text="Rotation:")
    col.prop(cam, "rotation_euler", index=0, text="X")
    col.prop(cam, "rotation_euler", index=1, text="Y")
    col.prop(cam, "rotation_euler", index=2, text="Z")
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.