class Length

 

Parent: Object

Class Index

Methods:<, <=, <=>, ==, >, >=, inspect, to_f, to_s

 

Sample Code:lengthtests.rb

 

Because length units are used so often in SketchUp, a special class has been added to make it easier to work with length values.

The Length class is derived from the Float class. 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

A number of methods have been added to the Ruby Numeric class to do units conversions.  

Instance Methods

 

<

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

Syntax:

status = length1 < length2

Arguments:

length1 - a length value

length2 - a length value

Return Value:

status - true if length1 is < length2; false if length1 is not < length2

Comments:

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

Example:

length1 = 11
length2 = 12
if length1 < length2
UI.messagebox "Less than"
else
UI.messagebox "Failure"
end


 

<=

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

Syntax:

status = length1 <= length2

Arguments:

length1 - a length value

length2 - a length value

Return Value:

status - true if length1 is <= length2; false if length1 is not <= length2

Comments:

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

Example:

length1 = 11
length2 = 12
if 11 <= 12
UI.messagebox "Less than or Equals"
else
UI.messagebox "Failure"
end


 

<=>

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

Syntax:

status = length1 <=> length2

Arguments:

length1 - a length value

length2 - a length value

Return Value:

status -

Comments:

 

Example:

length1 = 11
length2 = 12
if length1 <=> length2
UI.messagebox "Success"
else
UI.messagebox "Failure"
end


 

==

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

Syntax:

status = length1 == length2

Arguments:

length1 - a length value

length2 - a length value

Return Value:

status - true if length1 is == length2; false if length1 is not == length2

Comments:

 

Example:

 


 

>

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

Syntax:

status = length1 > length2

Arguments:

length1 - a length value

length2 - a length value

Return Value:

status - true if length1 is > length2; false if length1 is not > length2

Comments:

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

Example:

length1 = 11
length2 = 12
if length2 > length1
UI.messagebox "Greater Than"
else
UI.messagebox "Failure"
end


 

>=

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

Syntax:

status = length1 < length2

Arguments:

length1 - a length value

length2 - a length value

Return Value:

status - true if length1 is >= length2; false if length1 is not >= length2

Comments:

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
length2 = 12
if length2 >= length1
UI.messagebox "Greater Than or Equal"
else
UI.messagebox "Failure"
end


 

inspect

The inspect method is used to retrieve an unformatted string for the length.

Syntax:

length = length.inspect

Arguments:

 

Return Value:

length - an unformatted length string

Comments:

 

Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
length = entities.length
str = length.inspect


 

to_f

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

Syntax:

value = length.to_f

Arguments:

 

Return Value:

value - the float length value

Comments:

 

Example:

length = entities.length
f = length.to_f


 

to_s

The to_f method is used to convert a length to a string using current units.

Syntax:

length = length.to_s

Arguments:

 

Return Value:

length - a length string

Comments:

 

Example:

length = entities.length
s = length.to_s