0
$\begingroup$

I’ve got an add on for making objects parametrically. What I want is a way to specify that the mesh is immutable and thus can’t be edited.

Currently I do this by generates a new .blend file - linking the object into your scene and the addon checks every second to see if the underlying file has changed. It’s really inefficient, you can’t change the materials etc and there’s an annoying lag.

What I really want is either a way to signal blender that the file has been updated (without needing to poll) or better yet, a way to indicate that the mesh can’t be modified/edited (I’m guessing prevent creation of a Bmesh)

Is there anyway to do that in a plug-in?

$\endgroup$
2
  • $\begingroup$ How about create your object in a collection and then make an instance for that collection. Then only show the instance to user by hiding the real one in view port? $\endgroup$
    – HikariTW
    Commented Aug 21, 2020 at 2:05
  • $\begingroup$ interesting idea; it kind of works. I also realised I can do a similar thing by just linking the mesh and adding it to a new object $\endgroup$ Commented Aug 21, 2020 at 2:16

1 Answer 1

1
$\begingroup$

I've found a few solutions to this.

The nicest is the create the mesh in another .blend file, then link that in and attach to a local object. This gives you a linked icon in the outliner (for the mesh) and prevents mesh changes - downsides are you need to work with multiple files.

@HikariTW's suggestion of Collection instancing works; though doesn't give quite the experience I was looking for.

The other solution is to just watch for mode changes and block them. This seems to work pretty well; something like this works

import bpy

def restrict_edit_mode(object, data, unk=None):
    # XXX: check if bpy.context.object to see if it applies
    # remove the move into edit mode; so you can't undo into it
    bpy.ops.ed.undo()
    # make sure we're always in object mode, without this you can
    # end up in the wrong mode by undo/redo combos
    bpy.ops.object.mode_set(mode='OBJECT')
    # XXX: do something instead


# registering on a per oject basis seems unreliable
# but doing it for everything works pretty well
handle = object() 
subscribe_to = bpy.types.Object, "mode"


bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=handle,
    args=(None,),
    notify=restrict_edit_mode,
)
'''
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .