GetPlugInObject not working for VBScript?

I want to be able to use the VRay for Rhino methods in a VBScript code, but when I try something on the lines of

Dim vRay: vRay = Rhino.GetPlugInObject("V-Ray for Matrix")
Dim name: name = vRay.GetMaterialNameFromVismat(vismat_file_path)

I get

Object does not support this property or method

Am I understanding something wrong?

Hi Bhupati,

In VBScript you cannot assign an Object to a variable of type Variant. You have to use Set like below:

Option Explicit 

Call Main()
Sub Main()

Dim VRay, name, f

    Set VRay = Rhino.GetPlugInObject("V-Ray For Rhino")
    f = "D:\Software\VRay\Materials\360Materials\aqua\aqua.vismat"
    name = VRay.GetMaterialNameFromVismat(f, 1)
    If len(name) = 0 Then 
        Rhino.Print "Error" 
        Rhino.Print "MaterialName: " & name
    End If
End Sub

Does that help ?


1 Like

@clement Nope! I’m still getting the Object required for Rhino.GetPlugInObject error. Did it work for you?

Here are a view tips to try

  1. Is V-Ray for Rhino/Matrix loaded and able to generate renders?

  2. If you have matrix installed, I always prefer to use the GUID vs Plugin name to find the plug in object.

  3. Is vismat_file_path a string?


I was able to get the below code to work:

Option Explicit

Call Main()
Sub Main()

	Dim VRay
	Set VRay = Rhino.GetPluginObject("{E8CFE179-B60C-411A-8416-62A893334519}")

	' The bool at the end is "show error"
	Dim name: name = vRay.GetMaterialNameFromVismat("c:\test.vrmat", False)

	Rhino.Print "Material Name" & name

End Sub

@krsnadas it`s always good to use the plugin ID as “V-Ray for Matrix” is not the same as “V-Ray For Rhino”, but both have the same plugin ID. You might also test using IsObject to prevent the error, when VRay is not loaded eg:

If Not IsObject(VRay) Then 
    Rhino.Print "Error"
    Exit Sub
End If

btw. as Matt has mentioned in his code, the bool value, i would always recommend to set it to True. If the Error is not shown and a material is not found (eg. when the material path is invalid), the VRay.GetMaterialNameFromVismat returns an empty string.


Thanks, @matt_newberg and @clement. I am able to call the vRay object now, but really intrigued why this happens:

GetMaterialNameFromVismat(...) returns this


BUT, Rhino.MaterialName(...) returns this

/WhiteReflective-7a1ea260-ded9-4cec-9216-f070a11d4740 (last two digits are different each time I call!)

which essentially means this is the name stored in the table and as a result returns null when I search for Rhino.MaterialIndex.

Note: I loaded the material using Rhino.Command("-visLoadVismat " + vismat_file_path)

Sorry, I reckon what’s going on. Material being loaded multiple times and I guess that changes the URL each time.

@matt_newberg Also, I tried calling ApplyVRayMaterialToObjects, but I get an error ‘Object does not support this method’. Any idea what’s going wrong?

f = "C:\WhiteReflective.vismat"
Call Rhino.Command("-visLoadVismat " + f)
Dim strObject: strObject = Rhino.GetObject("select")
Dim vRay, mat_name, i, name, mat_index, materials, str_name, thisStr, obj_index
Set vRay = Rhino.GetPluginObject("{E8CFE179-B60C-411A-8416-62A893334519}")
mat_name = vRay.GetMaterialNameFromVismat(f, False)
vRay.GetSceneMaterialNamesScript materials
str_name = "WhiteReflective"
For i = 0 to UBound(materials)
    thisStr = materials(i)
    If InStr(thisStr, str_name) <> 0 Then
        Exit For
    End If
vRay.ApplyVRayMaterialToObjects thisStr, 1, strObjects

There is a typo in your method name, it should be ApplyVRayMaterialToObjects


Haha, good catch @clement. I typed it in here instead of pasting. But I’m sure I have it typed right in my script, so the error still stands!

The error you get should also print out a line number where to look for the error. I do not think that above quoted method of your edited code snippet exists. It should be GetSceneMaterialNames


Actually, I’m not sure why two separate functions exist, but both GetSceneMaterialNames and GetSceneMaterialNamesScript work just fine with the same result!

And, @matt_newberg approves! A bit more about V-Ray scripting

Where did you find this method name ?


@matt_newberg mentioned this somewhere. There is a help file for VRay scripting called VRayForRhinoExports.h which, for me, is in C:\ProgramData\VRAYMATRIX2\VfMatrix64\

Yes, and in this reference i do not have GetSceneMaterialNamesScript, that is why i mentioned it.


Version differences maybe? I’m not sure. But I just checked again and it does have it in mine.

Ok. Back to your code snippet above, what is the variable f pointing to ? It seems incomplete to me.


Sorry, okay corrected it above, but again got it right in my script. f is pointing to the path of the material file.

it makes it very hard to answer your questions if you are constantly editing your posts.


GetSceneMaterialNamesScript stores the array of strings slightly differently. I believe I wrote it to get around an issue with PythonScript/Rhinoscript.