Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop creating new node group if exist #70

Open
fmnijk opened this issue Nov 19, 2023 · 2 comments
Open

Stop creating new node group if exist #70

fmnijk opened this issue Nov 19, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@fmnijk
Copy link

fmnijk commented Nov 19, 2023

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.

@BrendanParmer BrendanParmer self-assigned this Dec 2, 2023
@BrendanParmer
Copy link
Owner

I like the idea; I think it's important to have a way to not clutter up your node groups.

I think the trouble is relying solely on the name to tell if a node tree is already in the scene. Let's say we've got a tree "Geometry Nodes" doing x that we convert to a Python add-on. But if a user has a different tree "Geometry Nodes" doing y already in their project before running the add-on, then the add-on won't generate the intended x tree. There'd need to be a check to compare the nodes of the x group with the y.

At some point I'd like to have that node tree comparing function anyways; it'd certainly make testing NodeToPython a lot easier and more robust. Can't say I've looked into it too much yet, but if anyone knows a quick way I'm open to implementing this.

In absence of that comparison function, I'm open to some sort of "Try to reuse node groups" checkbox you could set for the generated add-on's operator, which would do just the name check.

@BrendanParmer BrendanParmer added the enhancement New feature or request label Dec 2, 2023
@BrendanParmer BrendanParmer removed their assignment Dec 2, 2023
@fmnijk
Copy link
Author

fmnijk commented Dec 3, 2023

Currently it will use exist node group but still add a new node group. So the code I provided is a quick fix.

I think a checkbox is a good idea. Currently I rename node groups before exporting if I don't want it to reuse exist node groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants