Unexpected behavior when adding a line that has an endpoint on another line with Ruby API

Hi folks,

I’ve encountered some unexpected (and undesired) behavior in the Ruby API, and I’m looking for some help understanding it, and circumventing it.

When I add an edge, then add another edge which has a vertex that lies on the first edge, the first edge gets split into two edges. I see why this would be useful in some circumstances, but it’s not what I want to happen in this case. I did some research, and found that setting “Sketchup.break_edges = false” should fix it. However, I was surprised to find that seems to have no effect!

Any idea why this is happening, and how I can get around it? I don’t want the first edge to get split!

I’ve included some code that you can copy/paste into your SketchUp Ruby console that demonstrates the problem:

# Start with empty model
model = Sketchup.active_model
entities = model.entities
puts('Start with an empty model.')
puts('No entities, see?')
puts('entities.to_a :')
puts(entities.to_a)

Sketchup.break_edges = true

puts('Creating two lines, with one with a vertex on the other:')
line0 = entities.add_line([0, 0], [100, 0])
line1 = entities.add_line([50, 0], [50, 50])

puts('There should now be three edges, since the second edge split the first into two edges')
puts(entities.to_a)

puts('Clearing model')
entities.erase_entities(entities.to_a)

puts('Now let us try this with Sketchup.break_edges=false :')
Sketchup.break_edges = false
puts('Creating two lines, with one with a vertex on the other:')
line0 = entities.add_line([0, 0], [100, 0])
line1 = entities.add_line([50, 0], [50, 50])

puts('Now I would expect there to be only two edges, since Sketchup.break_edges = false. However, there are three entities again! The second edge split the first, despite break_edges = false')
puts(entities.to_a)

System info:
OS: macOS Sierra 10.12.6
SketchUp version: SketchUp Pro 2018

It’s what you did not expect but it is exactly how edges and vertices used to work in SketchUp.
Disabling “break edges” will not break two crossing edges (no vertex at the intersection), however still no edge can coexist with a vertex somewhere on the edge.

  • Can you describe a usecase why you want a vertex on the edge without it dividing two edges?
  • You could still group entities that you don’t want to intersect or interact with each other.
1 Like

Thank you for your response!

It seems to me that it’s inaccurate to say that “no edge can coexist with a vertex somewhere on the edge”, because if you repeat the code I posted above, but switch the order of creation of the two lines, the line does not break on the vertex - the vertex sits there happily on the edge without splitting it.

# Start with empty model
model = Sketchup.active_model
entities = model.entities
puts('Start with an empty model.')
puts('No entities, see?')
puts('entities.to_a :')
puts(entities.to_a)

puts('Creating two lines, with one with a vertex on the other:')
line1 = entities.add_line([50, 0], [50, 50])
line0 = entities.add_line([0, 0], [100, 0])

puts('There should are only two edges when the lines are created in this order:')
puts(entities.to_a)

This seems inconsistent to me - auto-splitting the edge is a useful feature in some circumstances, but I don’t like that the order of adding geometrical entities affects the end result.

Since the behavior where vertices break edges isn’t some fundamental feature of the underlying Sketchup data structure (see the example above where it doesn’t always happen), it seems like it should be toggle-able, like Sketchup.break_edges.

To answer your questions:

  • Can you describe a usecase why you want a vertex on the edge without it dividing two edges?

I can describe my use case - I’m writing a genetic algorithm that evolves collections of lines based on fitness criteria, with intermittent human intervention. When Sketchup splits my lines, it’s altering the evolutionary designs that have been created, so they can’t be directly fed back into the algorithm. I think in general it’s not hard to imagine wanting an edge to

  • You could still group entities that you don’t want to intersect or interact with each other.

Thank you for that suggestion - that may be a useful workaround for me. It seems that if I put the first edge in a group by itself, then add the second edge, it is not split, as you suggested.