π« Lightbeans | 3D Texture Library For
Architectural Visualizations
Download
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 use
face.material=mat` ... -
Thanks. Its working now.
Advertisement