# Script to apply offset

**URL:** <https://forums.sketchup.com/t/script-to-apply-offset/316138>\
**Category:** Ruby API\
**Tags:** sketchup, scripts, ruby, plugin\
**Created:** [February 25, 2025, 12:34pm UTC](https://forums.sketchup.com/t/script-to-apply-offset/316138 "2025-02-25T12:34:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [February 25, 2025, 2:19pm UTC](https://forums.sketchup.com/t/script-to-apply-offset/316138/2 "2025-02-25T14:19:17Z")

</div>

Post **colorized** code **correctly** in the forum and please **edit** your previous post.

- [[How to] Post correctly formatted and colorized code on the forum?](https://forums.sketchup.com/t/how-to-post-correctly-formatted-and-colorized-code-on-the-forum/46189/)

* * *

I created a quick code (based on other one I also posted in a forum).  
You will get a context menu _“Face Around Hole”_, after copy paste it to the Ruby Console.  
**To be able to use it you must install [TIG Smart offset](https://forums.sketchup.com/t/spiral-sketchup-pls-help/125733) first!**  
 ![Dezmo_FAH](https://global.discourse-cdn.com/sketchup/original/3X/3/f/3ff44e2e0da77b96d64c0bd1a502ad9e8fd160e2.gif)

```ruby
module Dezmo
module FaceAroundHole

  @@loaded = false unless defined?(@@loaded)
  extend self
  
  def tig_smart_offset
    begin
      require 'TIG-Smart_offset.rb'
    rescue LoadError
      url = "https://sketchucation.com/pluginstore?pln=TIG_Smart_offset"
      UI.messagebox( "Please install TIG: Smart Offset v3.0\n\n" + url)
      return
    end
    true
  end

  def get_size
    return unless tig_smart_offset

    @offset = 50.mm unless @offset
    prompts = [
      "Offset"
    ]
    defaults = [
      @offset
    ]
    title = "Face Around Hole"
    inputbox(prompts, defaults, title)
  end
  
  def msg
    UI.messagebox("Face Around Hole :\n\nPlease Right click on a Group Contains one Face with one hole !")
    nil
  end
  
  def create_structure
    model = Sketchup.active_model
    ents = model.active_entities
    sel = model.selection
    return msg unless sel.single_object?
    return msg unless sel.first.is_a?(Sketchup::Group)
    group = sel.first
    group.make_unique
    entities = group.entities
    faces = entities.grep(Sketchup::Face)
    return msg unless faces.first
    return msg if faces.size > 1
    face = faces.first
    loops = face.loops
    return msg if loops.size != 2
    o_loop = face.outer_loop
    i_loop = face.loops.find { |loop| !loop.outer? }
    edges_to_erase = o_loop.edges
    vertices = i_loop.vertices
    input = get_size
    return unless input
    @offset = input.first
    norm = face.normal
    model.start_operation('Face Around Hole', true)
    entities.erase_entities(edges_to_erase)
    temp_face = entities.add_face(vertices)
    temp_face.reverse! unless temp_face.normal.samedirection?(norm)
    face_new = TIG::Smart_offset.new(temp_face, @offset)
    entities.erase_entities(temp_face)
    model.commit_operation
  end
  
  unless @@loaded
    cmd = UI::Command.new("Face Around Hole"){
      create_structure()
    }
    UI.add_context_menu_handler{|menu|
      menu.add_item(cmd) if Sketchup.active_model.selection.grep(Sketchup::Group).first
    }
    @@loaded = true
  end

end
end

```

---

_[View the full topic](https://forums.sketchup.com/t/script-to-apply-offset/316138)._
