To run this script you need to select the render to Cycles Render.
Then go to Compositing from Screen layout ( in the top of the screen) and select Use Nodes from Material.
This will make a default material with a Diffuse BSDF.
The next step is to select Scripting from Screen layout.
This will allow you to make a script.
Create a new text and add this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import bpy pymat = bpy.data.materials print('material_library = {') for id, i in enumerate(pymat): name = i.name node = i.node_tree.nodes['Diffuse BSDF'] color = node.inputs[0].default_value[:] color = tuple(round(j, 4) for j in color) separator = ('' if id == len(pymat)-1 else ',') print(' \'{}\': {}{}'.format(name, color, separator)) print('}') |
Press keys Alt+P or run the script from Text – Run Script.
When you click on tabs or select something the print function will print the python code into the Console output area.
This can be used to see parts of the python code from add-ons or Blender API.
Example with Archimesh addon :
You need to have this addon install and press the books button.
The result of this source code is shown into console output and can be used with console shell to add books into your Scene:
1 | >>> bpy.ops.mesh.archimesh_books() |