Please reorganize your extension as a TRUE SketchUp extension.
See: https://ruby.sketchup.com/file.extension_requirements.html
Also, take note of the various numeric conversion methods that the SketchUp API has added to the Numeric class. (You do not need to write your own conversion formulae.) Here is an example that will default to model units, if the unit argument is blank:
def convert_to_inches(value, unit = nil)
units = Sketchup.active_model.options["UnitsOptions"]
if unit.nil? # use model units
case units["LengthFormat"]
when Length::Architectural, Length::Fractional
return value.inch
when Length::Engineering
return value.feet
else # Length::Decimal
unit = units["LengthUnit"]
end
end
case unit
when :in, Length::Inches then value.inch
when :m, Length::Meter then value.m
when :cm, Length::Centimeter then value.cm
when :mm, Length::Millimeter then value.mm
when :ft, Length::Feet then value.feet
when :yd, 5
# NOTE: constant Length::Yard (5) was added for SU2020,
# use 5 to avoid NameError exception in older versions.
value.yard # yards to inches
else
value.inch # if inches or unknown
end
end
Also, this is a good read for dealing with units in SketchUp:
https://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/