0

I almost have no clue regarding python and scripting, and I was wondering if there is a simple script to create two nodes in the shader editor.

Something like this:

uv map to image texture shader editor

UV map → Image texture

That's it. but every time I try to copy from the info window I get errors in the console, please help!

four two
  • 980
  • 1
  • 8
  • 18
  • Node types in your case: ShaderNodeUVMap and ShaderNodeTexImage – brockmann May 07 '20 at 11:03
  • @brockmann Hi, I understand that I need to use node types but as I said I am a complete noob and I just can't understand how to call the nodes and how to connect them. i have seen this post https://blender.stackexchange.com/questions/145882/blender-scripting-connect-nodes but still when i try to connect other nodes rather than the principled bsdf i get an error and unable to connect – four two May 07 '20 at 13:28
  • you can where i got to at: https://ctxt.io/2/AABAG2QCFA – four two May 07 '20 at 13:32
  • All pretty well explained in the dupe (no need for that other post). Take your time and try to understand it. To get the ball rolling: https://pastebin.com/VWMwGhmP – brockmann May 07 '20 at 14:43
  • Okay, thanks you – four two May 07 '20 at 14:52
  • Hi @brockmann, could you please help me with this? I am trying to create an operator button to lunch the script (i have amended it a bit to suit my needs better) but i keep getting an 'invalid bl_idname' error, i was looking all over and trying to figure it out but no luck :/ pls help: https://pastebin.com/T4eyauft – four two May 08 '20 at 15:48
  • You need an execute method as already explained to you: https://blender.stackexchange.com/a/167870/31447 (Try to understand: 2 Operator). Also change bpy.context.active_object.active_material.name to context.active_object.active_material.name. – brockmann May 08 '20 at 16:04
  • @brockmann okay thank will look into it – four two May 08 '20 at 17:48
  • @brockmann LOWER CASE?! I was ripping my hair out! haha :) (class OBJECT_OT_fancy_tool (and bl_idname = "object.fancy_tool") https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons#Naming – four two May 08 '20 at 18:41
  • thanks for the lesson, now i need to create a check for materials otherwise it raises an error, thanks again hope it wont be too complicated – four two May 08 '20 at 18:43
  • See my answer again on the the poll method (2 Operator). Add a poll(cls, context) and return context.object.active_material is not None, done. (will grey out the button) – brockmann May 08 '20 at 19:41
  • @brockmann Sorted! :) thanks for all your help, I really like automating things in blender for my workflow, helps a lot.. I guess I will learn, slowly.. https://pastebin.com/dRfj1wKQ – four two May 08 '20 at 22:10
  • Looks good. Suggest to add bl_options = {'REGISTER', 'UNDO'} to the operator (makes it possible to undo its execution).... Further reading: https://blender.stackexchange.com/questions/57306/how-to-create-a-custom-ui – brockmann May 08 '20 at 22:18
  • @brockmann ok, great idea! Thanks – four two May 09 '20 at 12:21

0 Answers0