I want to create a polygon mesh with points in an array. I want to go through the array adding the points to the mesh. What I do not know how to do is use “add_polygon” with my mesh. When I put it inside the loop (in the >>x<<) it does not work. But if I take it out of the loop it does not pick up the points. Any advice?

I’ve had good luck with something like the following. Note that I basically create a 2D array and then use that to populate the mesh with triangular polygons:

model = Sketchup.active_model
mesh = Geom::PolygonMesh.new()
node = []
for i in 0..10 do
pts = []
for j in 0..20 do
x = i
y = j
z = i * j / 20.0
pts.push(Geom::Point3d.new(x,y,z))
end
node.push(pts)
end
group = model.active_entities.add_group
for i in 0...10 do
for j in 0...20 do
mesh.add_polygon(node[i][j],node[i+1][j],node[i][j+1])
mesh.add_polygon(node[i][j+1],node[i+1][j],node[i+1][j+1])
end
end
group.entities.fill_from_mesh(mesh,1,0)