class Length

Because length units are used so often in SketchUp, a special class has been added to make it easier to work with length values. You can use a Length object any place that you would use a Float.

Internally, all lengths in SketchUp are stored in inches. The Length class stores values in inches as well. A number of methods have been added to the Ruby Numeric class to do units conversions.

The setting for the Length Format and Length Unit can be retrieved from the {Sketchup::Model#options} by querying the +“UnitsOptions”+ {Sketchup::OptionsProvider} for +“LengthFormat”+ and +“LengthUnit”+ respectively.

Constants:

Length Format
  • Length::Decimal

  • Length::Architectural

  • Length::Engineering

  • Length::Fractional

Length Unit
  • Length::Inches

  • Length::Feet

  • Length::Millimeter

  • Length::Centimeter

  • Length::Meter

(Added in SketchUp 2020.0)

  • Length::Yard

Area Unit

(Added in SketchUp 2019.2)

  • Length::SquareInches

  • Length::SquareFeet

  • Length::SquareMillimeter

  • Length::SquareCentimeter

  • Length::SquareMeter

(Added in SketchUp 2020.0)

  • Length::SquareYard

Volume Unit

(Added in SketchUp 2019.2)

  • Length::CubicInches

  • Length::CubicFeet

  • Length::CubicMillimeter

  • Length::CubicCentimeter

  • Length::CubicMeter

(Added in SketchUp 2020.0)

  • Length::CubicYard

  • Length::Liter

  • Length::USGallon

@note Prior to SketchUp 2015, Length used to be derived from Float. This

is no longer the case.

@version SketchUp 6.0

Constants

Architectural

Constants

Centimeter
CubicCentimeter
CubicFeet
CubicInches
CubicMeter
CubicMillimeter
CubicYard
Decimal
Engineering
Feet
Fractional
Inches
Liter
Meter
Millimeter
SquareCentimeter
SquareFeet
SquareInches
SquareMeter
SquareMillimeter
SquareYard
USGallon
Yard

Public Instance Methods

<(length2) click to toggle source

The < method is used to see if one length is less than another length.

For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 < l2 should return false.

@example

length1 = 12.to_l
length2 = 11.to_l
if length1 < length2
  puts "length1 is less than length2"
else
  puts "length1 is not less than length2"
end

@param [Length] length2

A length value.

@return [Boolean] true if length1 is < length2; false if

length1 is not < length2

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 125
def <(length2)
end
<=(length2) click to toggle source

The <= method is used to see if one length is less than or equal to another length.

@example

length1 = 11.to_l
length2 = 12.to_l
if length1 <= length2
  puts "length1 is less than or equal length2"
else
  puts "length1 is greater than length2"
end

@param [Length] length2

A length value.

@return [Boolean] true if length1 is <= length2; false if

length1 is not <= length2

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 147
def <=(length2)
end
<=>(length2) click to toggle source

The <=> method is used to see if one length is less than equal or greater than another length. Because we change == for Length to do a test based on a tolerance, we also need to change <=> to also take tolerance into account.

@example

length1 = 20.to_l
length2 = 30.to_l
result = length1 <=> length2

@param [Length] length2

A length value.

@return [Integer] the result of the comparison

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 165
def <=>(length2)
end
==(length2) click to toggle source

The == method is used to see if one length is equal to another length.

The equality comparison on Length values uses the default tolerance that SketchUp uses for comparing lengths.

@example

length1 = 20.to_l
length2 = 30.to_l
is_equal = length1 == length2

@param [Length] length2

A length value.

@return [Boolean] true if length1 is == length2; false if

length1 is not == length2

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 185
def ==(length2)
end
>(length2) click to toggle source

The > method is used to see if one length is greater than another length.

For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 > l2 should return false.

@example

length1 = 11.to_l
length2 = 12.to_l
if length1 > length2
  puts "length1 is greater than length2"
else
  puts "length1 is not greater than length2"
end

@param [Length] length2

A length value.

@return [Boolean] true if length1 is > length2; false if length1

is not > length2

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 209
def >(length2)
end
>=(length2) click to toggle source

The >= method is used to see if one length is greater than or equal to another length.

For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 >= l2 should return true. Also L1 <= l2 would return true.

@example

length1 = 11.to_l
length2 = 12.to_l
if length1 >= length2
  puts "length1 is greater than or equal length2"
else
  puts "length1 is less than length2"
end

@param [Length] length2

A length value.

@return [Boolean] true if length1 is >= length2; false if

length1 is not >= length2

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 234
def >=(length2)
end
inspect() click to toggle source

The inspect method is used to retrieve an unformatted string for the length, which is the length in inches, regardless of the user's model unit settings. See Length.to_s for a way automatically format your Length to the user's model units.

@example

length = 55.to_l
str = length.inspect

@return [String] an unformatted length string

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 249
def inspect
end
to_f() click to toggle source

The to_f method is used to convert a length to a normal float.

@example

length = 45.to_l
f = length.to_f

@return [Float] the float length value

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 261
def to_f
end
to_s() click to toggle source

Format a length as a String using the current units formatting settings for the model. (So if the user's model is set to feet, this method will return a nicely formatted length in feet.)

@example

length = 55.to_l
str = length.to_s

@return [String] the float length value

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/length.rb, line 275
def to_s
end