BrendanParmer / NodeToPython

Convert Blender node groups to a Python add-on
MIT License
236 stars 21 forks source link

Suggestion: Code to text block or clipboard #40

Closed Erindale closed 1 year ago

Erindale commented 1 year ago

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.

Talvara commented 1 year ago

This would be super useful for my needs as well,

I'm trying to make Blender act a little like 'Houdini engine' for Unity, If I was able to rebuild a predesigned node network through python code supplied by unity, then I could avoid loading and unloading .blend files making the process easier to obscure from the end user.

BrendanParmer commented 1 year ago

Think this would be a good option to have.

The main reason it creates a whole add-on right now is to guarantee referenced assets (namely images right now) in the node network are properly included, but I could see cases where that's either unnecessary or unwanted behavior.

Shouldn't be too hard to implement; I'll try to get a chance to work on it in the next few weeks.

In the meantime, the outermost [name]_node_group() function in the generated init.py files handles all the logic for creating a node network, so copying this will do the trick. It is a bit of a pain to unzip the addon and do this manually since these can get pretty long. You'd also have to make sure it isn't loading images or setting their defaults, too, which you can see by searching for #load image [name] comments. I think those are the only issues you might come across though

BrendanParmer commented 1 year ago

Got a rough implementation of this right now over at PR #53. There's a couple complications with how to save the script, so I'd like to hear everyone's thoughts on how best to implement this over at discussion https://github.com/BrendanParmer/NodeToPython/discussions/54