Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
π£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download
Checking wether material exists before declaring it
-
Hallo!
I want to declare a material in a method, but before it's declared it should checked wether the material already exists to avoid overloading the memory with tons of the same material. Here is the code i used but it doesn't work so far...
def status_anzeigen mod = Sketchup.active_model ents = mod.entities sel = mod.selection mats = mod.materials unless mats.include?("im_bau") bau_mat = mats.add "im_bau" bau_mat.color = [255,127,38] fertig_mat = mats.add "fertig" fertig_mat.color = [211,211,211] inplanung = mats.add"noch_nicht_angefangen" inplanung.color = [176,196,222] inplanung.alpha = 0.3 end #and so on -
model=Sketchup.active_model materials=model.materials mat=materials.add("MyNewMaterial")if not mat=materials["MyNewMaterial"]
This test adds a new material named"MyNewMaterial"IF it doesn't already exist AND sets 'mat' to refer to it, whether it exists OR it has just had to be made...
-
Ok, great. thank you. I'll change it this weekend. Hope you have a nice one

Bye.
Tim
Advertisement