How to get all the edges that are visible from the top view?

Given a model such as a chair:

Its top view is:

When I export the view to .dxf format, I get a fine 2D picture that is good to be used in AutoCAD:

I need the result - the 2D model from the top view. I want to how to achieve it. Firstly, if the Ruby API supports to export as .dxf and to read the lines in the .dxf, it would be easy to get the 2D picture. But it seems no way. Then I want to retrieve the edges, if I can get all the edges that are visible from the top view. Appreciate any suggestion in advanced.

I suppose you need to use Layout to export 2d cad files.
Also you may change the line view in Style window. E.g. hidden geometry.

The result of SketchUp export to dxf is fine:

I tried to get the same result by Ruby api:

model = Sketchup.active_model
options_hash = { :edges => true, }
status = model.export('d:\my_export.dxf', options_hash)

But the result is different like this:

It is obviously just exporting all edges of the chair model, not removing the invisible edges from the top view. So they are different methods - export to dxf by menu and by Ruby api.

This might be a difficult endeavor.

SketchUp’s idea of “hidden” is whether the entity is shown or not.
I don’t think that the API has a way to determine what objects are occluded and those that are not.

You might first get the bounding box of the object the code is testing using #bounds.

Then pick points offset above the bounding box and repeatedly fire rays downward toward the object. Perhaps you can glean information you need from the results.

Something like the following … it’s up to you to process the hit arrays.

NOTE: Sketchup::Model#raytest is VERY slow !

module Henry12
  module PlanScan 

    extend self

    # Scan an instance by firing rays downward.
    # 
    # @param inst [Sketchup::ComponentInstance] The instance to scan.
    #
    # @return [Array(Geom::Point3d, Array<Sketchup::Drawingelement>)]
    #  The array of ray hits.
    def scan(
      inst = Sketchup.active_model.active_entities.grep(Sketchup::ComponentInstance).first
    )
      x_dim = inst.bounds.width
      y_dim = inst.bounds.height
      z = inst.bounds.depth + 1

      model = inst.model
      prev_path = model.active_path
      model.active_path = Sketchup::InstancePath.new([inst])

      hits = []
      resolution = 100
      downward = Z_AXIS.reverse
      ray = [ Geom::Point3d.new(0, 0, z), downward ]

      0.step(to: x_dim, by: x_dim/resolution) do |x|
        0.step(to: y_dim, by: y_dim/resolution) do |y|
          ray[0]= Geom::Point3d.new(x, y, z)
          result = model.raytest(ray)
          hits << result if result
        end
      end

      model.active_path= prev_path
      return hits
    end

  end
end