Duplicate material by Ruby console

How to duplicate V-Ray material using ruby console in Sketchup?
I can’t find the method in VRay for Sketchup Ruby API document.
I’m not too proficient with Ruby so any guidance is much appreciated

You’re after the VRay::Scene::Plugin#duplicate method


So an example of that might be:


scene = VRay::Context.active.scene
material = scene["/Heather_Band"]
scene.change { material.duplicate(name: "/Foo", include_refs: true, family_only: true) }

Which makes me realize that the example in the documentation is incorrect, so thanks for helping us catch that :slight_smile:

Thanks a lot @noel.warren for your help!

I have some questions about material:
1/ Can the Attribute in VrayMtl like Contour, Translucency… be deleted using code? If so, an example is appreciated.

2/ I tried to set opacity of Contour to 0 but it doesn’t change. Any way to solve it?


context = VRay::Context.active
scene = context.scene
m = scene['/green fabric']
scene.change {
    m[:brdf][:opacity_tex_tex_on] = false
    m[:brdf][:opacity_tex] = 0
}​

Here is the video recording of this problem: https://www.youtube.com/watch?v=T-crl4wMj3M

1) Not sure I understand. You can delete plugins or you can modify their parameters
2) I’m guessing you were after modifying the opacity_tex_float userdata param. Use that instead of opacity_tex. You can tweak parameters in the UI and then use Plugin#dump to get a better understanding of what’s going on under the hood