Is there a way to convert a cycles material node setup to a python script which in it's turn can generate a new material with the same node setup?
Also, is it possible to somehow retain the x,y postion of these nodes for easy readability?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityIs there a way to convert a cycles material node setup to a python script which in it's turn can generate a new material with the same node setup?
Also, is it possible to somehow retain the x,y postion of these nodes for easy readability?
You can probably create a node_group programmatically and then instantiate the group.
Do you know what the setup looks like in advance? I suggest you load a node_group from a template Blender scene.
Here is an example of how I append nodes from external Blender scenes, I personally like this approach a lot, you can find the source files here:
def import_material_node_groups():
""" Load the archilogic cycles material node groups from the node-library.blend file.
"""
filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources/node-library.blend')
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.node_groups = data_from.node_groups
for node_group in data_to.node_groups:
log.debug('Importing material node group: %s', node_group.name)
node_group.use_fake_user = True
# Material group node (The datablock is not yet assigned)
node_group = node_tree.nodes.new('ShaderNodeGroup')
node_group.location = (0, 0)
node_group.node_tree = D.node_groups['group-name']
Alternatively you can programmatically create a node group (see this question, and then instantiate it like shown above.
Each node comes with a location data, so you can save your node locations with "location" or you can programmatically order your nodes if you know what they should look like.