Announcement

Collapse
No announcement yet.

simple Mel Script (Noob question) - change all vraymtl to GGX

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • simple Mel Script (Noob question) - change all vraymtl to GGX

    Hi everyone,

    I am fairly new to Maya, after changing over from 10 years of 3ds max, and therefor even more n00b at Mel/Python.

    Goal:

    I am trying to write a simple script that will select ALL vraymtl in the scene, and change the BRDF to GGX (from the default blinn or what ever). p.s. why is this not default in 3.1 already?

    I someone was kind of enough to write something for me on the max forums, that does exactly this in max... but now.. Maya.

    Problem:

    I simply don't know Mel well enough to figure it out.

    I have found the basic commands of selecting a specific vraymtl and changing its BRDF but, I can't seem to figure out how to mass select by type of material.

    Thanks in advance guys!

    EDIT:

    So I found this other script that randomises colours in diffuse and changed it.

    "
    // User must select bunch of materials first (maybe inside Hypershade)

    //store selected material as an array of String
    string $materials[] = `ls -sl` ;
    //loop through new selection of materials
    for($mat in $materials)
    {
    //get attributes on material
    string $attrs[] = `listAttr -v -k -u $mat` ;
    //loop through every attribute
    for($a in $attrs)
    {
    $randomR = rand(0,1);
    $randomG = rand(0,1);
    $randomB = rand(0,1);
    //if the attribute is diffuse, then set the attribute
    if($a == "brdfType")
    {
    setAttr ($mat + ".brdfType") 3;
    }

    }
    }
    "

    This actually works! but I am pretty sure it's bloated with stuff I don't need?

    Is there a better way of looking for the brdf attr ?

    "
    //loop through every attribute
    for($a in $attrs)
    {
    $randomR = rand(0,1);
    $randomG = rand(0,1);
    $randomB = rand(0,1);
    "

    thanks
    Last edited by thomaskc; 15-09-2015, 06:39 PM.

  • #2
    You can find out class of your material by typing nodeType myMaterial;

    Then you can use the following:

    string $phx[]= `ls -type "VRayMtl"`;


    int $num = size ($phx);

    for ( $i=0; $i<$num; ++$i )
    {
    catchQuiet (`setAttr ($phx[$i] + ".brdfType") 3`);


    };

    However, if you just select your materials in the channel box then you can change brdf type to anything you want and it will affect the selected, however they are all must be vray materials so they all must have the same set of attributes.
    Dmitry Vinnik
    Silhouette Images Inc.
    ShowReel:
    https://www.youtube.com/watch?v=qxSJlvSwAhA
    https://www.linkedin.com/in/dmitry-v...-identity-name

    Comment


    • #3
      Interesting, thanks.

      EDIT: excellent! your little script works the same way! much smaller. very nice. /EDIT

      The hack script I stole and changed works when I have a range of different material types in the hypershade, and I just do a select all shaders and materials command from the shelf. Then run my script.

      It currently only changes the vraymtl's which is perfect, as at least the standard mtl doesn't have that attribute.

      I would love for it to be a 1 btn solution, so that it worked by selecting everything in the scene, without having to open up the hypershade. Or maybe even if it automatically opened the hypershade, selected all shaders, ran the script and closed hypershade.

      Problem I'm having with that is that I can't seem to get any listener feedback on those commands, open hypershade... edit -> select by type -> shading groups and materials. ?

      Thanks!
      Last edited by thomaskc; 15-09-2015, 07:01 PM.

      Comment


      • #4
        Hmm why would you need to have hypershade or select them? This script simply says - list any node which are VrayMtl, then go through and set its brdfType to ggx. CatchQuiet means that even if it errors for example on material which has no brdf attribute, it will still continue running through the entire loop rather then stop.

        You can make this into a button I don't see why not?
        Dmitry Vinnik
        Silhouette Images Inc.
        ShowReel:
        https://www.youtube.com/watch?v=qxSJlvSwAhA
        https://www.linkedin.com/in/dmitry-v...-identity-name

        Comment


        • #5
          Oh I see!!

          I'm sorry, I didn't realise this worked without selecting anything! Amazing! exactly what I was after.

          Yes, I have made a button and it works wonders.

          Great for quickly converting assets.

          Thank you very much!

          p.s. sick showreel!

          Comment


          • #6
            Nerd python 1 line :

            [cmds.setAttr("%s.brdfType" % x, 3) for x in cmds.ls(type="VRayMtl")]
            www.deex.info

            Comment

            Working...
            X