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.

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