Projecting outer shape on surface

Hi all,

I’m new to Sketchup, new to ruby, new to this forum, but I like it all a lot!

I can’t figure this one out though: I am trying to figure out a way to project an odd-shaped object to a 2D surface and take the outer most edges only. Think of it as the shadow an object casts on the ground when the sun is exactly above it.
I can do this using Sandbox’s Drape tool and then erasing all the inner edges, but I feel like I’m missing an obvious method to code this. I have a messy work around to recreate some of the Drape tool when I’ve selected a group:

  model = Sketchup.active_model
  model.start_operation('Test', true)
  group = model.selection[0]
  group.entities.each{|e|
    if e.is_a? Sketchup::Edge
      p1 = e.start.position.clone
      p1.z = 0
      p2 = e.end.position.clone
      p2.z = 0
      model.entities.add_edges p1, p2
    end
  }
  model.commit_operation

Could anybody point me in the right direction and help me out?

Thanks!

Bob

Thanks!

Instead of using edges, you should use the face which allows you to specify just the outer loop of edges that define the face. Also, since you are using group entities, you need to transform them back to the model space. Something like this

model = Sketchup.active_model
model.start_operation('Test', true)
group = model.selection[0]
trans = group.transformation
group.entities.each{|e|
  if e.is_a?(Sketchup::Face)
    pts = e.outer_loop.vertices.map{|v|v.position}
    pts.each{|p|p.transform!(trans); p.z=0}
    model.entities.add_edges(pts<<pts[0])
  end
}
model.commit_operation
1 Like

Thanks sdmitch, using the face was the solution, that’s great!
It took me a while to understand the transformation trick and why you’d have to add pts[0] again, but it makes perfect sense to me now.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.