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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement