It takes time to be fluent on Ruby as it is a script language which has lots of unfamiliar concepts and syntactic sugar. But it is worth investment as I can make below animation
The outliner at the above video shows the hierarchy of the objects. For example, 'tractor_base' has 'tractor's and 'grip_base' which are moved along as the 'tractor_base' moves. Also note that 'glass' is rebased to 'tractor_base' when it is loaded on the stage and then rebased to 'bed' after it is released from the grip.
And the Ruby console shows internal debugging prints that must means nothing to outsider but invaluable information for the programmer.
I will describe what Ruby code is running behind from next blogs. But for those who can't wait, below shows what is driving in high level.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sketchup.rb" | |
load "e:/aux_depots/sketchups/sandbox/Motion.rb" | |
include Motion | |
hierarchy = Hierarchy.new( Sketchup.active_model ) | |
glass = hierarchy.walk_definition( "glass" ).first | |
tractor_base = hierarchy.walk_definition( "tractor_base" ).first | |
grip_base = hierarchy.walk_definition( "grip_base" ).first | |
camera_base = hierarchy.walk_definition( "camerabase" ).first | |
bed = hierarchy.walk_definition( "bed" ).first | |
program = Movement.new | |
program.return_home_when_finished( tractor_base, camera_base, grip_base ) | |
program.when_finished= lambda { |m| puts 'done!' } | |
program.chain( | |
Chain.MoveDir( glass, :AXIS_X, 1.0.m, 600.0.mm ), | |
step_glass_insert = Chain.MoveDir( glass, :AXIS_Z, -30.0.mm, 100.0.mm ), | |
Chain.MoveDir( grip_base, :AXIS_Z, -40.0.mm, 400.0.mm ), | |
Chain.MoveDir( tractor_base, :AXIS_X, 1.0.m, 400.0.mm ), | |
Chain.MoveDir( camera_base, :AXIS_Y, 25.0.mm, 50.0.mm ), | |
Chain.MoveDir( tractor_base, :AXIS_X, -1.0.m, 400.0.mm ), | |
Chain.MoveDir( camera_base, :AXIS_Y, 25.0.mm, 50.0.mm ), | |
Chain.MoveDir( tractor_base, :AXIS_X, 1.0.m, 400.0.mm ), | |
Chain.MoveDir( camera_base, :AXIS_Y, 25.0.mm, 50.0.mm ), | |
step_last_scan = Chain.MoveDir( tractor_base, :AXIS_X, -1.0.m, 400.0.mm ), | |
Chain.MoveDir( camera_base, :AXIS_Y, -75.0.mm, 50.0.mm ) ) | |
step_glass_insert.when_arrived = lambda { |e| | |
glass = Hierarchy.rebase( glass, tractor_base, Geom::Point3d.new(0,0,303.0.mm) ) | |
} | |
step_last_scan.when_arrived = lambda { |e| | |
glass = Hierarchy.rebase( glass, bed, Geom::Point3d.new(0,600.0.mm,603.0.mm) ) | |
program.chain( | |
Chain.MoveDir( grip_base, :AXIS_Z, 40.0.mm, 400.0.mm ), | |
Chain.MoveDir( glass, :AXIS_Z, 30.0.mm, 100.0.mm ), | |
Chain.MoveDir( glass, :AXIS_X, -1.0.m, 600.0.mm ) ) | |
} | |
program.run( Sketchup.active_model, 0.1 ) |