3
$\begingroup$

DISCLAIMER: I rewrite my post upon the latest success to not flood my own post with already solved parts so I left only the part that really is still not working...

PROBLEM: I need to replace all nodes of one material with all nodes of another linked material from another external .blend file via script.

I ALREADY HAVE ALMOST COMPLETELY WORKING SCRIPT NOW ALL MADE BY MYSELF AT LEAST, except the last thing: copying links between nodes...

Does anyone know how exactly write those two parameters, please?

I am using Blender v2.70.5

P.S.: I need strictly SCRIPT BASED ANSWERS ONLY...I know how to do it manually, of course

$\endgroup$
  • $\begingroup$ The answer may be more complex than you hope. There is a rather large contrib addon called online_material_library that exports materials to xml and imports them. There is also a patch that updates it for the new group api as well as support for nested groups. Maybe you could use that or adapt it to bypass the xml file step. $\endgroup$ – sambler May 13 '14 at 7:45
  • $\begingroup$ @sambler: did you noticed I edited my post stating I WAS ABLE TO DO IT except the last part of simple copying links from nodes? ;) So now I think it can be quite easily done like this I just still didn't figured out how to extract just the values itself from every link in node.links, or even better said: I am able to obtain every link values but when I try to apply it to nodes it says there is problem with type of value $\endgroup$ – bublible May 13 '14 at 11:09
  • $\begingroup$ @admins: please flag this post as [SOLVED] as I come to solution myself as described above...thanx ;) $\endgroup$ – bublible May 13 '14 at 16:26
  • $\begingroup$ @bublible Feel free to put your script in an answer below and accept it. Answering your own question is in fact encouraged, and to be "solved" a question needs an accepted answer. $\endgroup$ – gandalf3 May 13 '14 at 18:44
1
$\begingroup$

So I finally made it myself again after several hours of playing with the code (see I am actually FLASH ActionScript2 guy so it took me like 2 weeks to understand syntax of Python, its objects etc. and get used to it but now I have fully working script!!!).

The right solution is this:

# ...some quite long code here and now:
for r in _mNews.links: 
    _mOld.links.new(_mOld.nodes[r.from_node.name].outputs[r.from_socket.name], _mOld.nodes[r.to_node.name].inputs[r.to_socket.name])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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