3

What is the python code to make multiple float property like in the mapping node? enter image description here

user75587
  • 31
  • 2

2 Answers2

7

Use a FloatVectorProperty and set its subtype to 'XYZ' or 'TRANSLATION'.

Currently other available subtypes of that property are: 'COLOR', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'COLOR_GAMMA', 'LAYER'.

enter image description here

Ripped from: How to create a custom UI?

import bpy

from bpy.props import (FloatVectorProperty,
                       PointerProperty
                       )

from bpy.types import (Panel,
                       PropertyGroup
                       )


# ------------------------------------------------------------------------
#    Scene Properties
# ------------------------------------------------------------------------

class MyProperties(PropertyGroup):

    my_float_vector: FloatVectorProperty(
        name = "Float Vector Value",
        description="Something",
        default=(0.0, 0.0, 0.0), 
        min= 0.0,
        max = 0.1,
        subtype = 'XYZ'
        # 'COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 
        # 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 
        # 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER'
        )

# ------------------------------------------------------------------------
#    Panel in Object Mode
# ------------------------------------------------------------------------

class OBJECT_PT_CustomPanel(Panel):
    bl_idname = "object.custom_panel"
    bl_label = "My Panel"
    bl_space_type = "VIEW_3D"   
    bl_region_type = "UI"
    bl_category = "Tools"
    bl_context = "objectmode"   


    @classmethod
    def poll(self,context):
        return context.object is not None

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

        layout.prop(mytool, "my_float_vector", text="")

# ------------------------------------------------------------------------
#    Registration
# ------------------------------------------------------------------------

classes = (
    MyProperties,
    OBJECT_PT_CustomPanel
)

def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)

    bpy.types.Scene.my_tool = PointerProperty(type=MyProperties)

def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)
    del bpy.types.Scene.my_tool


if __name__ == "__main__":
    register()
brockmann
  • 12,613
  • 4
  • 50
  • 93
0

Blender built-in mathutils-Vector

class mathutils.Vector(seq)

This object gives access to Vectors in Blender.

Parameters: seq (sequence of numbers) – Components of the vector, must be a sequence of at least two

mathutils.Vector

Most of the Blender code contain this Vector component for value modification.

HikariTW
  • 7,821
  • 2
  • 18
  • 37