class CrystalScad::Hardware::TSlot
Attributes
args[RW]
the code in this class is based on code by edef1c
Ported to CrystalScad
by Jennifer Glauche License: GPLv3
Public Class Methods
new(args={})
click to toggle source
# File lib/crystalscad/Hardware.rb, line 365 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 = CrystalScadObject.new @machining_string = "" end
Public Instance Methods
description()
click to toggle source
# File lib/crystalscad/Hardware.rb, line 386 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/crystalscad/Hardware.rb, line 412 def hole(args={}) diameter = args[:diameter] || 8 position = args[:position] || "front" side = args[:side] || "x" if position.kind_of? 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/crystalscad/Hardware.rb, line 405 def holes(args={}) args[:position] = "front" res = self.hole(args) args[:position] = "back" res.hole(args) end
length(length)
click to toggle source
# File lib/crystalscad/Hardware.rb, line 390 def length(length) @args[:length] = length self end
multi_profile()
click to toggle source
# File lib/crystalscad/Hardware.rb, line 473 def multi_profile res = single_profile (@args[:configuration]-1).times do |c| c=c+1 res+= single_profile.translate(y:c*@args[:size]) end return res end
output()
click to toggle source
# File lib/crystalscad/Hardware.rb, line 378 def output res = profile res - @machining end
Also aliased as: show
profile()
click to toggle source
# File lib/crystalscad/Hardware.rb, line 443 def profile @@bom.add(description) unless args[:no_bom] == true return single_profile.color("Silver") if @args[:configuration] == 1 return multi_profile.color("Silver") end
single_profile()
click to toggle source
# File lib/crystalscad/Hardware.rb, line 449 def single_profile if @args[:simple] == true return 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{|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) } profile-=circle(r:gap/2,center:true); profile=profile.translate(x:size/2,y:size/2); return profile.linear_extrude(height:@args[:length],convexity:2) end end
thread(args={})
click to toggle source
# File lib/crystalscad/Hardware.rb, line 395 def thread(args={}) position = args[:position] || "front" @machining_string += "with thread on #{position} " self end
threads()
click to toggle source
# File lib/crystalscad/Hardware.rb, line 401 def threads self.thread().thread(position:"back") end