Announcement

Collapse
No announcement yet.

Apply VRay Attributes "subdivision" to all selected objects at once

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

  • Apply VRay Attributes "subdivision" to all selected objects at once

    Hello guys!

    I was looking for a python or mel script that apply a VRay Attributes "subdivision" level to each selected object at once.

    I found something on the web, but looks like something is wrong.
    Didnt work that script for me.

    import maya.cmds as cmds
    import maya.mel as mel

    def makeVrayAttributes(startID=1):
    sel = cmds.ls(sl=1)
    currentID=startID
    for i in sel:
    # get renderable shape nodes relative to transform, iterate through and apply subdivision
    shapes = cmds.listRelatives(i,s=1,ni=1)
    if shapes:
    for s in shapes:
    melCmd = "vray addAttributesFromGroup "+s+" vray_subdivision 1"
    mel.eval(melCmd)
    melCmd = "vray addAttributesFromGroup "+s+" vray_subquality 1"
    mel.eval(melCmd)
    # apply object ID to xform. i don't like giving individual shapes IDs.
    melCmd = "vray addAttributesFromGroup "+i+" vray_objectID 1"
    mel.eval(melCmd)
    cmds.setAttr(i+'.vrayObjectID',currentID)
    currentID += 1
    Do you have any idea how to write a script to turn on the subdivision for each selected object at once?

    I tried also to apply this over the VRay Shelf but you need to do this also manually and it will make a lot of nodes.

    I will appreciate any help because I have a lot of objects in my scene (just 2505 objects that require some time if I do one by one)

    Cheers!
    DE: ERFINDER des Elektroautos „SION"
    EN: INVENTOR / FOUNDER of the electric vehicle "SION".


    Computer #1 (Main) : Windows 10 PRO │ 2xXEON │128 GB │Quadro M4000 │ Quadro K4000 │ MaYa │vRay 5 │Phoenix FD 4 │

    Even I have a powerful Computer ... I NEED CHAOS CLOUD !

  • #2
    The indenting of the script is broken. Python scripts require proper indenting in order to work.
    Do you have the link to the original script?
    Also this script assigns consecutive objectIDs to your objects. Do you want this?
    And the last problem is that this script just defines a function. You need to execute it to get the result you're after.

    The modified script that seems to work:
    Code:
    import maya.cmds as cmds
    import maya.mel as mel
    
    def makeVrayAttributes(startID=1):
        sel = cmds.ls(sl=1)
        currentID=startID
        for i in sel:
            # get renderable shape nodes relative to transform, iterate through and apply subdivision
            shapes = cmds.listRelatives(i,s=1,ni=1)
            if shapes:
                for s in shapes:
                    melCmd = "vray addAttributesFromGroup "+s+" vray_subdivision 1"
                    mel.eval(melCmd)
                    melCmd = "vray addAttributesFromGroup "+s+" vray_subquality 1"
                    mel.eval(melCmd)
            # apply object ID to xform. i don't like giving individual shapes IDs.
            melCmd = "vray addAttributesFromGroup "+i+" vray_objectID 1"
            mel.eval(melCmd)
            cmds.setAttr(i+'.vrayObjectID',currentID)
            currentID += 1
    
    makeVrayAttributes()
    You can remove the code after "# apply object ID" to prevent the script from adding object id attributes to your nodes.
    V-Ray developer

    Comment


    • #3
      Hi Petrov!
      How you doing!

      Thank you fr replying to this.

      Well Im not a script pro. Have only basic knowledge using mel script.

      Here is the original post.

      https://www.reddit.com/r/Maya/commen...butes_to_many/

      What do mean with:
      - this script assigns consecutive objectIDs to your objects.
      consecutive

      Well I just want to active some properties for each selected object.
      1. VRay Attributes Subdivisions
      2. Subdivision and Displacement Quality
      3. Displacement control
      4. Object ID

      Everything that is under the VRay Attributes tab.
      At the moment I was only testig the "subdivisions" and the "object ID"

      I will appreciate your help a lot.
      Thank you!

      Cheers!
      DE: ERFINDER des Elektroautos „SION"
      EN: INVENTOR / FOUNDER of the electric vehicle "SION".


      Computer #1 (Main) : Windows 10 PRO │ 2xXEON │128 GB │Quadro M4000 │ Quadro K4000 │ MaYa │vRay 5 │Phoenix FD 4 │

      Even I have a powerful Computer ... I NEED CHAOS CLOUD !

      Comment


      • #4
        Another option is to connect all objects to a V-Ray displacement override set and to add subdivision attributes to it (without really using the displacement functionality).

        Best regards,
        Vlado
        I only act like I know everything, Rogers.

        Comment


        • #5
          this is my script that I use all the time. Select your objects in the outliner, viewport or however you like. Press "Cursor down" to get the shape node and then run this script
          {
          string $selection[] = `ls -selection -long`;
          for ( $object in $selection )
          {
          vray addAttributesFromGroup $object "vray_objectID" 1;
          vray addAttributesFromGroup $object "vray_subdivision" 1;
          vray addAttributesFromGroup $object "vray_subquality" 1;
          vray addAttributesFromGroup $object "vray_displacement" 1;
          setAttr($object + ".smoothLevel",0);
          setAttr($object + ".useSmoothPreviewForRender",0);
          setAttr($object + ".renderSmoothLevel",5);
          setAttr($object + ".vrayDisplacementStatic",0);
          setAttr($object + ".vrayDisplacementKeepContinuity",1);
          setAttr($object + ".vrayMaxSubdivs",6);
          setAttr($object + ".vrayDisplacementAmount",50);
          }
          }
          just comment out the lines you don't need and adjust the attributes to the values you like

          Comment


          • #6
            Hi vlado,
            Thnx! Will this is an option, but I prefered the script from t.petrov
            DE: ERFINDER des Elektroautos „SION"
            EN: INVENTOR / FOUNDER of the electric vehicle "SION".


            Computer #1 (Main) : Windows 10 PRO │ 2xXEON │128 GB │Quadro M4000 │ Quadro K4000 │ MaYa │vRay 5 │Phoenix FD 4 │

            Even I have a powerful Computer ... I NEED CHAOS CLOUD !

            Comment


            • #7
              Originally posted by vfx_film_televsion View Post
              this is my script that I use all the time. Select your objects in the outliner, viewport or however you like. Press "Cursor down" to get the shape node and then run this script


              just comment out the lines you don't need and adjust the attributes to the values you like

              Thank you vfx_film_television

              Unfortunately your script didnt work for me.
              I tried also in that way without adding a vray addAttributesFromGroup.
              This is new for me, but even with your script nothing happens

              Im using the t.petrov s script wich work just AWESOME!
              DE: ERFINDER des Elektroautos „SION"
              EN: INVENTOR / FOUNDER of the electric vehicle "SION".


              Computer #1 (Main) : Windows 10 PRO │ 2xXEON │128 GB │Quadro M4000 │ Quadro K4000 │ MaYa │vRay 5 │Phoenix FD 4 │

              Even I have a powerful Computer ... I NEED CHAOS CLOUD !

              Comment


              • #8
                Originally posted by t.petrov View Post
                The indenting of the script is broken. Python scripts require proper indenting in order to work.
                Do you have the link to the original script?
                Also this script assigns consecutive objectIDs to your objects. Do you want this?
                And the last problem is that this script just defines a function. You need to execute it to get the result you're after.

                The modified script that seems to work:
                Code:
                import maya.cmds as cmds
                import maya.mel as mel
                
                def makeVrayAttributes(startID=1):
                    sel = cmds.ls(sl=1)
                    currentID=startID
                    for i in sel:
                        # get renderable shape nodes relative to transform, iterate through and apply subdivision
                        shapes = cmds.listRelatives(i,s=1,ni=1)
                        if shapes:
                            for s in shapes:
                                melCmd = "vray addAttributesFromGroup "+s+" vray_subdivision 1"
                                mel.eval(melCmd)
                                melCmd = "vray addAttributesFromGroup "+s+" vray_subquality 1"
                                mel.eval(melCmd)
                        # apply object ID to xform. i don't like giving individual shapes IDs.
                        melCmd = "vray addAttributesFromGroup "+i+" vray_objectID 1"
                        mel.eval(melCmd)
                        cmds.setAttr(i+'.vrayObjectID',currentID)
                        currentID += 1
                
                makeVrayAttributes()
                You can remove the code after "# apply object ID" to prevent the script from adding object id attributes to your nodes.
                Hello t.petrov !
                THNX A BUNCH!!!!!!
                Your script did the job I was looking for.

                I really appreciate your help!

                Cheers to all!
                DE: ERFINDER des Elektroautos „SION"
                EN: INVENTOR / FOUNDER of the electric vehicle "SION".


                Computer #1 (Main) : Windows 10 PRO │ 2xXEON │128 GB │Quadro M4000 │ Quadro K4000 │ MaYa │vRay 5 │Phoenix FD 4 │

                Even I have a powerful Computer ... I NEED CHAOS CLOUD !

                Comment

                Working...
                X