public static void generateFromAnalysis(Analysis.Analysis analysis, String basePath, String outputPath) { List <MTConnectEvent> timeline = analysis.timeline; Log.Write("Generating StepNC Data"); STEPNCLib.AptStepMaker apt = new STEPNCLib.AptStepMaker(); STEPNCLib.Finder find = new STEPNCLib.Finder(); Log.Write("Using template StepNC file " + basePath); apt.Open238(basePath); find.Open238(basePath); long wp_id = find.GetMainWorkplan(); apt.NestWorkplanAfter("Workplan for MTConnect results", find.GetWorkplanExecutableCount(wp_id) + 1, wp_id); apt.Workingstep("testing"); apt.LoadTool(101); apt.Rapid(); // Add all the path positions foreach (PathPosition pp in timeline) { apt.GoToXYZ("seq" + pp.sequence, pp.coords.x * mmtoinch, pp.coords.y * mmtoinch, pp.coords.z * mmtoinch); } apt.SaveAsModules(outputPath); Log.Write("StepNC Written to " + outputPath); }
public StepInterface(string path) { apt = new STEPNCLib.AptStepMaker(); apt.Open238(path); finder = new STEPNCLib.Finder(); finder.Open238(path); STEPNCLib.MachineState.Init(); machinestate = new STEPNCLib.MachineState(path); }
static void Main(string[] args) { STEPNCLib.Finder Find = new STEPNCLib.Finder(); STEPNCLib.AptStepMaker APT = new STEPNCLib.AptStepMaker(); StringBuilder builder = new StringBuilder(); String out_dirFile = args[0]; String input_file = args[1]; APT.Open238(input_file); Find.Open238(input_file); long wp_id = Find.GetMainWorkplan(); int depth = 0; bool last = false; long count = 0; String uu = APT.SetUUID_if_not_set(wp_id); //System.Console.WriteLine("Main Workplan name " + Find.GetExecutableName(wp_id) + " has UUID: " + uu); Mark_plan(wp_id, Find, APT, builder, depth, last, ref count); Mark_pieces(Find, APT, builder); Mark_tools(Find, APT, builder); Mark_technologies(Find, APT, builder); APT.SaveAsModules("hardmoldy_IMTS_signed_uuid.stpnc"); string output = builder.ToString(); if (!Directory.Exists(out_dirFile)) //See if the path exists Directory.CreateDirectory(Path.GetDirectoryName(out_dirFile)); //Create if not using (StreamWriter out_file = //StreamWrite output to file new StreamWriter(File.Open(out_dirFile, FileMode.Create))) { out_file.WriteLine(output); } //Console.ReadLine(); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage: StepNCtoJSON <input-file> optional: <output_file>"); Environment.Exit(1); } //STEPNCLib.Finder find = new STEPNCLib.Finder(); STEPNCLib.AptStepMaker apt = new STEPNCLib.AptStepMaker(); STEPNCLib.Tolerance tol = new STEPNCLib.Tolerance(); string curr_path = Directory.GetCurrentDirectory(); bool test; string file = args[0]; string out_dirFile = ""; if (args.Length == 2) { out_dirFile = curr_path + args[1]; test = true; } else { test = false; } StringBuilder builder = new StringBuilder(); apt.Open238(file); //Open 238 file long count = tol.GetToleranceAllCount(); //Gets the total tolerance count double value, upper, lower; builder.Append("{ \"tolerances\": ["); //Starts the tolerances JSON string for (int i = 0; i < count; i++) //Loops through all tolerances one by one { bool last = false; //Valid Json error checking if (i == (count - 1)) { last = true; } //Get the next tolerance id and get its type/value long tol_id = tol.GetToleranceAllNext(i); /*string uu = apt.SetUUID_if_not_set(tol_id);*/ //UUID code that doesn't work til DLL is updated string type = tol.GetToleranceType(tol_id); value = tol.GetToleranceValue(tol_id); //Makes the list of faces that are associated to this tolerance if they exist long facc = tol.GetToleranceFaceCount(tol_id); long geom = 0; string faces = ""; if (facc != 0) { faces = "["; for (int j = 0; j < facc; j++) { long face = tol.GetToleranceFaceNext(tol_id, j); geom = tol.GetFaceMeasureGeometry(face); if ((j + 1) == facc) { faces = faces + face; } else { faces = faces + face + ", "; } //Console.WriteLine(face + " "); } faces = faces + "]"; } //Makes the list of datums that are associated to this tolerance if they exist long datc = tol.GetToleranceDatumCount(tol_id); string data = ""; if (datc != 0) { data = "["; for (int j = 0; j < datc; j++) { long datum = tol.GetToleranceDatumNext(tol_id, j); if ((j + 1) == datc) { data = data + datum; } else { data = data + datum + ", "; } //Console.WriteLine(datum + " "); } data = data + "]"; } //Does something different depending on Tolerance Class if (tol.IsSizeDimension(tol_id)) //Size Dimension : and all subclasses { tol.GetTolerancePlusMinus(tol_id, out lower, out upper); string temp = convertBounded(type, value, upper, lower, faces, data, geom, last); builder.Append(temp); } else if (tol.IsLocationDimension(tol_id)) //Location Dimension : and all subclasses { tol.GetTolerancePlusMinus(tol_id, out lower, out upper); string temp = convertBounded(type, value, upper, lower, faces, data, geom, last); builder.Append(temp); } else if (tol.IsGeometricTolerance(tol_id)) //Geometric Tolerance : and all subclasses { string temp = convertUnbounded(type, value, faces, data, geom, last); builder.Append(temp); } else if (tol.IsSurfaceTextureParameter(tol_id)) //Surface Texture Parameter : and all subclasses { string temp = convertUnbounded(type, value, faces, data, geom, last); builder.Append(temp); } else //Invalid Tolerance { Console.WriteLine("Invalid Tolerance"); } } //Console.ReadLine(); builder.Append(" ]}"); //Ends the JSON string if (test) //If user wants output file { string output = builder.ToString(); string res = httpPost(output); if (!Directory.Exists(out_dirFile)) //See if the path exists { Directory.CreateDirectory(Path.GetDirectoryName(out_dirFile)); //Create if not } using (StreamWriter out_file = //StreamWrite output to file new StreamWriter(File.Open(out_dirFile, FileMode.Create))) { //out_file.WriteLine(output); out_file.WriteLine(res); } ProcessStartInfo pf = new ProcessStartInfo("chrome.exe", "file:///C:/Users/Nick/Documents/Visual%20Studio%202015/Projects/ToleranceViewer/stepnc_hello_cs/test.html"); Process.Start(pf); } else //Otherwise Write to command line { string output = builder.ToString(); string res = httpPost(output); Console.WriteLine(output); Console.ReadLine(); } }