I am currently in the process of writing a project in python for Blender to simulate crowds automatically. However I would need for there to be a custom UI to allow the user to choose their settings such as min to max speed, how much they want locations to randomised by etc. But from tutorials I have watched, and links I have followed all seem to have the buttons and sliders only do what is already predefined in blender and does not allow me to make it execute a function I have wrote. I managed to find a workaround for creating a custom shape by adding it to the operator menu, but is there a way for it to save the value of a slider to a variable rather than doing a predefined Blender function.
import bpy
import math
import mathutils
class TargetMakerPanel(bpy.types.Panel) :
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"
bl_label = "CrowD"
def draw(self, context) :
layout = self.layout
scene = context.scene
TheCol = self.layout.column(align = True)
TheCol.operator("mesh.make_target", text = "Add Target")
layout.label(text=" Random Speed:")
row = layout.row()
row.prop(scene, "frame_start")
row.prop(scene, "frame_end")
class MakeTarget(bpy.types.Operator) :
bl_idname = "mesh.make_target"
bl_label = "Add Target"
bl_options = {"UNDO"}
def invoke(self, context, event) :
Vertices = \
[
mathutils.Vector((-0.5, -0.5,0)),
mathutils.Vector((0.5, -0.5, 0)),
mathutils.Vector((0.5, 0.5, 0)),
mathutils.Vector((-0.5, 0.5, 0)),
]
NewMesh = bpy.data.meshes.new("Target")
NewMesh.from_pydata \
(
Vertices,
[],
[[0, 1, 2], [0, 1, 3], [1, 2, 3], [2, 0, 3]]
)
NewMesh.update()
NewObj = bpy.data.objects.new("Target", NewMesh)
context.scene.objects.link(NewObj)
return {"FINISHED"}
#end invoke
def register() :
bpy.utils.register_class(MakeTarget)
bpy.utils.register_class(TargetMakerPanel)
def unregister() :
bpy.utils.unregister_class(MakeTarget)
bpy.utils.unregister_class(TargetMakerPanel)
if __name__ == "__main__" :
register()
In my code I would ideally like it so that the row that slider that says "Start Frame" would allow me to recognise that value and assign it to a variable called MinSpeed.... Rather than it automatically changing the frame as blender had already defined it as...