# I can not remove bottom circular face of a nut model

I used below code for creating a nut. It’s almost a success. But I can not remove bottom circular face of the nut model. Thank you in advance.

``````ruby
# *************************************************
model = Sketchup.active_model
entities = model.active_entities

# Parameters
outer_radius = 45.mm  # Radius of the circumscribed circle around the hexagon
height = 30.mm  # Height of the nut

# Create a new group
group_entities = group.entities

# Center and vector for the base hexagon
center = [0, 0, 0]
vector = [0, 0, 1]

# Function to create hexagonal points
points = []
6.times do |i|
angle = i * Math::PI / 3
x = center[0] + radius * Math.cos(angle)
y = center[1] + radius * Math.sin(angle)
points << Geom::Point3d.new(x, y, center[2])
end
points
end

# Create the outer hexagon

# Create the inner circle for hollowing out

# Check if the inner face is created successfully and erase it
if inner_face
inner_face.erase!
end

# Reverse the face orientation to ensure correct extrusion direction
outer_hex_face.reverse!

# Extrude the outer hex face to the specified height
outer_hex_face.pushpull(height)

# *************************************************
'''

Please edit your post and put three backticks on an otherwise empty line before your code and another one after it. As is, it gets processed as markup and a mess results!

Ie …

Try reversing the order of the pushpulls. Do the outer hex pushpull first, then draw the inner circle and pushpull it.

1 Like

Try the following, tested in SketchUp 2023 & 2024

``````model = Sketchup.active_model
entities = model.active_entities

# Parameters
outer_radius = 45.mm # Radius of the circumscribed circle around the hexagon
height = 30.mm # Height of the nut

# Create a new group
group_entities = group.entities

# Center and vector for the base hexagon
center = [0, 0, 0]
vector = [0, 0, 1]

# Function to create hexagonal points
points = []
6.times do |i|
angle = i * Math::PI / 3
x = center[0] + radius * Math.cos(angle)
y = center[1] + radius * Math.sin(angle)
points << Geom::Point3d.new(x, y, center[2])
end
points
end

# Create the outer hexagon

# Create the inner circle for hollowing out

# Inner face has one loop, outer has two
inner_face = inner_circle.first.faces.find { |f| f.loops.length == 1 }
inner_face.erase! if inner_face

# Reverse the face orientation to ensure correct extrusion direction
outer_hex_face.reverse!

# Extrude the outer hex face to the specified height
outer_hex_face.pushpull(height)
``````
1 Like

It solved my problem, as you can see in the picture below. Thank you, MSP_Greg. I appreciate it.

1 Like

Adding entities using the standard way (`Sketchup::Entities#add_*`) uses the SU inference engine, so adding edge ‘loops’ that contain other existing loops can do unexpected things with faces. Hence, the code to determine which face is the inner one.
EDIT: I checked using Sketchup::EntitiesBuilder, and until its methods match `Sketchup::Entities#add_*`, it doesn’t really provide any benefit.