I have a cube with several holes in it. Now I need to change the size of one hole to 6.34 mm diameter. What is the best way to do this?
3 Answers
The LoopTools add-on proposed by TLousky, is obviously massively convenient and exactly what you want.
Given the above statement, the rest of this answer might be slightly academic, but can still be useful if you are interested in how something like this is scripted. My solution works on the assumption that:
- the hole is a circle, and its vertices are the only things selected.
- the object has all transforms applied
- find the average coordinate (center of circle)
- let it find the diameter by checking the distance between the average coordinate and any of the vertices.
- use the average vector as a pivot point to scale away from.
code:
# This example assumes we have a mesh object in edit-mode
import bpy
import bmesh
from mathutils import Vector
def get_average_vector_of_selection(bm):
avg_vector = Vector()
num_vecs = 0
for v in bm.verts:
if v.select:
num_vecs += 1
avg_vector += v.co
return (avg_vector / num_vecs)
def get_radius(bm, average):
for v in bm.verts:
if v.select:
return (average-v.co).length
def scale_circle_verts(bm, new_radius):
average = get_average_vector_of_selection(bm)
# bpy.context.scene.cursor_location = average
current_radius = get_radius(bm, average)
print(current_radius)
if new_radius == current_radius:
return
amount_to_rescale = current_radius / new_radius
for v in bm.verts:
if v.select:
new_vec = (average).lerp(v.co, 1/amount_to_rescale)
v.co = new_vec
obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
scale_circle_verts(bm, new_radius=0.2)
bmesh.update_edit_mesh(me, True)
-
$\begingroup$ If the points are evenly distributed, then the coordinate average is the center of the circle. If the points are NOT evenly distributed, it is probably not the center of the circle. $\endgroup$ Commented Nov 10, 2015 at 21:17
Another way to achieve this is using the LoopTools addon's 'Circle tool'.
If the addon is not active on your system, go to the User Settings (CtrlAltU) > Addons > Mesh > LoopTools and activate it using the small checkbox on the right:
In Edit Mode select the loop or loops you want to resize, then either from the Tool Shelf > LoopTools or the Specials Menu (W > LoopTools) choose the 'Circle tool':
Toggle the "Radius" option on, then type in the radius you want (diameter / 2) for the hole:
-
$\begingroup$ That works but, Whats is the unit of radius? I want to set it in cm or what ever, not scale unit! $\endgroup$– DanielCommented Apr 23, 2019 at 4:59
Create a vertex group and add the vertices around the hole to it.
Add a shrinkwrap modifier (to the cube), select the cylinder as the object and limit it to the vertex group.
You may have to move the vertices from the cube into roughly the right position. As you see, they follow the cylinder but as they are not evenly spaced, the resulting hole is not very regular.
-
$\begingroup$ Step 2 - do you mean create a vertices group of original hole's outline. How do I add to the hole in it? Step 3 - who do I "limit it to the vertex group"? $\endgroup$ Commented Nov 7, 2015 at 2:19
-