I want to duplicated a VRay material and assign to Face, but I can't find the duplicated mtl in Sketchup.active_model.materials (the newly duplicated mtl does shown in UI). The number of Sketchup.active_model.materials doesn’t change after duplicate.
One thing I noticed that when I run the following code the second times in Console, I can get duplicated material in Sketchup.active_model.materials, but I'm only able to do it in console, i can't replicate this "run twice" workaround in code.
Is this a bug because I assume the duplicated mtl should be available in Sketchup.active_model.materials
Or maybe I need some method to force update materials list after duplicated?
One thing I noticed that when I run the following code the second times in Console, I can get duplicated material in Sketchup.active_model.materials, but I'm only able to do it in console, i can't replicate this "run twice" workaround in code.
Is this a bug because I assume the duplicated mtl should be available in Sketchup.active_model.materials
Or maybe I need some method to force update materials list after duplicated?
Code:
all_entities = Sketchup.active_model.entities all_mtls = Sketchup.active_model.materials context = VRay::Context.active scene = context.scene number_mtl = all_mtls.count # It return 21 puts 'number: ' + number_mtl.to_s # Get mtl by name mtl_plugin = scene['/blue wood'] # Duplicate mtl mtl_plugin.duplicate(name:'/blue wood2' ,include_refs: true) VRay::refresh_ui number_mtl = all_mtls.count # After duplicated mtl, I expected that it return 22 but it still 21 puts 'number: ' + number_mtl.to_s face_array = all_entities.grep(Sketchup::Face) face_array.each do |face| # I can get the duplicated mtl by VRay method vray_duplicated_mtl = scene['/blue wood2'] # Here return VRay::Scene::Plugin but I don't know how to apply it to Face so I must use Sketchup method. # get the duplicated mtl by Sketchup method duplicated_mtl = all_mtls['blue wood2'] # Here return blank puts 'Duplicated_mtl : ' + duplicated_mtl.to_s face.material = duplicated_mtl end