Global position

I’m trying to add a hole using two components, hinge and door, however, I’m having problem with rotation orientation of one of the holes, in this code:

entities = model.entities

# Function to draw the circle inside the given entities (target component entities)
def desenhar_circulo(entities, center, normal, radius, segments = 24)
  circle = entities.add_circle(center, normal, raio.mm, segments) # Create circle in mm directly
  face = circle.first.find_faces

# Remove the face of the circle, leaving only the edges
  face.erase! if face & face.is_a? (Sketchup::Face)

puts "Circle created in the center: #{center} with radius: #{radius} mm inside the target component."
End

# Function to detect components with attribute "pcusinage" and value "transferhole"
def find_transfer_hole_components(entities)
  usinagem_components = []
  entities.each of the |entity|
    if entity.is_a? (Sketchup::ComponentInstance) || entity.is_a? (Sketchup::Group ```
![Door|472x500](upload://jN6lQWeHTzf5M1L0GLOHspnbPhi.png)

Please do not put spaces between the method name and its parameter list in Ruby code.
This can cause warnings noise to appear in the Console or in extreme situations, confuse the interpreter.


The Sketchup::Edge#find_faces method does not return a face object. This method is poorly named. It is not a search method, it is a creation method.

You might try something like:

face = circle[0].common_face(circle[1])

Or you can use the snapshot paradigm:

# Take a snapshot of the faces in the entities context:
before = entities.grep(Sketchup::Face)
circle = entities.add_circle(center, normal, raio.mm, segments)
after  = entities.grep(Sketchup::Face)
# Use array subtraction to get an array of any new faces:
new_faces = after - before
face = new_faces.find do |face|
  face.edges.all? { |edge| circle.include?(edge) }
end
# Test face because it will be nil if not found so:
face.erase! if face
3 Likes