I’m trying to learn scripting in blender by writing a simple plugin. The basic script works, it generates a helix mesh. I can even start it from the tools menu. The problem is creating a UI to change the values of the variables in the script. I have set them as properties (variable = bpy.prop.IntProperty), but when I try calling them in the UI, (self.layout.prop(“mesh.helix”, variable)) the script crashes.
# Helix Script
import bpy
from bpy.props import *
from math import radians, cos, sin
class Helix(bpy.types.Operator):
bl_label = "Helix"
bl_idname = "mesh.helix"
bl_description = "Create a helix primative"
bl_options = {"UNDO"}
numberOfCoils = IntProperty(
name = "numberOfCoils",
description = "How many coils in the spring",
default = 10)
length = FloatProperty(
name = "length",
default = 1.0)
coilRadius = FloatProperty(
name = "coilRadius",
description = "Radius of the spring",
default = 0.5)
coilResolution = IntProperty(
name = "coilResolution",
description = "number of verticies per revolution",
default = 16)
def execute(self, context):
cursor = bpy.context.scene.cursor_location
anglesInRadians = [radians(degree) for degree in range(0, 360, int(360 / self.coilResolution))]
currentHeight = 0
verticies = []
for currentCoil in range(self.numberOfCoils):
for theta in anglesInRadians:
x = cursor.x + self.coilRadius * cos(theta)
y = cursor.y + self.coilRadius * sin(theta)
z = cursor.z + currentHeight
verticies.append((x, y, z))
currentHeight += self.length / self.numberOfCoils / self.coilResolution
edges = []
for vertexIndex in range(len(verticies)-1):
edges.append((vertexIndex, vertexIndex + 1))
# write data to the scene
mesh = bpy.data.meshes.new("HelixMesh")
ob = bpy.data.objects.new("Helix", mesh)
bpy.context.scene.objects.link(ob);
mesh.from_pydata(verticies, edges, [])
mesh.update()
return{"FINISHED"}
class HelixPanel(bpy.types.Panel):
bl_label = "Helix Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
def draw(self, context):
layout = self.layout
# This next line is the problem
layout.prop("mesh.helix", 'numberOfCoils')
layout.operator("mesh.helix")
bpy.utils.register_class(Helix)
bpy.utils.register_class(HelixPanel)
Any help would be apreciated