Retrieve position of face vertex in global frame of reference

Positions obtained from vertices are always locale to their parent - not global.

In order to work out the global position you need the combined transformation for all the parent instances. How you do that depend on context of how your extension work.

For instance, if your extension works on the active_entities at all time, then you can obtain the transformation via model.edit_transform.

But if you are traversing the whole model, say if you do a model export, then you need to keep track of the instance transformations as you dig down into the model hierarchy.

module Example

  def self.get_entities(instance)
    if entity.is_a?(Sketchup::Group)
      entity.entities
    else
      entity.definition.entities
    end
  end

  def self.walk(entities, transformation = IDENTITY)
    entities.each { |entity|
      case entity
      when Sketchup::Face
        global_points = face.outer_loop.vertices.map { |vertex|
          vertex.position.transform(transformation)
        }
        # Do stuff to global position of vertices here...
      when Sketchup::Group, Sketchup::ComponentInstance
        entities = get_entities(instance)
        walk(entities, entity.transformation * transformation)
      end
    }
  end

end