Announcement

Collapse
No announcement yet.

V-Ray Script Access - Can I even do this?

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

  • V-Ray Script Access - Can I even do this?

    Hello,

    I'm trying to write a python script to perform some repetitive actions, but I am struggling with the V-Ray Script Access Documentation (https://docs.chaos.com/display/VRHIN...+Script+Access).

    I'd like to perform the following actions for each item in a list of material names:
    1. Create a new material duplicated from a template material
    2. Rename the new material
    3. Swap it's diffuse bitmap for a new bitmap from a list
    Is this possible with the tools provided by Chaos?

  • #2
    Hi,

    In short:
    1) Yes
    2) Yes
    3) Yes

    Consider that you have a template V-Ray material already existing
    Click image for larger version  Name:	templateMtl.png Views:	0 Size:	36.7 KB ID:	1176497

    Since every V-Ray material has a Rhino material table entry, you all non V-Ray changes using a regular Rhino API calls.
    Afterwards you use V-Ray API calls to take care of the V-Ray specific materials

    Here is what you need to do.
    Code:
    import Rhino
    import rhVRay as vray
    
    mtlTable = Rhino.RhinoDoc.ActiveDoc.RenderMaterials
    templateMtl = mtlTable[0]
    
    # make copy of the template material, and change its name.
    newMat = templateMtl.MakeCopy()
    newMat.Name = "/MyNewMat"
    
    # Add the new material to the material table
    mtlTable.Add(newMat)
    
    # Modify V-Ray properties - e.g. change the diffuse texture bitmap
    with vray.Scene.Transaction() as f:
        vray.Scene.Plugin("/MyNewMat/VRay Mtl/Bitmap/Bitmap").file = r"D:\y5.png"​
    And here is the result if you run the script
    Click image for larger version  Name:	newMtl.png Views:	0 Size:	36.5 KB ID:	1176498
    Last edited by nikolay.bakalov; 24-03-2023, 10:12 AM.

    Comment


    • #3
      Thank you Nikolay! This is very helpful and I will go this route next time

      This time the solution I found (with my limited scripting knowledge) was to manipulate .vrmat files as they are saved in plain text format. Your solution makes much more sense!

      Comment


      • #4
        Manipulating .vrmats is also an option. There is an API for that as well, so you do mot need to parse XML files, or have certain knowledge about the format.

        Comment


        • #5
          Can you point me towards the documentation for that API please?

          Comment


          • #6
            You can check the VRay::Internal::StructuredVRMat class in the AppSDK.
            There is no official documentation, but the API is fairly simple to use

            Comment


            • #7
              Hey Nikolay, I'm trying to use the AppSDK in RhinoPython, but i seem to be getting this error message. Am I doing something wrong?

              RhinoPython runs ironpython 2.7.12. Is that a problem?

              imput:
              Code:
              import vray
              output:
              Code:
              Message: cannot import vray from python27
              
              Traceback:
                line 37, in import_module, "C:\Program Files\Rhino 7\Plug-ins\IronPython\Lib\importlib\__init__.py"
                line 17, in <module>, "C:\Program Files\Chaos Group\V-Ray\AppSDK\python\vray.py"
                line 1, in <module>, "C:\Users\charlie\AppData\Local\Temp\TempScript.py"​

              Comment


              • #8
                that won't work. RhinoPython is IronPython 2.7, and appsdk is implemented on CPuthon

                it should work with Rhino 8 though. They switched to CPython 3.9 there

                Comment

                Working...
                X