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!
โ ๏ธ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
Check for existing material
-
I want to check if a material (name) exists, and if not create one with that name.
However I can't get the syntax right.
Can't seem to find any reference to it anywhere either.
Here's my try:if(Sketchup.active_model.materials["MyMaterial"]) face.material = model.materials "MyMaterial" #If material exist use it else #Else create a new material with that name face.material = Sketchup;;Color.new(100,100,100) face.material.name = "MyMaterial" end -
` model=Sketchup.active_model
mats=model.materials
mname="SomeMaterialName"
unless mat=mats[mname] ### nil if no match
mat=mats.add(mname) ### reference to the new materialset up 'mat' properties - RGB, alpha etc...
end
The variable 'mat' points at the material named 'mname'. If it's 'new' then you can set its properties, otherwise it be opaque/black ! ... Finally useface.material=mat` ... -
Thanks. Its working now.

Advertisement