Skip to content

Instantly share code, notes, and snippets.

@jimfoltz
Last active October 30, 2015 17:42
Show Gist options
  • Save jimfoltz/071aa7b818cbbf5c2228 to your computer and use it in GitHub Desktop.
Save jimfoltz/071aa7b818cbbf5c2228 to your computer and use it in GitHub Desktop.

Revisions

  1. jimfoltz revised this gist Oct 30, 2015. No changes.
  2. jimfoltz revised this gist Oct 30, 2015. No changes.
  3. jimfoltz created this gist Oct 26, 2015.
    44 changes: 44 additions & 0 deletions limit-scale.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    # Limit the scale handles for Groups and Instances

    UI.add_context_menu_handler do |menu|
    model = Sketchup.active_model
    selection = model.selection
    if selection.nitems == 1 and selection[0].is_a? Sketchup::Group or selection[0].is_a?(Sketchup::ComponentInstance)
    menu.add_item("Limit Scale") do
    JF::LimitScale.do(selection[0])
    end
    end
    end

    module JF
    module LimitScale
    X = 1
    Y = 2
    Z = 4
    XZ = 8
    YZ = 16
    XY = 32
    XYZ = 64
    def self.do(e)
    if e.is_a?(Sketchup::Group)
    b = e.entities[0].parent.behavior
    end
    if e.is_a?(Sketchup::ComponentInstance)
    b = e.definition.behavior
    end
    m = b.no_scale_mask?
    m = m.to_s(2).split(//)
    while m.length < 7
    m.unshift(0)
    end
    m.reverse!
    prompts = %w( X Y Z XZ YZ XY XYZ )
    r = UI.inputbox(prompts, m, "Scale Mask 1=Disable")
    return if r == false
    s = r.join
    s = "0b" + s.reverse
    s = Integer(s)
    b.no_scale_mask = s
    end
    end
    end