Link/append pre and post handlers #122357

Open
opened 2024-05-28 11:01:35 +02:00 by Nika Kutsniashvili · 4 comments
Contributor

Creating this to-do at the request of Philipp Oeser

For add-ons that are meant to be in production environment support for appending, linking, and library overrides is crucial. While most of the stuff works out-of-the-box pretty well, the absence of handlers for those things make it hard to manually avoid or troubleshoot problems, especially for add-ons that are dealing with custom data, or are meant to be overriding something within Blender.

To give practical use cases, here are examples that are required for Keymesh add-on:

  • Add-on assigns unique ID to each animated object and uses that ID to identify data that should be assigned to that object. In single .blend files those work fine, but when appending or linking there's a big chance that what was unique ID in original file isn't unique in scene file. Object might be assigned 7 in original file, and if import it in a scene where 7 is already taken, it breaks the animation and UI for both objects. To avoid this, I would use append/link handler to check if appended objects ID is already used in the scene, and if it is offset it and give new ID.

(That means of course, that when using handler you should have access to appended data-block somehow. I don't know how possible it is, but even without that assuming append/link makes imported object active, context.active_object would be a great start)

  • Overriding properties: Sometimes add-ons require some Blender properties to be certain way to work. In original .blend file add-on can use operators to adjust them, but linking/appending data in clean file, with wrong property values can break the add-on. To give second example: both link and append operators have "Instance Object Data" enabled by default. That option creates new object for each userless object data that is imported. Since Keymesh object comes with pointers to userless meshes you need to disable that property, otherwise you'll have to delete every object operator has created, and if you're working on dense meshes and it imports big number of them it can freeze Blender. With handler I would be able to always override "Instance Object Data" property to avoid this, even if user forgot to uncheck it.

  • Append/link removes fake user from data-blocks it imports, which can result in data-loss in Keymesh since it relies to userless object data-blocks to exist in the scene. (This might qualify as a bug even, I'm not sure). With handler I would reset fake user on all appended/linked data.

  • I would attach timeline update function on handler, so that when imported object shows correct shape for the current frame, without needing to scrub the timeline.

Creating this to-do at the request of Philipp Oeser For add-ons that are meant to be in production environment support for appending, linking, and library overrides is crucial. While most of the stuff works out-of-the-box pretty well, the absence of handlers for those things make it hard to manually avoid or troubleshoot problems, especially for add-ons that are dealing with custom data, or are meant to be overriding something within Blender. To give practical use cases, here are examples that are required for [Keymesh](https://extensions.blender.org/add-ons/keymesh/) add-on: * Add-on assigns unique ID to each animated object and uses that ID to identify data that should be assigned to that object. In single .blend files those work fine, but when appending or linking there's a big chance that what was unique ID in original file isn't unique in scene file. Object might be assigned 7 in original file, and if import it in a scene where 7 is already taken, it breaks the animation and UI for both objects. To avoid this, I would use append/link handler to check if appended objects ID is already used in the scene, and if it is offset it and give new ID. (That means of course, that when using handler you should have access to appended data-block somehow. I don't know how possible it is, but even without that assuming append/link makes imported object active, context.active_object would be a great start) * Overriding properties: Sometimes add-ons require some Blender properties to be certain way to work. In original .blend file add-on can use operators to adjust them, but linking/appending data in clean file, with wrong property values can break the add-on. To give second example: both link and append operators have "Instance Object Data" enabled by default. That option creates new object for each userless object data that is imported. Since Keymesh object comes with pointers to userless meshes you need to disable that property, otherwise you'll have to delete every object operator has created, and if you're working on dense meshes and it imports big number of them it can freeze Blender. With handler I would be able to always override "Instance Object Data" property to avoid this, even if user forgot to uncheck it. * Append/link removes fake user from data-blocks it imports, which can result in data-loss in Keymesh since it relies to userless object data-blocks to exist in the scene. (This might qualify as a bug even, I'm not sure). With handler I would reset fake user on all appended/linked data. * I would attach timeline update function on handler, so that when imported object shows correct shape for the current frame, without needing to scrub the timeline.
Nika Kutsniashvili added the
Type
To Do
label 2024-05-28 11:01:35 +02:00
Member

Would like to check on this.

Append/link removes fake user from data-blocks it imports, which can result in data-loss in Keymesh since it relies to userless object data-blocks to exist in the scene. (This might qualify as a bug even, I'm not sure)

Think this is on purpose, see #106321

Would like to check on this. >Append/link removes fake user from data-blocks it imports, which can result in data-loss in Keymesh since it relies to userless object data-blocks to exist in the scene. (This might qualify as a bug even, I'm not sure) Think this is on purpose, see #106321
Philipp Oeser self-assigned this 2024-05-28 12:05:45 +02:00
Author
Contributor

You're right it was done in #111042. I assumed it would be the case. That's where handlers would help to restore fake user where it makes sense

You're right it was done in #111042. I assumed it would be the case. That's where handlers would help to restore fake user where it makes sense
Member

Usually, these callbacks come with PRE and POST, for POST, it is more or less straightforward to have the callback fire for each ID linked (using BKE_callback_exec_id), for PRE I wouldnt be sure what to give the callback as an arg... a string (of what we are trying to link -- using BKE_callback_exec_string)?

Another possible thing to consider: if the linked/appended comes with dependencies (other IDs get pulled in as well), would we want the callbacks to fire on them as well (wouldnt thinks so)?

Usually, these callbacks come with PRE and POST, for POST, it is more or less straightforward to have the callback fire for each ID linked (using `BKE_callback_exec_id`), for PRE I wouldnt be sure what to give the callback as an arg... a string (of what we are trying to link -- using `BKE_callback_exec_string`)? Another possible thing to consider: if the linked/appended comes with dependencies (other IDs get pulled in as well), would we want the callbacks to fire on them as well (wouldnt thinks so)?
Author
Contributor

@lichtwerk In Keymesh (at least) all the dependancies that come with appended/linked object can be accessible. If I can access something like context.appended_object I can simply use context.appended_object.keymesh.blocks and I'll access all mesh dependencies it imports with it. I assume that is the case for all other cases as well, therefore I ddon't think callbacks to those are necessary. Only active ID that user chose in file browser.

For pre I'm also not sure, I've been thinking about that but don't have clear idea. If linked/appended ID can be referenced directly in post I think that might be enough?

@lichtwerk In Keymesh (at least) all the dependancies that come with appended/linked object can be accessible. If I can access something like context.appended_object I can simply use context.appended_object.keymesh.blocks and I'll access all mesh dependencies it imports with it. I assume that is the case for all other cases as well, therefore I ddon't think callbacks to those are necessary. Only active ID that user chose in file browser. For pre I'm also not sure, I've been thinking about that but don't have clear idea. If linked/appended ID can be referenced directly in post I think that might be enough?
Iliya Katushenock added this to the User Interface project 2024-05-28 14:49:25 +02:00
Iliya Katushenock added the
Interest
ID Management
label 2024-05-28 14:49:42 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#122357
No description provided.