Compositor node type-string inconsistency and problematic API changes #35336
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#35336
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
%%%--- Operating System, Graphics card ---
Tested on:
Ubuntu 13 with Nvidia GeForce 9600GT
Windows7 with AMD Readon HD 6800
Bug on 2.67
Works on 2.66
There have been API changes in the type property of compositor nodes.
For instance, what used to be 'R_LAYERS' is now 'CompositorNodeRLayers'.
So using the old type string fails with an obscure error:
Traceback (most recent call last):
RuntimeError: Error: Node type R_LAYERS undefined
That by itself isn't a bug I guess, though it breaks backward compatibility with scripts such as my render layer and pass file saver:
https://github.com/Tlousky/production_scripts/blob/master/save_all_renderlayers_and_passes.py
But when you check the type of an existing render layers node, you get back the old string, instead of the new one:
This one is a bug I assume, as it doesn't enable you to check the new type string of a node you created manually.
bpy.data...nodes["Render Layers"]
'R_LAYERS'
There's also no direct way to see all the new type strings. These should probably be documented here:
http://www.blender.org/documentation/blender_python_api_2_67_release/bpy.types.Node.html
The API also doesn't inform on the new types in any way, when you use autocomplete to create a new node:
autocomplete with ctrl + space only outputs this:
new()
Nodes.new(type)
Add a node to this node tree
It would be useful if both the autocomplete and the error of using a wrong type string will output a list of the existing types.
It would also be nice to have some backward compatibility. I assume the new changes are because of the new possibilities brought by python nodes, but maybe some way around this is possible.
Open a node editor and a python console and tick "use_nodes":
Reference the node tree in the console with:
tree = bpy.context.scene.node_tree
Try to create a new render layers node with:
tree.nodes.new('R_LAYERS')
or:
tree.nodes.new(type='R_LAYERS')
Manually create a new render layers input node through the node editor.
Access it in the python console through the tree object, and print its type:
tree.nodes[use_node_name_or_index].type
Thank you!%%%
Changed status to: 'Open'
%%%I amended my addon
https://github.com/Tlousky/production_scripts/blob/master/save_all_renderlayers_and_passes.py
It now supports both blender 2.67 and 2.66, so it won't be helpful to test it in case you were planning to.
But the changes in this script reflect the API changes and the problem they could represent.%%%
%%%This is indeed an API change: the nodes.new() function now expects the node.bl_idname string, which is a generic type identifier like those used for other registerable blender types (operators, menu, etc.). The "type" property otoh is an enum identifier based on the old hardcoded integer identifiers, which are not suitable for dynamically regsitering nodes. It is basically deprecated now, it only still exists for the purpose of keeping existing scripts working and should be avoided (so replace nodes.new(somenode.type) with nodes.new(somenode.bl_idname)).
A possible solution for backward compatibility could be to use the old enum "type" property as a fallback: if the given bl_idname string is not found it could try the enum identifier instead. But this could lead to unforeseen problems with ambiguous names too and just pollutes the API further, so i'd rather not do that unless it's absolutely necessary.
Displaying a set of possible choices with autocomplete is also difficult. For enums it only works with fixed enum items lists, so using a dynamically generated enum won't be any help (the enum generator callback depends on context, which generally doesn't match for plain api calls).%%%
%%%Thanks for your reply, Lukas.
The important thing for me was to have a consistent way to know what string to use to create a node through the nodes.new() function.
Since checking a node's bl_idname does that, it solves my problem, at least for the next versions (for backward compatibility, I just check the
version and use a string to match).
The reasons for the change make a lot of sense.
Your explanation, or the essence of it, should probably be documented somewhere (nodes.new() docs probably?).
Cheers%%%
%%%Added a hint in the doc string for nodetree.nodes.new() now, consider this fixed.%%%
Changed status from 'Open' to: 'Resolved'