Plugin for changing radius of multiple circles
-
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].curvegrab 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].curvegrab 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_p2look 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
-
why not just scale the circle using a scale_factor = new_radius/old_radius
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection crv = sel[0].curve rad = crv.radius ctr = crv.center var = UI.inputbox(["New Radius;"],[rad],"Resize Circle") if !var then return end tr = Geom;;Transformation.scaling(ctr,var[0]/rad) ent.transform_entities(tr,crv)
-
I don't know why, I just figured that was too easy
Anyway, I tested that method, and it does work and appears to be accurate, so thank you. Unfortunately it still breaks the model, not as badly as my previous method, but on saving you still get a bunch of warnings The plane equation for CFace (xxxxxx) is not valid.
Any ideas?
-
@crazystick said:
I don't know why, I just figured that was too easy
Anyway, I tested that method, and it does work and appears to be accurate, so thank you. Unfortunately it still breaks the model, not as badly as my previous method, but on saving you still get a bunch of warnings The plane equation for CFace (xxxxxx) is not valid.
Any ideas?
I have run several tests and I don't get any error messages in v8 or v2014. Could you post the model. Also info on initial and final radii.
-
@sdmitch said:
I have run several tests and I don't get any error messages in v8 or v2014. Could you post the model. Also info on initial and final radii.
The model is the one from this post, just a simple cube with a cylindrical hole. I ran the script on the top and bottom circle, then tried to save.
I just made one change, which was to convert to mm - I can't cope with 0.15346 etc.
rad = crv.radius.to_mm
The starting radius in the model is 15mm, I tried going down to 10mm and up to 20mm with the same result. I'm using Sketchup Pro 2014
-
@crazystick said:
@sdmitch said:
I have run several tests and I don't get any error messages in v8 or v2014. Could you post the model. Also info on initial and final radii.
The model is the one from this post, just a simple cube with a cylindrical hole. I ran the script on the top and bottom circle, then tried to save.
I just made one change, which was to convert to mm - I can't cope with 0.15346 etc.
rad = crv.radius.to_mm
The starting radius in the model is 15mm, I tried going down to 10mm and up to 20mm with the same result. I'm using Sketchup Pro 2014
Sorry I forgot about the models in first post. I downloaded both and using the scale method on both didn't cause any errors using 2014 free. I have found that you can never be totally sure about the order of things in sketchup.
Use .to_l to display values in model units.
-
To do this manually. You would select the inside surface of the hole, and then select the scale tool. You'd use two opposite corner handles, in the middle of the cylinder (not on the top or bottom circles. IE, you scale in the X and Y axis, but not in the Z axis.)
The scale tool may adjust the selection set for the user.
So try running it on the surface instead.
-
I didn't know you could scale a cylinder like that. It's handy to know. I don't know how to do that in ruby though - I tried scaling all 24 faces in the x,y axes using the centre of the cylinder, but unfortunately that didn't work.
I also don't know why the model gets corrupted when I run the script and not when others do, I get the same results in 2013 Pro too. Maybe its a Mac issue.
If you have any more ideas, let me know, otherwise I'll just have to live with it
Advertisement