1
$\begingroup$

I'm Creating some nodes through python script. The problem is that all the nodes are overlapping each over. I just wanna programatically re position those nodes. How to do this?

 imgtx1 = nodes.new('ShaderNodeTexImage')
 imgtx2 = nodes.new('ShaderNodeTexImage')

Just consider these 2 nodes as of now. Thanks in advance!

$\endgroup$
4
$\begingroup$

Every node has it's own size/location properties that are accessible in the node itself.

import bpy
from mathutils import Vector

imgtx1 = nodes.new('ShaderNodeTexImage')
imgtx2 = nodes.new('ShaderNodeTexImage')

#location
imgtx1.location = Vector((200.0, 400.0))

#or
imgtx2.location.x = 100
imgtx2.location.y = 200

#size
# only width changes are allowed within the values of 
# node.bl_width_min and node.bl_width_max
imgtx2.width = 200
imgtx2.width_hidden = 100
| improve this answer | |
$\endgroup$
  • $\begingroup$ This is really helpful! Thanks a lot! @Secrop $\endgroup$ – youhsia May 18 '19 at 11:21
  • $\begingroup$ If I use newmat.location = Vector(500,100) I get NameError: name 'Vector' is not defined. newmat.location.x = -200 works though. $\endgroup$ – edna Jun 18 '19 at 5:11
  • $\begingroup$ @edna, you need to import mathutils... I'll correct the answer. $\endgroup$ – Secrop Jun 20 '19 at 7:58
  • $\begingroup$ Thanks for updating. In 2.80 I found that I don't need it actually. imgtx2.location = -300, 150 works fine. $\endgroup$ – edna Jun 21 '19 at 4:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.