Merge vertices by distance in a complex mesh

Please post code correctly with proper indentation:


Sketchup.send_action("activateMainWindow:")

This is an unknown (undocumented) action string. It does not work on Windows platform.
It could be an AI “invented” solution that really does not exist.

Use the Sketchup.focus module method instead.


The code does not actually move the vertices. To do this, vertex objects must be moved with either the Entities#transform_by_vectors or Entities#transform_entities methods. The first method using vectors is likely your need.

There is no real point in drawing clines from the old point to the new centroid. Just collect the vectors into an array whose members match the position of each vertex in the vertices array. See Geom::Point3d#vector_to method.
Ie:
vectors = vertices.map { |vertex| vertex.position.vector_to(centroid) }

1 Like