Hello to all,
I am playing a little with blender python,
my objective is to use blender to open HDRI image, and show them in background.
I have 2 different problems:
but first here is the code.
import bpy
#mettre en place Cycle et le node tree
scn = bpy.context.scene
scn.render.engine = 'CYCLES'
scn.world.use_nodes = True
wd = scn.world
# effacer tout ce qui traine, et vlan
OBJJ= bpy.ops.object
OBJJ.select_by_type(extend=False, type='MESH')
OBJJ.delete()
OBJJ.select_by_type(extend=False, type='LAMP')
OBJJ.delete()
#creer une texture y mettre l'image, connectrer tout ça.
bpy.ops.texture.new()
nt = bpy.data.worlds[wd.name].node_tree
#désolé pour le naming, c'est de l'emprunt
gradNode = nt.nodes.new(type="ShaderNodeTexEnvironment")
backNode = nt.nodes['Background']
gradNode.location.x = backNode.location.x-300
gradNode.location.y = backNode.location.y
gradColOut = gradNode.outputs['Color']
backColIn = backNode.inputs['Color']
nt.links.new(gradColOut, backColIn)
#Une image sur mon PC, ref
imagew=bpy.ops.image.open(filepath="C:\\IMG_3015.JPG", directory="C:\\", files=[{"name":"IMG_3015.JPG", "name":"IMG_3015.JPG"}], relative_path=True, show_multiview=False)
gradNode.select=True
#gradNode.image=imagew
I can not find a way to set active the Display>World bacground
I tried:
bpy.types.SpaceView3D.show_world
bpy.context.space_data.show_world = True but it is logic.
There is surely something with
bpy.data.screens[âScriptingâ].
but I canât find the way.
I also tried:
for area in bpy.context.screen.areas:
if area.type == 'SpaceView3D':
area.show_world = TRUE
Also I need to connect the image. with the node
gradNode.image=imagew
does not work.
A little bit long Post, sorry for this.
I will really really appreciate your help.