Delete all front face materials

Hi guys,

So I’m using the extension ‘TIG: Reverse Faces Tool’. It has a great option to ‘Delete back materials’.

I was wondering is there any other extension which allows you to delete the Front Materials.

To Note: the Fix Reverse Face Materials is not an option for what I plan to do.

Thanks to anyone who can help.

model=Sketchup.active_model
model.start_operation("NoFaceMats", true)
# In Model’s faces
model.entities.grep(Sketchup::Face).each{|f| f.material = nil }
# In compo/group’s faces
model.definitions.each{|d|
  next if d.image?
  d.entities.grep(Sketchup::Face).each{|f| f.material = nil }
}
model.commit_operation
puts "Done."
1 Like

@TIG
Thank s a million. That works great.

Maybe you can help me with this problem so, if you wouldn’t mind.

I have a model with a lot of flipped normals see here…

So that’s how the model should look. But obviously the materials are on the back face of the wrong normals (red).

My main goal:
To have two models. The first model with materials for the red faces and then the second model with materials for just the white faces.

Issues:

  • It’s not possible to flip all the normals without a lot of manual work. Not with orient faces, fredo tools, you name it. But at the moment that isn’t my first priority.
  • A lot of the flipped faces have two materials see image below. Which means selecting by material is impossible while some faces share materials they shouldn’t.

My Method
Here I have deleted the materials on the front face

However, we have materials still on the backface

So now the problem is all these materials are on the backface but I only want the materials on one side of the normals (White or Red).

I’ve tried multiple ways but I don’t know if it’s possible.

I hope what I’ve said makes sense.
Thanks.

If you are sure that the incorrectly orientated faces are only painted on their backs then try this…
If a face has materials on both sides it’s skipped !
There’s no UV mapping of a flipped texture…
Of course you could also flip the face AND delete all of its materials - using nil NOT back in the two blocks below…

f.material = nil
model=Sketchup.active_model
model.start_operation("ReOrientFacesWithMat", true)
# In Model’s faces
model.entities.grep(Sketchup::Face).each{|f|
  if back=f.back_material && ! f.material
    f.reverse!
    f.material = back
    f.back_material = nil
  end
}
# In compo/group’s faces
model.definitions.each{|d|
  next if d.image?
  d.entities.grep(Sketchup::Face).each{|f|
    if back=f.back_material && ! f.material
      f.reverse!
      f.material = back
      f.back_material = nil
    end
  }
}
model.commit_operation
puts "Done."

To see other options look at my oldies:

http://sketchucation.com/forums/viewtopic.php?p=264134#p264134

So if I’m correct I should run the code you gave earlier to delete all the front faces and then run the code you just gave.

Because at the moment the incorrectly orientated faces do have two materials.

No.
It only works if the faces only have a back material.

It’s difficult to know what face is wrongly oriented - as you’ve found.

So first you need to select only faces that appear reversed to the camera [i.e. you are looking at the back], and then delete their back [and front ?] material…
Of course if you look at a box with all of its faces correctly oriented, then the ones of its far side do have their backs looking towards the camera and you do NOT want to reverse them !

Try this to change the selection to include only those faces you can see the back of.
It doesn’t cope with faces inside ‘containers’ - it’s possible but much more complex !

model=Sketchup.active_model
model.start_operation("SelectBackFaces", true)
# In Model’s faces
direction = model.active_view.camera.direction
eye = model.active_view.camera.eye
faces = []
model.entities.grep(Sketchup::Face).each{|f|
  normal = f.normal
  # check if something is in the way !
  if direction.angle_between(normal) < 90.degrees
    center = f.bounds.center
    if model.raytest([center,eye], false)
      next
    else
      faces << f
    end
  end
}
ss = model.selection
ss.clear
ss.add(faces)
model.commit_operation
puts "Done."

You’ll probably need to locate the camera around the model 4 or more times to catch all faces.
If is badly modeled you might get some backs visible when you wouldn’t expect - e.g. one face walls !

You now have a selection of faces you can see the back of…

You can now use this to force a reversal and remove the material…

model = Sketchup.active_model
ss = model.selection
model.start_operation("Reverse+NoMats", true)
ss.grep(Sketchup::Face).each{|f|
  f.material = nil
  f.back_material = nil
  f.reverse!
}
model.commit_operation
puts "Done.."

If you want to remove ALL faces’ materials use the methods outlined earlier…

The double material could be that some components have had materials applied while closed and on their faces when open for editing. Using a plugin that removes C/G materials may help clear things up a bit.