How to set all vertexs Z_position to zero

hi
Some times we make a drawing 2D in top view to create a Face but after many times we figure out some vertex is not in same Z position, any way
How to set all vertexs Z_position to zero?

https://sketchucation.com/pluginstore?listtype=1&author=0&category=0&search=flatten&submit=%3F

https://sketchucation.com/pluginstore?pln=dropverts

1 Like

Basically, vertices are an Entity subclass, so they can be transformed using Entities#transform_by_vectors() where each vector for a given vertex is the vector from it’s current position to the new position whose Z == 0.

2 Likes

Beware that if the vertex is already close to zero, but not quite (within the equal tolerance of Point3d) - then it won’t be moved.

1 Like

Thomas, isn’t there a trick with transforming a vertex using a zero length vector ?
… what was that for ?

Yes! You jogged my memory - there is a way to move a vertex with absolute precision;

Scale to zero around the target position:

vertices = [...]
positions = [...] # maps 1:1 to `vertices`
vertices.each_with_index { |vertex, index|
  pt = positions[index]
  tr = Geom::Transformation.new(pt, 0.0)
  entities.transform_entities(tr, vertex)
}

This does mean you have to process each vertex individually, but that’s the only sure way to move vertices to 100% exact positions.

Ideally we’d have a entities.position_vertices(vertices, positions) method.

2 Likes