Module: AMS

Defined in:
../ams_Lib.rb,
main.rb

Defined Under Namespace

Modules: Cursor, Keyboard, Lib, MIDI, Menu, RayUtil, Registry, Screen, Sketchup, System, Timer, Window Classes: MultiLineText, SketchupObserver, Translate

Class Method Summary (collapse)

Class Method Details

+ (Numeric) clamp(value, min, max)

Clamp value between min and max.

Parameters:

  • value (Numeric)
  • min (Numeric, nil)

    Pass nil to have no min limit.

  • max (Numeric, nil)

    Pass nil to have no max limit.

Returns:

  • (Numeric)

Since:

  • 2.0.0



35
36
37
38
39
# File 'main.rb', line 35

def clamp(value, min, max)
  value = min if min and value < min
  value = max if max and value > max
  value
end

+ (Sketchup::Entity?) get_entity_by_id(id)

Get entity by entity ID.

Parameters:

  • id (Fixnum)

Returns:

  • (Sketchup::Entity, nil)

Since:

  • 2.0.0



80
81
82
83
84
85
86
87
88
89
90
# File 'main.rb', line 80

def get_entity_by_id(id)
  model = Sketchup.active_model
  model.entities.each { |e|
    return e if e.entityID == id
  }
  model.definitions.each { |d|
    d.instances.each { |e| return e if e.entityID == id }
    d.entities.each { |e| return e if e.entityID == id }
  }
  nil
end

+ (Boolean) is_boolean?(object) Also known as: is_bool?

Determine whether object is true or false.

Returns:

  • (Boolean)

Since:

  • 2.0.0



95
96
97
# File 'main.rb', line 95

def is_boolean?(object)
  object.is_a?(TrueClass) || object.is_a?(FalseClass)
end

+ (Numeric) max(a, b)

Get greatest value of the two values.

Parameters:

  • a (Numeric)
  • b (Numeric)

Returns:

  • (Numeric)

Since:

  • 2.0.0



63
64
65
# File 'main.rb', line 63

def max(a, b)
  a > b ? a : b
end

+ (Numeric) min(a, b)

Get least value of the two values.

Parameters:

  • a (Numeric)
  • b (Numeric)

Returns:

  • (Numeric)

Since:

  • 2.0.0



54
55
56
# File 'main.rb', line 54

def min(a, b)
  a < b ? a : b
end

+ (Geom::Vector3d) scale_vector(vector, scale)

Scale vector.

Parameters:

  • vector (Array<Numeric>, Geom::Vector3d)
  • scale (Numeric)

Returns:

  • (Geom::Vector3d)

Since:

  • 2.0.0



72
73
74
# File 'main.rb', line 72

def scale_vector(vector, scale)
  Geom::Vector3d.new(vector[0]*scale, vector[1]*scale, vector[2]*scale)
end

+ (Fixnum) sign(value)

Get numeric value sign.

Parameters:

  • value (Numeric)

Returns:

  • (Fixnum)

    -1, 0, or 1

Since:

  • 2.0.0



45
46
47
# File 'main.rb', line 45

def sign(value)
  value.zero? ? 0 : (value > 0 ? 1 : -1)
end

+ (void) validate_type(object, *types)

This method returns an undefined value.

Validate object type.

Parameters:

  • object (Object)
  • types (Object, Array<Object>)

    An object or an array of objects to check against.

Raises:

  • (TypeError)

    if object class doesn't match with any of the specified types.

Since:

  • 2.0.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'main.rb', line 14

def validate_type(object, *types)
  types.flatten!
  return if types.empty?
  types.each { |type| return if object.is_a?(type) }
  string = case types.size
  when 1
    types[0]
  when 2
    "#{types[0]} or #{types[1]}"
  else
    "#{types[0...-1].join(', ')}, or #{types[-1]}"
  end
  raise TypeError, "Expected #{string}, but got #{object.class}.", caller
end