I've been looking for a plugin to change the radius of multiple circles but I didn't find one, so I had the idea to write one myself. I want to replicate the functionality of editing the radius in the Entity Info box, as I have a lot of holes which are pushed into / through another object, so they form empty cylinders.
My basic idea was:
- select a circle
- get the center and normal
- make a new (bigger or smaller) circle and grab the points of the vertices
- delete the new circle
- move the vertices of the original circle to the new points
My problem is that when you create a circle and push it through another one, the two circles are not directly above each other - they are offset by 2 arcs. If you do the same through the API they don't twist, and so moving the vertices twists the face of the cylinder which breaks it. Here's the code and the model. Before.skp
` model = Sketchup.active_model
!!!manually select the top circle (sorry, has to be run in the console atm)
cur_c = model.selection[0].curve
cur_p = []
grab the positions of each vertex
cur_c.vertices.each { | v | cur_p << v.position }
!!!manually select the bottom circle
cur_c2 = model.selection[0].curve
cur_p2 = []
grab the position of the bottom circle's vertices
cur_c2.vertices.each { | v | cur_p2 << v.position }
show the points
cur_p
cur_p2`
The output was
> cur_p
[Point3d(2.55906, 1.9685, 0.590551), Point3d(2.53893, 1.81566, 0.590551), Point3d(2.47994, 1.67323,
0.590551), Point3d(2.38609, 1.55092, 0.590551), Point3d(2.26378, 1.45707, 0.590551), Point3d(2.12135, 1.39808, 0.590551), Point3d(1.9685, 1.37795, 0.590551), Point3d(1.81566, 1.39808, 0.590551), Point3d(1.67323, 1.45707, 0.590551), Point3d(1.55092, 1.55092, 0.590551), Point3d(1.45707, 1.67323, 0.590551), Point3d(1.39808, 1.81566, 0.590551), Point3d(1.37795, 1.9685, 0.590551), Point3d(1.39808, 2.12135, 0.590551), Point3d(1.45707, 2.26378, 0.590551), Point3d(1.55092, 2.38609, 0.590551), Point3d(1.67323, 2.47994, 0.590551), Point3d(1.81566, 2.53893, 0.590551), Point3d(1.9685, 2.55906, 0.590551), Point3d(2.12135, 2.53893, 0.590551), Point3d(2.26378, 2.47994, 0.590551), Point3d(2.38609, 2.38609, 0.590551), Point3d(2.47994, 2.26378, 0.590551), Point3d(2.53893, 2.12135, 0.590551), Point3d(2.55906, 1.9685, 0.590551)]
> cur_p2
[Point3d(2.47994, 2.26378, 0), Point3d(2.53893, 2.12135, 0), Point3d(2.55906, 1.9685, 0), Point3d(2.53893, 1.81566, 0), Point3d(2.47994, 1.67323, 0), Point3d(2.38609, 1.55092, 0), Point3d(2.26378, 1.45707, 0), Point3d(2.12135, 1.39808, 0), Point3d(1.9685, 1.37795, 0), Point3d(1.81566, 1.39808, 0), Point3d(1.67323, 1.45707, 0), Point3d(1.55092, 1.55092, 0), Point3d(1.45707, 1.67323, 0), Point3d(1.39808, 1.81566, 0), Point3d(1.37795, 1.9685, 0), Point3d(1.39808, 2.12135, 0), Point3d(1.45707, 2.26378, 0), Point3d(1.55092, 2.38609, 0), Point3d(1.67323, 2.47994, 0), Point3d(1.81566, 2.53893, 0), Point3d(1.9685, 2.55906, 0), Point3d(2.12135, 2.53893, 0), Point3d(2.26378, 2.47994, 0), Point3d(2.38609, 2.38609, 0), Point3d(2.47994, 2.26378, 0)]
The first point in the top circle is the third point in the bottom circle. Continuing anyway:
` entities = model.active_entities
new_p = []
create a bigger circle on the top face
new_e = entities.add_circle cur_c.center, cur_c.normal, 20.mm
new_c = new_e[0].curve
grab the new vertices
new_c.vertices.each { | v | new_p << v.position }
delete the circle
entities.erase_entities new_e
move the vertices to the new positions
cur_c.move_vertices new_p
new_p2 = []
create a bigger circle on the bottom face
new_e2 = entities.add_circle cur_c2.center, cur_c2.normal, 20.mm
new_c2 = new_e2[0].curve
grab the vertices
new_c2.vertices.each { | v | new_p2 << v.position }
delete the circle and move the vertices
entities.erase_entities new_e2
cur_c2.move_vertices new_p2
look at the points where the new vertices are
new_p
new_p2`
The output was:
> new_p
[Point3d(1.1811, 1.9685, 0.590551), Point3d(1.20793, 2.1723, 0.590551), Point3d(1.28659, 2.3622, 0.590551), Point3d(1.41173, 2.52528, 0.590551), Point3d(1.5748, 2.65041, 0.590551), Point3d(1.76471, 2.72908, 0.590551), Point3d(1.9685, 2.75591, 0.590551), Point3d(2.1723, 2.72908, 0.590551), Point3d(2.3622, 2.65041, 0.590551), Point3d(2.52528, 2.52528, 0.590551), Point3d(2.65041, 2.3622, 0.590551), Point3d(2.72908, 2.1723, 0.590551), Point3d(2.75591, 1.9685, 0.590551), Point3d(2.72908, 1.76471, 0.590551), Point3d(2.65041, 1.5748, 0.590551), Point3d(2.52528, 1.41173, 0.590551), Point3d(2.3622, 1.28659, 0.590551), Point3d(2.1723, 1.20793, 0.590551), Point3d(1.9685, 1.1811, 0.590551), Point3d(1.76471, 1.20793, 0.590551), Point3d(1.5748, 1.28659, 0.590551), Point3d(1.41173, 1.41173, 0.590551), Point3d(1.28659, 1.5748, 0.590551), Point3d(1.20793, 1.76471, 0.590551), Point3d(1.1811, 1.9685, 0.590551)]
> new_p2
[Point3d(1.1811, 1.9685, 0), Point3d(1.20793, 2.1723, 0), Point3d(1.28659, 2.3622, 0), Point3d(1.41173, 2.52528, 0), Point3d(1.5748, 2.65041, 0), Point3d(1.76471, 2.72908, 0), Point3d(1.9685, 2.75591, 0), Point3d(2.1723, 2.72908, 0), Point3d(2.3622, 2.65041, 0), Point3d(2.52528, 2.52528, 0), Point3d(2.65041, 2.3622, 0), Point3d(2.72908, 2.1723, 0), Point3d(2.75591, 1.9685, 0), Point3d(2.72908, 1.76471, 0), Point3d(2.65041, 1.5748, 0), Point3d(2.52528, 1.41173, 0), Point3d(2.3622, 1.28659, 0), Point3d(2.1723, 1.20793, 0), Point3d(1.9685, 1.1811, 0), Point3d(1.76471, 1.20793, 0), Point3d(1.5748, 1.28659, 0), Point3d(1.41173, 1.41173, 0), Point3d(1.28659, 1.5748, 0), Point3d(1.20793, 1.76471, 0), Point3d(1.1811, 1.9685, 0)]
The second set of points, created from circles added through the API are not twisted, i.e. the first point in new_c is directly above the first point in new_c2
The result of this is that after you have moved both sets of vertices, the surface of the cylinder is broken. You'll get a warning when you load it. After.skp