Dear Reader,
question from a Blender Newby.
i am trying to add a custom property to an own mesh plugin.
in order to not have to build two plugins for each shape, it would be nice to know how i add a Boolean or more preferably a ListSelect property to the plugin so i can switch between multiple sizes: radius / edge length / unit
any help is welcome…
thank you
bl_info = {
"name": "Octa PLUS",
"author": ":. ieoie .:",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Add > Mesh > New Octa PLUS",
"description": "Adds a new Mesh Object",
"category": "Add Mesh",
}
import bpy
import math
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector
def add_octaplus(self, context):
scale_x = self.scale.x
scale_y = self.scale.y
scale_z = self.scale.z
radius = 1
edge_size = math.sqrt(2)
"""
if (size_type == 0):
size = radius
else:
size = radius / edge_size
"""
size = radius
verts = [
Vector((0, 0, size * scale_z)),
Vector((size * scale_x, 0, 0)),
Vector((0, size * scale_y, 0)),
Vector((-size * scale_x, 0, 0)),
Vector((0, -size * scale_y, 0)),
Vector((0, 0, -size * scale_z)),
]
edges = []
faces = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1],
[5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]
mesh = bpy.data.meshes.new(name="obj_OctaPlus")
mesh.from_pydata(verts, edges, faces)
object_data_add(context, mesh, operator=self)
class OBJECT_OT_add_octaplus(Operator, AddObjectHelper):
"""Create a new Mesh Object"""
bl_idname = "mesh.add_octaplus"
bl_label = "Add Mesh Object"
bl_options = {'REGISTER', 'UNDO'}
scale: FloatVectorProperty(
name="scale",
default=(1.0, 1.0, 1.0),
subtype='TRANSLATION',
description="scaling",
)
size_type: bpy.props.BoolProperty(
name="Toggle Scale",
default=0,
subtype='TRANSLATION',
description="Radius or Edgelength"
)
def execute(self, context):
add_octaplus(self, context)
return {'FINISHED'}
# Registration
def add_octaplus_button(self, context):
self.layout.operator(
OBJECT_OT_add_octaplus.bl_idname,
text="Octahedron PLUS",
icon='PLUGIN')
def register():
bpy.utils.register_class(OBJECT_OT_add_octaplus)
bpy.types.VIEW3D_MT_mesh_add.append(add_octaplus_button)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_add_octaplus)
bpy.types.VIEW3D_MT_mesh_add.remove(add_octaplud_button)
if __name__ == "__main__":
register()