5
$\begingroup$

I tried to create an image node in blender with cycles renderer enabled.

My first attempt looks like this:

import bpy
mat = bpy.data.materials["Material"]

nodes = mat.node_tree.nodes
material_output = nodes.get("Material Output")

image = bpy.types.Image(file_format='PNG')
image.file_format = 'PNG'
image.filepath = 'C:\\Users\\Standardbenutzer\\Desktop\\bla.png'

node_texture = nodes.new(type='ShaderNodeTexImage')
node_texture.image = image
node_texture.location = 0,200

links = mat.node_tree.links
link = links.new(node_texture.outputs[0], nodes.get("Diffuse BSDF").inputs[0])

If i execute this code i get the error message:

Traceback (most recent call last): File "\Text", line 7, in TypeError: bpy_struct.new(type): expected a single argument Error: Python script fail, look in the console for now...

In the blender docs i found this:

http://www.blender.org/api/blender_python_api_2_72_1/bpy.types.Image.html#bpy.types.Image

the constructor asks for a ID but even if i set something like 0 i get the same message.

$\endgroup$
3
  • $\begingroup$ Related: blender.stackexchange.com/q/19500/599 $\endgroup$ Commented Jan 31, 2015 at 22:10
  • $\begingroup$ 'RuntimeError: Error: Cannot add node of type CompositorNodeImage to node tree 'S hader Nodetree' $\endgroup$ Commented Jan 31, 2015 at 22:16
  • 1
    $\begingroup$ @binaryBigInt You of course need to adapt that to Shader Nodes, that answer was for Compositor Nodes but it is similar: you can compare here: blender.stackexchange.com/questions/23436 $\endgroup$ Commented Jan 31, 2015 at 23:02

1 Answer 1

6
$\begingroup$

This is how you add image:

import bpy

path = "path_to_the_image"

try:
    img = bpy.data.images.load(path)
except:
    raise NameError("Cannot load image %s" % path)
$\endgroup$
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.