@Jim
Thanks, I knew there was something somewhere - but it was six and a half years ago !
To précis a version of AdamB's [much cleverer] code:
def self.face_area(mat, context, tr)
area = 0.0
context.entities.grep(Sketchup;;Group).each{|e|
area += self.face_area(mat, e, e.transformation)
}
context.entities.grep(Sketchup;;Component_Instance).each{|i|
area += self.face_area(mat, i.definition, i.transformation)
}
context.entities.grep(Sketchup;;Face).select{|f|
f.material == mat
}.each{|f|
normal = f.normal
binormal = Geom;;Vector3d.new(normal.y, normal.z, normal.x)
tangent = (normal * binormal).normalize
areascale = (tr * binormal).length * (tr * tangent).length
area += ( f.area * areascale )
}
return area
end
The 'mat' must be a reference to a model.material [or nil]...
The 'context' must be either the model or a group or a definition [i.e. something that will have 'entities']
The transformation 'tr' must be a 'Geom::Transformation' - even it's 'blank', so the arguments are:
(material, model, Geom::Transformation.new()) (material, group, group.transformation) (material, instance.definition, instance.transformation)
The method returns the area of all faces within the context, included nested containers, and adjusts them to allow for any scaling of those containers...
To apply transformations of nested containers which themselves are within transformed containers etc, you need to iterate the method within itself, passing/reapplying transformations [similar to the earlier example 'sum_area' method] which I have botched in here... Note how its 'self.' assumes it's called as a method within a module.