Saturday, May 17, 2014

Sketchup Plugin #1


Here's the ruby that I wrote for a plugin for Sketchup.


require 'sketchup' def do_curve(x) a1 = 0 a2 = 0 a3 = 4.7173806e-006 a4 = -1.13578e-007 a5 = 8.4145793e-010 r = -1.111234 c = 1.0/r k = -3.739907 return (c * x * x) / (1 + (1 - (1 + k) * c * c * x * x) ** 0.5) end def draw_curve model = Sketchup.active_model entities = model.entities model.start_operation "DrawCurve" last_num = 0 last_y = 0 for i in -1000 .. 1000 floati = i.to_f / 100 y = do_curve(floati) if i != -1000 Sketchup.active_model.entities.add_line [floati, y, 0], [last_num, last_y, 0] end last_num = floati last_y = y end model.commit_operation end UI.menu("PlugIns").add_item("Draw Curve") { draw_curve } #draw_curve
I used this to draw a curve in sketchup, which I turned into a 3d shape to print out on my 3d printer.

This represents some interesting skills that I've acquired.
1) The ability to program in Ruby, or rather the skill to write a short program in an unknown language in about an hour.
2) The ability to programmatically control a 3d modelling program, in this case sketchup.
3) The ability to turn that 3d model into a physical object, using a 3d printer.