# Creating Track Type

Tracks types are loaded dynamically and custom ones can be created in the track directory. To open this directory run: EneRailroad::Template.open_dir(:track_type).

## Create Directory (And define ID)

Each track type template is saved in a sub directory named as its ID. This directory's name must start with your initial or some other rather unique character combination, followed by an underscore (_), to prevent name collisions.

IDs without leading initials (such as 'conctete_ties rather than 'ene_concrete_ties') are reserved for the tracks shipped with the extension (and 'ene_' prefix is already reserved by me, Eneroth3). Using such an ID for your own track may lead to it being overwritten when updating the extension.

Create a sub directory with the chosen ID as name to save the files in.

## Making the Model

Basically a track consists of extrusions (yellow), arrayed elements (red) and endings (green). The rails and track ballast are typically extrusions while ties/sleepers are arrayed and buffer stops are endings.

Create a model named 'model.skp' in the directory you just created. For backward compatibility save models as Sketchup version 8.

The extrusion profile, arrayed elements and endings are drawn as groups in this model. The groups are identified by attributes. Their position within the model doesn't matter for the plugin, however how the internal geometry is positioned in relation to the groups' local coordinate systems is vital.

### Extrusion Profiles

Each face in this group must be alone in its own group. By separating faces to individual groups unnecessary vertices from edges binding other faces can be avoided, reducing the number of faces created in the extrusion.

these one-face-groups can be painted with a material or left without so the user can paint the track as a whole themselves. The faces should be drawn in the profile group's x-z plane with the front of the face pointing towards negative y.

The most important extrusions may be the 2 rails. The standard gauge (distance between inner sides of rails) is 1,435 m. The top side of the rails must be along the x axis. The inner side should be half the gauge distance from the profile group origin.

To make the plugin recognize the extrusion profile group, add the attribute by selecting the group and run:

Sketchup.active_model.selection.first.set_attribute "ene_railroad_template_part", "type", "extrusion_profile"

### Arrayed Elements

Groups (or components) can be arrayed along the tracks, e.g. ties/sleepers. There can be multiple arrayed groups for the same track type.

Also in these groups x axis represents the top of rail plane. Ties/sleepers should normally be underneath it but centered at origin in horizontal(x-y) plane.

To make the plugin recognize the arrayed groups, add the attribute by selecting each one of them and run:

Sketchup.active_model.selection.first.set_attribute "ene_railroad_template_part", "type", "arrayed"

To set the target distance between each copy of the group, run:

Sketchup.active_model.selection.first.set_attribute "ene_railroad_template_part", "distance", 1.m

Replace '1' with the length in meters or replace '1.m' with the length in inches. Use point (.) as decimal separator.

### Endings

Groups (or components) can also be added at the end of either each piece of track, where the track type changes (e.g. start of inner rails for bridges or tunnels) or where the track comes to an halt (e.g. buffer stop).

Endings are typically based on the extrusion profile model with the faces push-pulled towards negative y. It's also possible to do it the other way around; starting with the ending and copy faces from its x-z plane to use for the extrusions. Positive y is where the rest of the track will be.

To make the plugin recognize the ending groups, add the attribute by selecting each one of them and run:

Sketchup.active_model.selection.first.set_attribute "ene_railroad_template_part", "type", "ending"

The default ending type is a complete end o the railroad line (e.g. buffer stop). To make an ending group apply to each track end or end of the track type, select it and run:

Sketchup.active_model.selection.first.set_attribute "ene_railroad_template_part", "ending_type", "<ending_type>"

Replace '<ending_type>' with either 'track' or 'type'.

## Create/Update Information

To create or edit track information run EneRailroad::Template.edit_properties in the Ruby console when inside track's model.

Name should start with gauge in millimeters unless it is default (1435 mm) or it's irrelevant, e.g. for monorail tracks. If the track type is specifically made to match a structure, use same name as for the structure.

There's a tiny space to show a track information, e.g. if its drawn to match a structure.

## Create Preview Image

To create the preview image of the track type, open preview.skp in the track directory. Change track type of the track in the model by right clicking it and open track properties.

The closer to 1362 * 610 the viewport size is, the better line thickness will match those of templates shipped with the plugin. My Viewport Resizer can be used to achieve this.

If you've drawn your track at another scale, e.g. for a toy train, you can zoom in to make it more visible, otherwise you can use the camera location of the scene to make it match other track previews.

Run this code in console to save preview image:

EneRailroad::Template.create_preview

## Distributing Track

The whole folder for the track type can easily be compressed, shared, and decompressed in someone else's track folder.

Copyright © Julia Christina Eneroth 2015.