8
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ What shape are the holes? It's easy for square shapes (as edge length = diameter). $\endgroup$
    – dr. Sybren
    Commented Nov 6, 2015 at 16:19
  • $\begingroup$ The hole is round. $\endgroup$ Commented Nov 7, 2015 at 2:14

3 Answers 3

5
$\begingroup$

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)
$\endgroup$
1
  • $\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$
    – Mutant Bob
    Commented Nov 10, 2015 at 21:17
5
$\begingroup$

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:

enter image description here

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':

enter image description here

Toggle the "Radius" option on, then type in the radius you want (diameter / 2) for the hole:

Example

$\endgroup$
1
  • $\begingroup$ That works but, Whats is the unit of radius? I want to set it in cm or what ever, not scale unit! $\endgroup$
    – Daniel
    Commented Apr 23, 2019 at 4:59
0
$\begingroup$
  1. Make a cylinder at the right place and size. Added cylinder

  2. Create a vertex group and add the vertices around the hole to it. Vertex group

  3. Add a shrinkwrap modifier (to the cube), select the cylinder as the object and limit it to the vertex group. Shrinkwrap

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. Move vertices

$\endgroup$
2
  • $\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
  • $\begingroup$ I'll add some screenshots. $\endgroup$
    – Gunslinger
    Commented Nov 7, 2015 at 8:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .