# GetPlugInObject not working for VBScript?

**URL:** <https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136>\
**Category:** Scripting\
**Created:** [June 27, 2015, 1:42pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136 "2015-06-27T13:42:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 27, 2015, 1:42pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/1 "2015-06-27T13:42:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 27, 2015, 6:03pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/2 "2015-06-27T18:03:08Z")

</div>

Hi Bhupati,

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

```auto
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" 
    Else
        Rhino.Print "MaterialName: " & name
    End If
   
End Sub

```

## Does that help ?

c.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 28, 2015, 2:48pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/3 "2015-06-28T14:48:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matt\_newberg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/matt_newberg/32/13325_2.png) [@matt\_newberg](https://discourse.mcneel.com/u/matt_newberg)\
**Post date:** [June 28, 2015, 4:41pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/4 "2015-06-28T16:41:02Z")

</div>

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?

GetPlugInObject("{E8CFE179-B60C-411A-8416-62A893334519}")

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
```

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 28, 2015, 7:58pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/5 "2015-06-28T19:58:22Z")

</div>

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

```auto
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.

c.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 8:17am UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/6 "2015-06-29T08:17:15Z")

</div>

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

`GetMaterialNameFromVismat(...)` returns this

/WhiteReflective-7a1ea260-ded9-4cec-9216-f070a11d4720

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)`

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 10:48am UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/7 "2015-06-29T10:48:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 12:20pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/8 "2015-06-29T12:20:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 29, 2015, 12:30pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/9 "2015-06-29T12:30:15Z")

</div>

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

- 

c.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 12:32pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/10 "2015-06-29T12:32:48Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 29, 2015, 12:40pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/11 "2015-06-29T12:40:41Z")

</div>

> [@krsnadas](#):
>
> GetSceneMaterialNamesScript

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.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 12:53pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/12 "2015-06-29T12:53:35Z")

</div>

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](http://discourse.mcneel.com/t/a-bit-more-about-v-ray-scripting/20663)

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 29, 2015, 1:02pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/13 "2015-06-29T13:02:30Z")

</div>

> [@krsnadas](#):
>
> GetSceneMaterialNamesScript

Where did you find this method name ?

- 

c.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 1:06pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/14 "2015-06-29T13:06:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 29, 2015, 1:07pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/15 "2015-06-29T13:07:52Z")

</div>

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

- 

c.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 1:10pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/16 "2015-06-29T13:10:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 29, 2015, 1:13pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/17 "2015-06-29T13:13:06Z")

</div>

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

- 

c.

---

<div class="post-metadata">

**Author:** ![krsnadas](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/krsnadas/32/46010_2.png) [@krsnadas](https://discourse.mcneel.com/u/krsnadas)\
**Post date:** [June 29, 2015, 1:19pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/18 "2015-06-29T13:19:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 29, 2015, 1:26pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/19 "2015-06-29T13:26:52Z")

</div>

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

- 

c.

---

<div class="post-metadata">

**Author:** ![matt\_newberg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/matt_newberg/32/13325_2.png) [@matt\_newberg](https://discourse.mcneel.com/u/matt_newberg)\
**Post date:** [June 29, 2015, 1:29pm UTC](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136/20 "2015-06-29T13:29:31Z")

</div>

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

[Next page](https://discourse.mcneel.com/t/getpluginobject-not-working-for-vbscript/22136.md?page=2)
