Well, think about it. You use a conditional statement to first test whether the material is already loaded.
if so, use it, if not load it first.
This is a perfect exercise to write up a little method to return a reference to a material object.
Answer (click to expand ...)
def get_material( mat_name, matl_folder )
model = Sketchup.active_model
materials = model.materials
matl = materials[mat_name] # nil if not found
return matl if matl
# otherwise load it:
matlpath = "Materials/#{matl_folder}/#{mat_name}.skm"
path = Sketchup.find_support_file(matlpath)
matl = materials.load(path)
matl ? matl : false
end
Check that return result is truthy before using the returned object reference.
Huh? Once again, SketchUp tags/layers are nothing more than a display property sheet that the display engine can use to know how to display multiple objects, regardless of their position in the model hierarchy.
They (layers/tags) are not Sketchup::Drawingelement
subclass objects, and are not geometric collections. So you cannot “paint” a layer. You can assign a layer’s property to use a Sketchup::Color
instance, but as I said before, you cannot (yet) assign a Sketchup::Material
instance to a layer/tag. (It has been requested to be able to assign materials to layers, but it has not yet been implemented.)
So just being a data construct holding properties, a layer/tag cannot “have” a side.
I’m not sure what you mean by “material tab” … do you mean the Materials inspector panel in a tray ?
It might help to post snips from the screen (use snipping tool.)
Be aware that if you click on any material in the Materials inspector panel (from any collection, ie, the “In Model” collection or one of the collections on disk,) no matter what you active tool is, SketchUp will automatically activate the Paint Bucket tool.
This tool is only useful if you have rendering set to either “Shaded” or “Shaded with Textures”.
It is not useful if you have any other rendering mode set, including “Color by Tag (Layer)”, since you cannot see that you’ve actually painted an object or a surface.
So, I think you need to learn more about SketchUp rendering, Styles, and setting up Scenes with their own style.
If you are going to be using “Color by Tag (Layer)”, then paint with materials is not needed and has no use.
If you do want to use materials, then you must not use “Color by Tag (Layer)” rendering, and must use either “Shaded” or “Shaded with Textures”.
See the User Guide on …