Add Boolean or SelectList Switch to custom plugin

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()


This is pretty well documented in the API docs, and there are multiple example scripts that Blender ships with that demonstrate how to use properties. Have you looked at the sample scripts?

From the script editor, they are under Templates->Python

Operator File Export, Operator File Import, Operator Modal… just a handful of sample scripts that use properties, I’m sure you’ll find more. Spend some time looking at those and if you have a specific question feel free to come back and I’ll try to answer it for you.

Thank you,
Managed to add multiple different types operators into my script.
they are accessible in my def where i need them, cause i can print them.

as i understand i have to draw them into a panel or UI element.
and dont know or understand if i have to write also a poll invoke or update function to make my shape listen to the operator.

i’m stuck with the draw definition, in terms of, how do i access the ‘newObjects’ custom properties, so my operators are visible inside the “Custom properties”

i see in my console, when i manually add a new property this command, bpy.ops.wm.properties_edit

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.props import (
    BoolProperty,
    BoolVectorProperty,
    EnumProperty,
    FloatProperty,
    FloatVectorProperty,
)

from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector




def add_octaplus(self, context, newBool, newFloat, newEnum):
    
    print('newBool: %s' %newBool)
    print('newFloat: %s' %newFloat)
    print('newEnum: %s' %newEnum)
    
    scale_x = self.scale.x
    scale_y = self.scale.y
    scale_z = self.scale.z
    
    radius = 1
    edge_size = math.sqrt(2)
    
    if (newEnum == 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",
    )
    
    myBool: BoolProperty(
        name="Toggle Scale",
        default=0,
        #subtype='NONE',
        description="Radius or Edgelength",
        options={'ANIMATABLE'}
    )

    myHeight: FloatProperty(
        name="Height",
        description="Box Height",
        min=0.01, max=100.0,
        default=1.0,
        options={'ANIMATABLE'}
    )
    
    myType: EnumProperty(
        name="Example Enum",
        description="Choose between two items",
        items=(
            ('OPT_A', "First Option", "Description one"),
            ('OPT_B', "Second Option", "Description two"),
        ),
        default='OPT_A',
    )
    
    
    def draw(self, context):

        """
        bpy.ops.wm.properties_edit(
                                data_path="object", 
                                property="jaja", 
                                value="1.0", id
                                default="1.0", 
                                min=0, max=1, 
                                use_soft_limits=False, 
                                is_overridable_library=False, 
                                soft_min=0, soft_max=1, 
                                description="", subtype='NONE'
        )
        """
        #bpy.ops.wm.propperties_add.idName(self.myType)
        #bpy.ops.wm.propperties_edit.idName(self.myType)
        bpy.ops.wm.propperties_context_change.idName(self.myType)



    
    
    def execute(self, context):
        #draw(self, context)
        
        add_octaplus(self, context, self.myBool, self.myHeight, self.myType)

        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_octaplus_button)


if __name__ == "__main__":
    register()


when writing a class that inherits from bpy.types.Operator, the draw function will override what is shown in the operator panel. It’s not required, because by default the Operator class will draw the properties you’ve created in the order you created them. It’s only necessary to make your own draw function when you have a specific way you want things to be displayed (for example, only show this one property if this other property is True, etc). Remove your draw function entirely and your custom properties should show up in the Operator panel when you run the operator.

indeed, they show up in the operator panel, but i cannot adjust them in last operation panel, and would like to have them inside the “Custom Properties section” of the object so in there can set the settings manually and have the option to animate the operators.

could you advise me into that direction?
a per object controll.

i am coming from Maya, am making the switch to blender so learning to build all my custom plugins in Blender so i can do my art project in Blender.

something like this.

Ah- what you’re wanting to do is create a non-destructive procedural primitive. That’s a much deeper subject. Typically, in Blender when you create an object the properties you set to initialize the object are only used for initialization- the data created is committed to the object. The property itself is only used for that initialization, unless the data itself has a direct link to it (in the case of a Light, for example). For a Mesh type, you don’t have many options- once the object is created and the mesh is initialized, there are no direct links to any properties that can reconfigure that mesh. You would have to rebuild the mesh each time. It is technically possible to build something like this in Blender but it would be a pretty advanced topic for someone just starting out with Blender scripting.

if i understand correct, per vertex animation is not an easy thing to do in Blender.
please correct me if i understand wrong

yet i am eager to learn this complex matter, because Autodesk is applying new Activation rules for older versions, and since i use a 2013 Maya version, there will come a time i will not be able to activate my Maya on a new computer, this is for me the main reason to dive into Blender, i was lucky to get a Maya license once, but cannot afford to update it… and to be honest, i also do not want it anymore… stay ahead of the wave from this new asspolicy of Autodesk.

In Maya i am building a audio driven animation, the audio driven animation track has to be baked into the shapes/nodes before rendering, so this is not an option in Blender?

i have like a whole set of project standards, 50 curves, 80 shapes, and some Point nodes, that i need to re-write into Blender.

Since i have build many different nodes in Maya.
Thinking out loud… if i have 3 templates… i can build my Point nodes, Mesh nodes, Curve nodes.
And re-write all my Maya plugs into Blender and continue with the art project

next to that i am also developing some new Mesh shapes that have pretty complex pure math.
this development i do in Three.js with an CGI math professor, its a slow process, but very beautiful once they are finished.

life of an artist aint easy…:wink:
but together we can add beauty to this planet.
i do not need Blender for Modeling or other standard tasks, only to create beautiful geometric animations, this time audio driven.

do you know anyone inside the Blender community who can do this complex addon/plugin creation and would love to help me build 3 templates for, custom vertex points, custom mesh and custom curves.
someone who likes to be my TD/Help for 3 base templates, i can also pay a little for these templates if that is what is needed. Am not rich, but would love to keep going with my project, and leave Autodesk to my past.

if you like or need, i can show you through TeamViewer what i am doing in Maya, to make sure you have the exact details of my request.

@NewbyBlender Have you looked at Baking Sound to Fcurve in Blender? Lots of tutorials on the 'net.

Also have you looked at Animation Nodes? Similar things can be done here also. Again - lots of tutorials on the 'net.

Let me know if these do want you want, I have also written some additional AN nodes for Sound & MIDI…

Cheers, Clock.

EDIT: Also investigate ShapeKeys as a means of manipulating vertices in animation options.

1 Like

Will have a google search on it… quick reply…thats in Maya, the node editor. will dive deeper into it… but… in Maya everything is a node… and in the node editor you can call these nodes and connect them like seen i can do in blender as well… My aim is to have these own custom nodes in there, i do have for instance pointnodes where i can connect shapes or curve nodes in to larger complex grids…with certain custom attributes so i can manipulate my shapes easily & exactly how i like them to behave, for instance, if i have an octahedron from which i can set with an enum the radiusSize or the edgelengthSize… will make life much easier when ready, maybe a tough road to get there, but in the end i can easily connect it in the node editor of Blender, and connect it to audio.
think that will not be so different than Maya, the custom nodes is where i am now, learning how to build them in Blender, so if you like to help me with that, you are welcome…i will be a very grateful and happy chap… and probably would be best to meet up one day in TeamView/Skype screenshare so we know both exactly what the goal is…
first impression on shapekeys is thats a lot of manual labor, when grids become larger… and having custom nodes a real good solution to avoid this manual labor…

@clockmender Did instal the Animation Nodes, its getting there, but am not able to load and connect my own shapes there, or at least i do not know how.
For the rest it looks like the Maya Node Editor, that i am missing in Blender, its a very nice tool to have… miss it very much… maybe its an idea for the Blender developer to look at…

Animation Nodes is a third party Add-on and still a WIP - contact @OmarEmaraDev or details.

Cheers, Clock.

1 Like

@clockmender, this is a great thing this Animation Nodes Plugin, going to dive in and see if i can generate my shapes in there.
Seems after a thurrow google, Blender is developing an all nodes concept like Maya has, cant wait for that, will contact Omar and see if i maybe can help to add some basic shapeMeshes to the project.
thank you for the tip… :wink: