Skip to content

Instantly share code, notes, and snippets.

@watson
Created May 20, 2010 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watson/407487 to your computer and use it in GitHub Desktop.
Save watson/407487 to your computer and use it in GitHub Desktop.
require 'sketchup'
module MyPlugin
class Helper
class << self
LENGTH_TEXT_SYMBOL_DICT = {
:inches => '"',
:feet => "'",
:millimeters => "mm",
:centimeters => "cm",
:meters => "m"
}
LENGTH_NAME_DICT = {
:inches => "Inches",
:feet => "Feet",
:millimeters => "Millimeters",
:centimeters => "Centimeters",
:meters => "Meters"
}
def length_type(arg = 'nameString')
unitopts = Sketchup.active_model.options['UnitsOptions']
# allow the ordinal in the set to be returned if arg
# is any class other than String (or a String subclass.)
return unitopts['LengthUnit'] unless arg.kind_of?(String)
if unitopts['LengthFormat'] == 0 # decimal
unitSet = [:inches, :feet, :millimeters, :centimeters, :meters]
unitSet[unitopts['LengthUnit']]
elsif unitopts['LengthFormat'] == 2 # engineering
:feet
else # 1 == Architectural, 3 == Fractional
:inches
end
end
def length_text_symbol(arg = 'nameString')
LENGTH_TEXT_SYMBOL_DICT[length_type(arg)]
end
def length_name(arg = 'nameString')
LENGTH_NAME_DICT[length_type(arg)]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment