Addons Enhancements

While porting works in mechanicalblender.org as an addon, I found some limitations i did not like all the workarounds i found, so i decided to create generic addons tasks, so it could be added in blender for everybody. I assume that specific things would not be included, and developing and addon make things easier for users.

I started with this Task

Add Handlers to Addons

As I think they benefit blender, i’ll do my best, but i also assume that community support is needed, so please support this patches, so they do not get the abandoned status.

Thanks!

13 Likes

Awesome initiative, I wish other addon developers with C++ knowledge could support you too and add to your effort :slight_smile:

One of the most important things that we cannot do right now as an addon with the Python API IMHO is to extend classes.

I mean, imagine I want to create a custom type of Empty, I want that empty to have a custom shape, and some custom controls, that’s not possible right now and I have to go through a lot of loops to achieve it.

So adding the capability to extend from a class and customise that class with proper UI and methods would be very helpful :slight_smile:

3 Likes

What do you want to extend?

For example an empty, with a custom shape and some custom properties, also a custom creation function, for example, where you can set some parameters before you end up the creation process.

Picture it, you have a scene with 1000 empties, but 10 of them are empties you use for your addon, when you want to access those 10 empties randomly (and without storing them in a parameter of the scene) you have to loop over those 1000 empties.
If you have a custom empty class (cool_empty) you would have to look only for those “cool_empty” objects.

That’s a simple example, but I’m sure addon developers would be more than happy to provide other examples :slight_smile:

1 Like

@mauge,
this is a much have enhancement… thank you

another use cases…

. addon for viewport undo/redo view matrix changes

. with modal handler, unlock view navigation for standard transform tools/operators

. display warning while entering in edit mode (tab key) if object is procedurally builded or display window settings for adjust it rather than entry in edit mode

I can figure it now. At the moment, the best way to handle that i think is the one you already proposed, having a separate list for this objects.

Added a similar Task, and a simple diff for it.

https://developer.blender.org/T86264

For this one, compiling blender is not needed, as is python only patch.

2 Likes

This looks very useful, I’ve been saying for years that BPY needs a robust event/subscriber delegate system, this looks like the next best thing.

I’m assuming this works with any registered operator, including those coming from addons?

Yes :wink:

Updated the Differential summary adding a simple operator as example for testing.

Uploaded a recent release build for operator handlers tests.

Example script can be found on https://developer.blender.org/D10579

Feedback is of course welcome, as support and advises to get it included in Blender releases!

3 Likes

amazing… I did a undo_view addon to test and working very well.

def view3d_pre(params):
bpy.context.scene[‘old_viewmatrix’] = bpy.context.region_data.view_matrix.copy()
bpy.context.scene[‘old_viewmode’] = bpy.context.region_data.view_perspective #[‘PERSP’, ‘ORTHO’, ‘CAMERA’]
print(‘view-matrix pre’, Matrix(bpy.context.scene[‘old_viewmatrix’]))

def execute():
bpy.context.region_data.view_matrix = Matrix(context.scene[‘old_viewmatrix’])
bpy.context.region_data.view_perspective = context.scene[‘old_viewmode’]

bpy.ops.view3d.rotate.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.move.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.zoom.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.dolly.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.walk.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.fly.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.navigate.handlers.invoke_pre.append(view3d_pre)

bpy.ops.view3d.localview.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.localview_remove_from.handlers.invoke_pre.append(view3d_pre)

bpy.ops.view3d.view_all.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_axis.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_camera.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_center_camer.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_center_cursor.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_center_lock.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_center_lock.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_lock_clear.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_lock_to_active.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_orbit.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_move_qcd_slot.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_pan.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_persportho.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_qcd_slot.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_roll.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.view_selected.handlers.invoke_pre.append(view3d_pre)

bpy.ops.view3d.zoom_border.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.zoom_border.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.zoom_custom_target.handlers.invoke_pre.append(view3d_pre)

bpy.ops.view3d.ndof_all.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.ndof_orbit.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.ndof_orbit_zoom.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.ndof_pan.handlers.invoke_pre.append(view3d_pre)
bpy.ops.view3d.object_as_camera.handlers.invoke_pre.append(view3d_pre)

1 Like

Uo! I always think about the feature as something espeficic to the operator itself :stuck_out_tongue:

As pointed on feature task https://developer.blender.org/T86191#1125789 this kind of things should be allowed to have a better handling in a more general (working always) way, than adding handlers everywhere, as will not work if for example the matrix are changed in another not considered places.

1 Like

yes. I agree… but current solution is oddest (replacing every default view operator with a custom one to save view matrix.)

a region_data’s pre change handler operator would be great.
I think msgbus can do this but any viewport changes are ignored by msgbus. :grimacing:

:open_mouth:

Most changes done internally are ignored by msgbus because they work directly with a pointer: because faster, or because of generic methods (eg Transform). Or just because the coder did not consider that.

1 Like

Uploaded a new build on graphicAll

  • all callbacks are getting context and event,
  • added modal_end handler
  • allow to remove on block.

Next I will spend some time on https://developer.blender.org/T86618 because i would like to insert some menu / options related to existing ones, from an addon.

1 Like

**posting here the same I posted in graphicall…

Thank you for new updated build… :heart: :heart: :heart:

Working really nice.

I think this is a game changer for addon development, now I can address almost all of my missing needs from another DCC modeling tool with minimal effort… :slightly_smiling_face:

I really hope this will catch the attetion of blender devs and be committed in master. :pray: :pray: :pray:

1 Like

Uploaded a build for testing https://developer.blender.org/T86618

Allows an addon developer to place menu options referenced to other options.

1 Like

really digging these addon developer focused improvements you’re making, I seriously hope that blender devs take notice and work with you on getting them integrated into main

2 Likes

Added a new diff, for testing, allowing to add new items to existing enums (EnumProperty)

https://developer.blender.org/D10852

3 Likes

Do not know if there is an standard procedure to show addon info on ui like the splash About window. Not so parametrized and also hidden on preferences -> addons. Let’s say more integrated and easy to find.

Created this task

https://developer.blender.org/T87287

1 Like