Announcement

Collapse
No announcement yet.

Script Vray attributes?

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

  • Script Vray attributes?

    I've wanted for a long time to MEL script turning on some of Vray's custom attributes (e.g. OpenSubdiv) for all selected objects so that they don't all have to be done manually. I'm not much of a scripter so usually rely on feedback in the script editor for pointers, but when testing with a single object I've never been able to determine which parts of the code that is returned does the work. With Echo All Commands turned on in the script ed. you get a lot of UI callbacks, but I can't find anything like a setAttr or addAttr command. All I want to do is create some simple for-in loops as procedures so that we can turn some of these attrs on and off easily. Can someone point me in the right direction?

  • #2
    template code for iterating through any number of shapes and adding roundedges, displacemnt and the controls

    be sure to select the shape node of your objects (down arrow key if you select the Transform Node in the Outliner, I guess it's the default selection)

    if you want to add another Vray-Custom attribute you have to look up the name in den Documentation in the "Scripting"-Section and change the name in this line vray addAttributesFromGroup $obj "custom_vray_attribute" 1;

    {
    string $selection[] = `ls -selection -long`;
    for($obj in $selection)
    {


    vray addAttributesFromGroup $obj "vray_roundedges" 1;
    vray addAttributesFromGroup $obj "vray_displacement" 1;
    vray addAttributesFromGroup $obj "vray_subquality" 1;
    vray addAttributesFromGroup $obj "vray_subdivision" 1;
    setAttr($obj + ".vrayDisplacementAmount",200);
    setAttr($obj + ".vrayMaxSubdivs",16);
    setAttr($obj + ".vrayEdgeLength",1);
    setAttr($obj + ".vrayDisplacementKeepContinuity",1);
    setAttr($obj + ".vrayDisplacementShift",0);
    setAttr($obj + ".smoothLevel",0);
    setAttr($obj + ".useSmoothPreviewForRender",0);
    setAttr($obj + ".renderSmoothLevel",1);
    setAttr($obj + ".vrayDisplacementStatic",0);
    setAttr($obj + ".vrayDisplacementKeepContinuity",1);
    setAttr($obj + ".vrayMaxSubdivs",6);
    setAttr($obj + ".vrayDisplacementAmount",.15);
    setAttr($obj + ".vrayDisplacementType",0);

    }
    }

    Kind Regards
    Pirmin

    Comment


    • #3
      Thanks. Which "Scripting" section are you talking about -- in the Vray help docs or Maya help docs? I would assume they must be in the Vray docs, but that is part of the problem -- I've never been able to find this, and the lack of intuitive script editor feedback on adding, say, the object ID attribute has made identifying these attrs by name difficult.

      Comment


      • #4
        Most of the time, there is a scripting section at the bottom of the documentation like in the screenshot I attached.

        Another good trick is to "Echo All Commands" in your ScriptEditor under the "History" Tab at the top. It fetches a lot of code but sometimes it's usefull and you may find something that you are looking for


        Kind Regards
        Pirmin

        Comment


        • #5
          Got it, thanks -- never noticed that "Scripting" section at the bottom of the page.

          You can remove the need to select your shape nodes manually like this:

          $objs = `ls -sl`;
          $shapes = `listRelatives -shapes`;

          select $shapes;

          for($shape in $shapes)
          {

          vray addAttributesFromGroup $shape "vray_objectID" 1;
          }

          Comment


          • #6
            Ah yes, the scripting sections on the docs - if you think of ways for us to make this more obvious / useful on the docs - just let me know and we'll think of something.
            Alex Yolov
            Product Manager
            V-Ray for Maya, Chaos Player
            www.chaos.com

            Comment


            • #7
              Well, now that I know they are there.... The script examples are very useful. That said, there seem to be some pages that don't have any at all. Given that some UI actions don't seem to generate any script ed feedback at all it would be useful to have a more thorough list of nodes and attributes (perhaps there is one that I don't know about?). An example that came up today -- was trying to script the color of a dirt map node. Doing this manually doesn't create any feedback at all, so I had to identify the attribute name. The only way I could think of doing it was to RMB and go to "Create Expression".

              Comment


              • #8
                Is there a way to assign a different name to a render element on creation? vrayAddRenderElement seems to be the command, but it won't accept the -n flag (wrong number of arguments). Can't find any other documentation about this command.

                Comment


                • #9
                  Hm, so based on this it seems that the vrayAddRenderElement command is actually calling a script: https://github.com/BigRoy/mayaVrayCo...RenderElements

                  Does that mean it's not possible to change the default naming of these nodes?

                  Comment


                  • #10
                    Originally posted by SonyBoy View Post
                    An example that came up today -- was trying to script the color of a dirt map node. Doing this manually doesn't create any feedback at all, so I had to identify the attribute name. The only way I could think of doing it was to RMB and go to "Create Expression".
                    Are you on 2018.3? Autodesk broke the color attributes with 2018.1 and this was fixed in the recently released 2018.4. So anything in between (2018.1, 2018.2 and 2018.3) have the problem that color attributes (on all nodes, not only the vray ones) do not return echo and are not added to the undo queue.
                    See if that's the case with you. In the meantime, I made a note to add script examples wherever they're missing.
                    Last edited by yolov; 04-09-2018, 10:57 PM.
                    Alex Yolov
                    Product Manager
                    V-Ray for Maya, Chaos Player
                    www.chaos.com

                    Comment


                    • #11
                      Originally posted by SonyBoy View Post
                      Hm, so based on this it seems that the vrayAddRenderElement command is actually calling a script: https://github.com/BigRoy/mayaVrayCo...RenderElements

                      Does that mean it's not possible to change the default naming of these nodes?
                      I don't think we have a way for the user to set the name on creation, as we do this internally. But you can go around it using vrayAddRenderElement - it returns a string with the name (of the node) of the newly created render element. You can wrap it in a string that you can use to rename the node after creation.
                      So something like this should work for you, hopefully:

                      Code:
                      string $createCustomVRayLSRE = `vrayAddRenderElement LightSelectElement`;
                      rename $createCustomVRayLSRE "myCustomLightSelect";
                      OR

                      Code:
                      import maya.cmds as cmds
                      import maya.mel as mel
                      
                      createCustomVRayLSRE = mel.eval('vrayAddRenderElement LightSelectElement')
                      cmds.rename(createCustomVRayLSRE, 'myCustomLightSelect')
                      Btw, I'm giving the LightSelect as an example on purpose, because it's the only render element with a different type - it's a set that expects light objects as members.
                      So if after creation, renaming etc you want to list by type - all vray render elements will be of type VRayRenderElement, but the Light Select will be of type VRayRenderElementSet.

                      Also another thing that might help - if you select a render element from the list in the render settings, the script editor will echo some help for the command to call to create it.

                      Let me know if this helps.
                      Last edited by yolov; 04-09-2018, 10:58 PM.
                      Alex Yolov
                      Product Manager
                      V-Ray for Maya, Chaos Player
                      www.chaos.com

                      Comment


                      • #12
                        Whenever you create a RenderElement with code like vrayAddRenderElement "diffuseChannel"; it is automatically selected by Maya. You can then use the ls command to fetch it into a variable and then use rename to give it a new name

                        Template Code:

                        {
                        vrayAddRenderElement "diffuseChannel";
                        string $RenderE[] = `ls -sl`;
                        print $RenderE[0];
                        rename $RenderE[0] "Your_Pass_Name";
                        }

                        Kind Regards
                        Pirmin

                        //EDIT: It seems yolov was faster and his code seems to be even shorter :O

                        Comment


                        • #13
                          Both look like good solutions. Thanks!

                          Comment

                          Working...
                          X