The objective of this tutorial is to present the process of machine code generation for the Shopbot router and to demonstrate how to visualize the path using basic animation techniques.
Code Generation Phase
The above pictured diagram shows the setup required for processing a list of polylines into machine code for the Shopbot. The code below initializes the machine, emits an entry/exit point per polyline setting the Z coordinate to the clearance plane to ensure clean transfers. Each point of each polyline is emitted as text and also collected in the geometry list.
private void RunScript( List<Polyline> Polylines, double JogSpeed, double CutSpeed, double Clearance, ref object Geometry ) { var geometry = new List<Point3d>( ); //-- Initialization //-- Print( "SA" ); Print( "MS,{0:0.0},{0:0.0}", JogSpeed ); Print( "M3,,,{0}", Clearance ); Print( "SO 1,1" ); //-- Paths to Code //-- foreach( var polyline in Polylines ) { //-- Write Path Entry Data //-- var start = polyline[0]; start.Z = Clearance; Print("MS,{0:0.0},{0:0.0}", JogSpeed); Print("M3,{0:0.000},{1:0.000},{2:0.000}", start.X, start.Y, start.Z); Print("MS,{0:0.0},{0:0.0}", CutSpeed); //-- Add Machine Path Entry //-- geometry.Add(start); //-- Write Path Position Data //-- foreach( var point in polyline ) { Print("M3,{0:0.000},{1:0.000},{2:0.000}", point.X, point.Y, point.Z); //-- Add Machine Path Step //-- geometry.Add(point); } //-- Write Path Exit Data //-- var end = polyline[polyline.Count - 1]; end.Z = Clearance; Print("MS,{0:0.0},{0:0.0}", JogSpeed); Print("M3,{0:0.000},{1:0.000},{2:0.000}", end.X, end.Y, end.Z); //-- Add Machine Path Exit //-- geometry.Add(end); } Print("M3,,,{0}", Clearance); Print("SO 1,0"); Print("END"); Geometry = geometry; }
Visualization Phase
The goal of this script is to create a persistent counter which can be used in conjuntion with the List Item component and Timer component to sequentially play back simple animations. This is a general purpose strategy and it can be adapted for many other types of simulations and visualizations.
The following program contains effectively two lines of code. A class scope declaration of a counter variable is used to retain the value before/after the script execution is complete. The script itself increments and resets the internal counter variable and exports the value through the index reference parameter.
public class Script_Instance : GH_ScriptInstance { private void RunScript(bool Reset, ref object Index) { Index = Reset ? Count = -1 : ++Count; } // <Custom additional code> int Count; // </Custom additional code> }