# Balise Tool

Custom ruby code can be executed when a train reaches a certain point along the track.

Click along the track to add balise. This opens up the code editor for it.

Click existing balise to move it. When it's selected you can also remove it by pressing delete.

Double click existing balise to edit its code.

The code can also be tested from Sketchup's own console. When testing EneRailroad.ss_train, EneRailroad.ss_rs and EneRailroad.ss_track can be used to get a reference to the train, rolling stock or track selected in the model.

## Short Reference

The train reaching the balise:
train
Previous train reaching the balise:
last_train
Time previous train reached the balise:
last_run
Time since last train reached balise (in s):
Time.now - last_run
Train speed (in m/s):
train.v
Train target speed (in m/s) being reached by defined acceleration:
train.v_target
Train acceleration (in m/s2) used to reach target speed:
train.a
Array of rolling stocks in train:
train.r_stocks
First Rolling stock i train:
train.r_stocks[0]
Group first rolling stock is drawn to:
train.r_stocks[0].group
Balise object
balise
Balise location
balise.point
Track event occurs on
balise.track

For a full list of everything that can be done with a train or rolling stock object, check their source files in the plugin's folder. For documentation regarding the Sketchup group object, check out the Sketchup API docs.

## Examples

Set speed to 4 m/s:
train.v = 4
Double speed:
train.v *= 2
Stop, wait 15 seconds and then set speed to 3 m/s (e.g. at station)
train.v = 0
UI.start_timer(15, false) { train.v = 3 }
Change direction of travel:
train.reverse
Change destination signs:
train.draw_text [{:label => "DestinAtion", :text => "Lund C"}]

Label is case insensitive, hence the capital A in the example.

Remove first rolling stock in train (e.g. at scrapyard)
train.r_stocks[0].group.erase!

The rolling stock object has a method to remove it but without removing the group resulting in a 'dead' rolling stock being left on the track. Erasing the group (same as manually delete it) triggers an observer to also remove the rolling stock object.

Paint first rolling stock with random material (from within model):
mats=Sketchup.active_model.materials
mat=mats[rand(mats.length-1)]
train.r_stocks[0].group.material = mat
Paint random rolling stock in train with random material (from within model):
mats=Sketchup.active_model.materials
mat=mats[rand(mats.length-1)]
rs_index=rand(train.r_stocks.length-1)
train.r_stocks[rs_index].group.material = mat
Paint whole train with random material (from within model):
mats=Sketchup.active_model.materials
mat=mats[rand(mats.length-1)]
train.r_stocks.each { |rs| rs.group.material = mat }

Please note that painting rolling stock has no effect if default material isn't used inside them.

Draw random line within the cube starting at origin and reaching 1000 inches along each axis:
Sketchup.active_model.entities.add_edges [rand(1000), rand(1000), rand(1000)], [rand(1000), rand(1000), rand(1000)]
Bounce back with speed reduced to 75% and slow down with 5 m/s^2 to a complete stop (e.g. at a buffer stop):
train.reverse
train.v *= 0.75
train.a = 5
train.v_target = 0

Copyright © Julia Christina Eneroth 2015.