GetPlugInObject not working for VBScript?

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
Next
vRay.ApplyVRayMaterialToObjects thisStr, 1, strObjects

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

c.

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

c.

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 ?

c.

@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.

c.

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.

c.

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.

c.

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

Sorry @clement, I didn’t realize. I just tried GetSceneMaterialNames (in VB); I am getting a type mismatch error, whoa

Hi Matt, i do not get both to work, GetSceneMaterialsScript gives me “unsupported property or method” and using GetSceneMaterials i get a VarType of 8200:

    materials = Null
    Call vRay.GetSceneMaterialNames(materials)
    MsgBox VarType(materials)

If i try to access materials(0) i get a “type conflict”. What VarType is 8200 ?

c.

8200 would be VarType ( VT_ARRAY | VT_BSTR ). While GetSceneMaterialNamesScript outputs VarType (VT_ARRAY | VT_VARIANT). This was the reason I wrote up this different function to get around that error.

Which version of V-Ray For Rhino / V-Ray For Matrix are you running and getting the said error with GetSceneMaterialNamesScript?

Hi Matt, V-Ray For Rhino 1.5 Edu. I remeber to have searched how to access ByteString in rvb in the past without success.

c.

@clement

GetSceneMaterialNamesScript was added in the builds from Mid July 2014.You will have to get a newer build to use that function.

Possible typo, strObjects should be strObject. If i understand it correctly, it should be an array of objects but i cannot test it as i do not get past the GetSceneMaterialNamesScript method at this point.

Btw. you might use Option Explicit to avoid writing variable names which have not been declared before.

c.