Rail3D*


 


A simple script by Mark Hodson that creates the specified number of straight track sections of the same length. The starting node must be selected before the script is called, and the script then works out which end of the node is free and creates the sections from there. If both or neither ends of the selected node are free, the direction the track is laid in is random (unless you actually know the node's orientation angle already).


Init()
{
// Get selected node
node mNode=Document.GetCurrentNode();

// Get the connected nodes in either direction
// if they exist
node Node1=mNode.GetConnectedNode(0,0);
node Node2=mNode.GetConnectedNode(1,0);

// Get start position
float x=mNode.GetX();
float y=mNode.GetY();
float z=mNode.GetZ();
float alpha=mNode.GetAlpha();

// Returns 0 if Node2 does not exist
float xb=Node2.GetX()

// User input
float length=InputFloat("Length in m");
int numbersections=InputInt("Number of Sections");

if(xb==0) // Which way to go?
{
alpha=3.1416+alpha;
}

float x1=x;
float y1=y;

int count=0;

// Keep creating sections until done
while(count<numbersections)
{
float x2=x1+(length*sin(alpha));
float y2=y1+(length*cos(alpha));

Document.BuildLink(x1,y1,z,x2,y2,z);

x1=x2;
y1=y2;

count++;
}
}

DanielEvans 30/09/2015 18:01:19