Question on how to draw the connecting lines of points!

I want to make an external skeleton as a line by drawing the corners of each group model in the current sketchup. The code I made for him is as follows


model = Sketchup.active_model
entities = model.active_entities


material = model.materials.add("purple")
material.color = Sketchup::Color.new(255, 0, 255) 

groups = model.selection.grep(Sketchup::Group)

groups.each do |group|
  edges = group.entities.grep(Sketchup::Edge)
  edges.each do |edge|
    start_point = edge.start.position.transform(group.transformation)
    end_point = edge.end.position.transform(group.transformation)
    entities.add_line(start_point, end_point).layer = model.layers.add("tag8")
    entities.add_line(start_point, end_point).material = material
  end
end

(Tags and materials can be ignored because they are codes created for distinction)
The problem with this code is that it does not take into account the intersect point.
Please understand with the explanation shown in the picture below

What I want is a combination of edges that connect the point and the point considering the intersect point.

I ask for your help.

When you’ve added the edges into your group.entities try using this
https://ruby.sketchup.com/Sketchup/Entities.html#intersect_with-instance_method

entities1 = group.entities
entities2 = entities1.to_a
transformation1 = Geom::Transformation.new
entities1.intersect_with(true, transformation1, entities1, transformation1, true, entities2)

It should split any intersecting edges…
You might need to play around with the various arguments to get what you want - it is one of the most complex API methods…

2 Likes

Maybe exclude cofrontal lines first. These lines are often not part of determining the outline of the object.

thanks for help! :grinning:

thank you for your advice :grinning: