brendanparmer / nodetopython Goto Github PK
View Code? Open in Web Editor NEWConvert Blender node groups to a Python add-on
License: MIT License
Convert Blender node groups to a Python add-on
License: MIT License
Current placement doesn't make much sense. Additionally, a user should just be able to select the node group from a list of options instead of having to type out its full name
The Name attribute of nodes is not replicated when exported as a script. It is used to name the variable in the resulting script, but the attribute isn't initialized with the name.
This is what I get from a Value node currently:
#node Foo
foo = paint_visualizer_002.nodes.new("ShaderNodeValue")
foo.label = "FooLabel"
But would be great if it also populated name, like this:
#node Foo
foo = paint_visualizer_002.nodes.new("ShaderNodeValue")
foo.name = "Foo"
foo.label = "FooLabel"
file.write((f"{inner}if {str_to_py_str(nt_name)} in bpy.data.node_groups:\n"))
file.write((f"{inner}\treturn\n"))
file.write((f"{inner}else:\n"))
file.write((f"{inner}\t{nt_var}"
f"= bpy.data.node_groups.new("
f"type = \'ShaderNodeTree\', "
f"name = {str_to_py_str(nt_name)})\n"))
file.write("\n")
Something like this I think.
Traceback (most recent call last):
File "/Applications/Blender.app/Contents/Resources/3.3/scripts/modules/addon_utils.py", line 421, in disable
mod.unregister()
File "/Users/zhangbinqi/Library/Application Support/Blender/3.3/scripts/addons/node_to_python.py", line 464, in unregister
bpy.utils.unregister_class(NodeToPython)
RuntimeError: unregister_class(...):, missing bl_rna attribute from 'RNAMeta' instance (may not be registered)
Currently it
It looks like the initial values on a curve do not get removed when new values are added.
Above, How the curves are in the geometry nodes.
Below, How the curves are when using the addon created for these geometry nodes.
Ran into this when trying out the plugin on this fantasy tree by RC12
https://rc12.gumroad.com/l/fantasytree
Reprosteps:
Hey Brendan,
Cool project. I'm a coder just learning blender, I would love to explore some geo node's I found online as code.
If you mean Object in the outliner panel I don't see the option there after installing your script as an addon.
Node network still functions the same, it's just real ugly
I tried to use the NodeToPython add-on to convert Material Node Groups in Blender 4.0, but it gives the following error:
Python: Traceback (most recent call last):
File "C:\ [...] \Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\materials.py", line 246, in execute
process_mat_node_group(nt, level, node_vars, used_vars)
File "C:\ [...] \Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\materials.py", line 192, in process_mat_node_group
process_mat_node_group(node_nt, level + 1, node_vars,
File "C:\ [...] \Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\materials.py", line 212, in process_mat_node_group
group_io_settings(node, file, inner, "output", nt_var, node_tree)
File "C:\Users\Golden Dragon\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\utils.py", line 276, in group_io_settings
ntio = node_tree.outputs
AttributeError: 'ShaderNodeTree' object has no attribute 'outputs'
I'm pretty sure it's because of Blender 4.0's new NodeTrees system.
I would love to have it fixed.
(By the way, thanks for the great add-on, it really helps me!)
Rather than creating an addon from scratch, I mainly want to "copy" my node tree into existing code.
Maybe something where the code starts from creating a new node_group datablock, and adds all the nodes and links rather than the full boilerplate and zip version. That way I can just insert the code to my addons where I know when it gets to it, it'll just create a copy of my node graph and then continue with what I need afterwards. I wouldn't even assign it to a modifier or anything either, I'd leave that up to the end user to integrate the code.
Separate code further, with different files for
Nevermind - I figured it out. Great add-on! Thank you for this.
Example, an capture_attribute node have 5 inputs called 'Value', so when creating links like
aaaaa.links.new(radius.outputs["Radius"], capture_attribute.inputs["Value"])
, and using Float, it doesnt create the link properly.
changing "Value" with 2 aaaaa.links.new(radius.outputs["Radius"], capture_attribute.inputs[2]
), works as intended
ps. just seen this issue was closed before.
Add new Geometry Nodes from Blender 3.4 or research if the API lets us get all the necessary info about each node without hard-coding them in
While using re-route node, I am getting several different types of errors. It seems re-route node is either not handled correctly or not tested extensively. The error msg varies from case to case. Sometimes it says, 4 default values are expected instead of 3, sometimes it says that a set is expected instead of float. It seems the error msg depends on the type of nodes the re-route node connects to. Not every time it throws an error. So a rigorous testing is needed with complex node trees having extensive use of reroute nodes.
We use re-route node for better formatting. So one idea can be to do away with this altogether and create a direct link between the source and the destination nodes. That is what I did for some of my projects and it worked correctly. The same thing can be automated, so the add-on won't include the re-route nodes. That is just a workaround in case the original problem cannot be fully resolved.
Some default values for nodes are set in the output socket list. Currently the addon doesn't handle this
The addon adds in the points for the curves, but it won't update the node.
Thought there might've been a refresh or update function. If not, we may be able to hack it by adding and deleting a point.
The add-on currently sets the geometry node input default values, but not the actual inputs used. For example, images inputs don't have a default_value
attribute and aren't set. This shouldn't be too hard a fix. There maybe should be a UI option to disable this, as it may not always be wanted.
Geometry Nodes
Shader Nodes
Compositor Nodes
General
NodeTree
-> NodeTree.interface
in 4.0+Would be cool to do it with materials too
GeometryNodeStringToCurves
does not initialize its font parameter
Constant variable names generated by the add-on (like those for the material, a modifier, etc) should not be used as node variable names
Let's say we turn a tree into python, and the tree has a group node using tree called "A", which does x. If there's already a group called "A" (doing y) in the scene when we run the generated add-on, then the generated add-on defaults to the group doing y, which could result in errors
Looks like Blender doesn't like it if you register two add-ons of the same name, investigate further what issues can arise and potential fixes
Currently the script just looks up what settings (ex. Vertex/Edge/Face/Face Corner domain options) a node needs to be set with a hard-coded dictionary. This will be increasingly more difficult to maintain many versions of Blender as it grows, and is a bit of a headache everytime they release a new version. By programmatically determining the node settings, then NodeToPython should be compatible with several different versions without much maintenance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.