Parametric Primitives and Dynamic UI

Hi, I’m fairly experienced with scripting for Max and Maya with Maxscript and Python/PyMel, but new to bpy.
I have some questions about getting started on a script.

I mainly want a sort of parametric object (cabinets, but more advanced than Archimesh) driven by a Dynamic UI. What I ideally would like is someone to suggest me an example script to learn from, that does one or two of the following:

-A custom primitive object with parameters that can de modified at any time after creation, the gemoetry regenerates any time you make a change. Pretty much like Max’s primitives (in Max this would be a scripted primitive).

-A custom UI that change dynamically based on user input. I’d want to freely add buttons, tabs, cells, etc, with the UI updating as we go. Basically rebuild and refresh the entire UI panel. In Max this can be done with DotNet, in Maya there’s tons of resources for doing this with Qt.

Thanks!

I would like to help but I have limited time, so I’ll share what I can give you immediately eg. without having to research a lot myself.

Before I start: Here is a good quick overview of getting started with Python in BLender
https://docs.blender.org/api/blender_python_api_current/info_quickstart.html

What you need:

UI Panel
a UI panel that is in the bl_space_type of ‘PROPERTIES’. In this case it will shop up in the object properties tab. But you can also place it in the 3D view tools tap in which case you would use a bl_space_type of ‘TOOL_PROPS’
see more + examples: https://wiki.blender.org/index.php/Dev:Py/Scripts/Cookbook/Code_snippets/Interface
Example


class ObjectPanel(bpy.types.Panel):
    bl_label = "Hello from Object context"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
 
    def draw(self, context):
        self.layout.operator("hello.hello", text='Bonjour').country = "France"

Object stored properties
In blender you can store properties in different locations, for example: Addon preferences, Object properties, Scene properties,… For TexTools I store all settings in the scene. In your case it sounds like you want to store them per object.

At its core this should work:


bpy.context.object["MyOwnProperty"] = 42

Although I don’t like video examples myself here is a good introduction to storing custom properties to objects, it should give you all you need


Read also the user guide on adding custom properties via the interface:
https://docs.blender.org/manual/en/dev/data_system/custom_properties.html

As for dynamic UI’s
You can access object, scene, selection properties pretty much in realtime in the ‘def draw(self, context):’ code. For example in TexTools I very often evaluate input and change icons or labels depending on the input.
https://farm5.staticflickr.com/4627/40389093552_cdb1083840_o.gif
It’s literally just a matter of writing if else … statements and changing icons or labels when plotting down a label
particular GIF example uses this


message = ""
icon = "NONE"
mode = op_mesh_texture.get_mode()
if mode == 'CREATE_FACES':
	message = "Create UV mesh faces"
	icon = "MESH_GRID"
elif mode == 'CREATE_OBJECT':
	message = "Create UV mesh"
	icon = "MESH_GRID"
elif mode == 'WRAP':
	message = "Wrap texture meshe" 
	icon = "POTATO"
elif bpy.context.active_object:
	icon = "ERROR"


col.label(text = message, icon= icon)

Hope this helps

If you don’t want to develop code specifically, you could try your hand at Sverchok