Skip to content

Instantly share code, notes, and snippets.


Theverat/ Secret

Last active Jun 16, 2019
What would you like to do?
from bpy.types import PropertyGroup
from bpy.props import PointerProperty
def add_lens(obj):
""" opticore is an instance of the OptiCoreProps PropertyGroup """
opticore = obj.opticore
rad = opticore.rad
# Replace mesh
# Set material
if obj.material_slots:
obj.material_slots[obj.active_material_index].material = opticore.material
class OBJECT_OT_add_lens(Operator, AddObjectHelper):
"""Create a new Mesh Object"""
bl_idname = "mesh.add_lens"
bl_label = "Add Mesh Object"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
if not obj:
# Create object (without mesh)
obj = ...
# Mark as lens, so in the future our custom panel is displayed on this object
obj.opticore.is_lens = True
# Generate the mesh
return {'FINISHED'}
class OPTICORE_OT_apply_lens(Operator):
bl_idname = "opticore.apply_lens"
bl_label = "Apply"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
obj = context.object
mesh =
# Delete mesh vertices and re-create them
return {'FINISHED'}
class OptiCoreProps(PropertyGroup):
rad = FloatProperty(
name="Surface 1 Radius",
default = 12.,
description="Radius of Curvature of Mirror Surface",
material = PointerProperty(type=bpy.types.Material)
is_lens = BoolProperty() # Not visible in UI
class OptiCorePanel(bpy.types.Panel):
bl_label = "Opticore Settings"
bl_context = "object"
def poll(cls, context):
# Check if it's a lens object
return context.object and not context.object.library and context.object.opticore.is_lens
def draw(self, context):
layout = self.layout
opticore = context.object.opticore
layout.prop(opticore, "rad")
# Don't need prop_search because we can now use a PointerProperty
layout.prop(opticore, "material")
# Apply button
def register():
bpy.types.Object.opticore = PointerProperty(type=OptiCoreProps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.