class SolidRuby::Assemblies::TSlot

Attributes

args[RW]

the code in this class is based on code by edef1c Ported to SolidRuby by Jennifer Glauche License: GPLv3

Public Class Methods

new(args = {}) click to toggle source
Calls superclass method SolidRuby::Assemblies::Assembly::new
# File lib/solidruby/assemblies/tslot.rb, line 22
def initialize(args = {})
  @args = args

  @args[:size] ||= 20
  @args[:length] ||= 100
  @args[:configuration] ||= 1
  @args[:gap] ||= 8.13
  @args[:thickness] ||= 2.55
  @args[:simple] ||= false
  @machining = SolidRubyObject.new
  @machining_string = ''

  super(args)
end

Public Instance Methods

description() click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 44
def description
  "T-Slot #{@args[:size]}x#{@args[:size] * @args[:configuration]}, length #{@args[:length]}mm #{@machining_string}"
end
hole(args = {}) click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 70
def hole(args = {})
  diameter = args[:diameter] || 8
  position = args[:position] || 'front'
  side = args[:side] || 'x'

  if position.is_a? String
    case position
    when 'front'
      z = @args[:size] / 2
      @machining_string += "with #{diameter}mm hole on front "
    when 'back'
      z = @args[:length] - @args[:size] / 2
      @machining_string += "with #{diameter}mm hole on back "
    end
  else
    z = position
    @machining_string += "with #{diameter}mm hole on #{z}mm "
  end

  @args[:configuration].times do |c|
    cyl = cylinder(d: diameter, h: @args[:size])
    if side == 'x'
      @machining += cyl.rotate(x: -90).translate(x: @args[:size] / 2 + c * @args[:size], z: z)
    else
      @machining += cyl.rotate(y: 90).translate(y: @args[:size] / 2 + c * @args[:size], z: z)
    end
  end

  self
end
holes(args = {}) click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 63
def holes(args = {})
  args[:position] = 'front'
  res = hole(args)
  args[:position] = 'back'
  res.hole(args)
end
length(length) click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 48
def length(length)
  @args[:length] = length
  self
end
multi_profile() click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 132
def multi_profile
  res = single_profile
  (@args[:configuration] - 1).times do |c|
    c += 1
    res += single_profile.translate(y: c * @args[:size])
  end
    res
end
output() click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 37
def output
  res = profile
  res - @machining
end
Also aliased as: show
profile() click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 101
def profile
  BillOfMaterial.bom.add(description) unless args[:no_bom] == true
  return single_profile.color('Silver') if @args[:configuration] == 1
  multi_profile.color('Silver')
end
show()
Alias for: output
single_profile() click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 107
def single_profile
  if @args[:simple] == true
    cube([@args[:size], @args[:size], @args[:length]])
  else
    start = @args[:thickness].to_f / Math.sqrt(2)

    gap = @args[:gap].to_f
    thickness = @args[:thickness].to_f
    size = @args[:size]
    square_size = gap + thickness
    if square_size > 0
      profile = square(size: square_size, center: true)
    else
     profile = nil
    end

    (0..3).each do |d|
      profile += polygon(points: [[0, 0], [0, start], [size / 2 - thickness - start, size / 2 - thickness], [gap / 2, size / 2 - thickness], [gap / 2, size / 2], [size / 2, size / 2], [size / 2, gap / 2], [size / 2 - thickness, gap / 2], [size / 2 - thickness, size / 2 - thickness - start], [start, 0]]).rotate(z: d * 90)
    end
    profile -= circle(r: gap / 2, center: true)
    profile = profile.translate(x: size / 2, y: size / 2)
    profile.linear_extrude(height: @args[:length], convexity: 2)
  end
end
thread(args = {}) click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 53
def thread(args = {})
  position = args[:position] || 'front'
  @machining_string += "with thread on #{position} "
  self
end
threads() click to toggle source
# File lib/solidruby/assemblies/tslot.rb, line 59
def threads
  thread.thread(position: 'back')
end