Пример #1
0
        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 void WriteSTEPNC(List <Layer> layers, string outname)
        {
            STEPNCLib.AptStepMaker stnc = new STEPNCLib.AptStepMaker();

            stnc.NewProjectWithCCandWP("Additive Manufacturing STEP-NC", 1, "Main Additive Workplan");//make new project

            stnc.Millimeters();

            stnc.DefineTool(1.75, 1.75 / 2, 10.0, 10.0, 1.0, 0.0, 45.0);

            foreach (Layer layer in layers)
            {
                stnc.NestWorkplan("Additive Layer-" + layer.LayerNO.ToString());

                foreach (Polyline polyline in layer.Polylines)
                {
                    stnc.LoadTool(1);//load tool
                    stnc.Workingstep("Additive WS" + "(" + polyline.PolylineType + ")" + "-" + polyline.PolylineID.ToString());
                    //stnc.Rapid();
                    bool travel = true;
                    foreach (Point point in polyline.Points)
                    {
                        if (polyline.PolylineType == "contour-open")
                        {
                            if (travel)
                            {
                                stnc.Rapid();
                                stnc.GoToXYZ(polyline.PolylineType, point.X, point.Y, point.Z);
                                stnc.Feedrate(1600.0);
                                stnc.SpindleSpeed(220);
                                travel = false;
                            }
                            else
                            {
                                stnc.GoToXYZ(polyline.PolylineType, point.X, point.Y, point.Z);
                            }
                        }
                        else if (polyline.PolylineType == "hatch")
                        {
                            if (travel)
                            {
                                stnc.Rapid();
                                stnc.GoToXYZ(polyline.PolylineType, point.X, point.Y, point.Z);
                                stnc.Feedrate(1600.0);
                                stnc.SpindleSpeed(220);
                                travel = false;
                            }
                            else
                            {
                                stnc.GoToXYZ(polyline.PolylineType, point.X, point.Y, point.Z);
                                travel = true;
                            }
                        }
                    }
                }
                stnc.EndWorkplan();
            }
            stnc.SaveFastAsModules(outname);
            return;
        }
Пример #3
0
 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);
 }
Пример #4
0
        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();
        }
Пример #5
0
        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();
            }
        }
Пример #6
0
        public void WriteSTEPNC(MetaData metadata, string outname)
        {
            STEPNCLib.AptStepMaker stnc = new STEPNCLib.AptStepMaker();

            stnc.NewProjectWithCCandWP(metadata.PartNo, 1, "Main Workplan");//make new project

            if (metadata.Units == "IN" || metadata.Units == "Inches")
            {
                stnc.Inches();
            }
            else
            {
                stnc.Millimeters();
            }

            if (metadata.Multax == "ON")
            {
                stnc.MultaxOn();
            }

            Cutter[] tools = new Cutter[metadata.CutterTools.Keys.Count];
            metadata.CutterTools.Values.CopyTo(tools, 0);

            for (int i = 0; i < tools.Length; i++)//define all tools
            {
                stnc.DefineTool(tools[i].Diameter, tools[i].Diameter / 2, 10.0, 10.0, 1.0, 0.0, 45.0);
            }

            foreach (MachineGroup machineGroup in metadata.MachineGroups)
            {
                stnc.NestWorkplan("Machine Group-" + machineGroup.ID.ToString());

                foreach (ToolpathGroup toolpahtGroup in machineGroup.Operations)
                {
                    stnc.LoadTool(toolpahtGroup.Tool);//load tool associated with the current operation
                    stnc.Workingstep("WS-" + toolpahtGroup.ID.ToString());

                    foreach (MachiningData mchData in toolpahtGroup.MachiningData)
                    {
                        if (mchData is Rapid)
                        {
                            stnc.Rapid();
                        }
                        if (mchData is GoTo)
                        {
                            GoTo temp = mchData as GoTo;
                            stnc.GoToXYZ("point", temp.point.X, temp.point.Y, temp.point.Z);
                        }
                        if (mchData is Circle)
                        {
                            Circle temp = mchData as Circle;
                            stnc.ArcXYPlane("arc", temp.endpoint.X, temp.endpoint.Y, temp.endpoint.Z, temp.center.X, temp.center.Y, temp.center.Z, temp.radius, temp.direction);
                        }
                        if (mchData is Feedrate)
                        {
                            Feedrate temp = mchData as Feedrate;
                            stnc.Feedrate(temp.Fedrat);
                        }
                        if (mchData is SpindleSpeed)
                        {
                            SpindleSpeed temp = mchData as SpindleSpeed;
                            stnc.SpindleSpeed(temp.Spindlespeed);
                        }
                        if (mchData is Coolant)
                        {
                            Coolant temp = mchData as Coolant;
                            if (temp.activation)
                            {
                                stnc.CoolantOn();
                            }
                            else
                            {
                                stnc.CoolantOff();
                            }
                        }
                    }
                }
                stnc.EndWorkplan();
            }
            stnc.SaveAsP21(outname);
            return;
        }
Пример #7
0
        static void CreateNCFile(List <Layer> layers, string outname, double unitsmultiplier, double[] focii)
        {
            STEPNCLib.AptStepMaker asm = new STEPNCLib.AptStepMaker();
            asm.NewProjectWithCCandWP(outname, 4, "Main");
            asm.Millimeters();
            int toolcount = 1;
            Dictionary <double, int> focustoolmap = new Dictionary <double, int>(); //Map focus to tools.

            foreach (double focus in focii)                                         //Make tools.
            {
                asm.DefineTool(focus, 1, 1, 1, 1, 1, 1);
                asm.SELCTLTool(toolcount);
                asm.SetToolIdentifier(Convert.ToString(toolcount), Convert.ToString(toolcount));
                //asm.ToolGeometry("ROD.stp", Convert.ToString(toolcount));
                focustoolmap[focus] = toolcount;
                toolcount++;
            }
            int i = 0;

            foreach (Layer layer in layers)
            {
                asm.NestWorkplan(String.Format("Layer {0}", i));
                foreach (GeomData operation in layer.operations)
                {
                    asm.LoadTool(focustoolmap[operation.MetaData.focus]);
                    if (operation is CLIHatches)
                    {
                        asm.Workingstep(String.Format("Layer {0} Hatching", i));
                        asm.Rapid();
                        bool       firstop = true;
                        CLIHatches tmp     = operation as CLIHatches;
                        foreach (CLIHatch hatch in tmp.hatches)
                        {
                            if (firstop)
                            {
                                asm.GoToXYZ("HatchStart", hatch.startx * unitsmultiplier, hatch.starty * unitsmultiplier, layer.height * unitsmultiplier);
                                asm.Feedrate(operation.MetaData.speed);
                                asm.SpindleSpeed(operation.MetaData.power);
                                firstop = false;
                            }
                            else
                            {
                                asm.GoToXYZ("HatchStart", hatch.startx * unitsmultiplier, hatch.starty * unitsmultiplier, layer.height * unitsmultiplier);
                            }
                            asm.GoToXYZ("HatchEnd", hatch.endx * unitsmultiplier, hatch.endy * unitsmultiplier, layer.height * unitsmultiplier);
                        }
                    }
                    if (operation is Polyline)
                    {
                        asm.Workingstep(String.Format("Layer {0} Polyline", i));
                        bool firstop = true;
                        asm.Rapid();
                        Polyline tmp = operation as Polyline;
                        for (var j = 0; j < tmp.numberofpoints; j++)
                        {
                            if (firstop)
                            {
                                asm.GoToXYZ(String.Format("PolylinePt{0}", j), tmp.points[j].x * unitsmultiplier, tmp.points[j].y * unitsmultiplier, layer.height * unitsmultiplier);
                                asm.SpindleSpeed(operation.MetaData.power);
                                asm.Feedrate(operation.MetaData.speed);
                                firstop = false;
                            }
                            else
                            {
                                asm.GoToXYZ(String.Format("PolylinePt{0}", j), tmp.points[j].x * unitsmultiplier, tmp.points[j].y * unitsmultiplier, layer.height * unitsmultiplier);
                            }
                        }
                    }
                }
                i++;
                asm.EndWorkplan();
            }
            asm.SaveAsModules(outname);
            return;
        }
Пример #8
0
        private static void apt_to_stepnc(MetaData metadata, string outname)
        {
            double multiplier = 1;

            STEPNCLib.AptStepMaker stnc    = new STEPNCLib.AptStepMaker();
            STEPNCLib.Feature      feature = new STEPNCLib.Feature();
            STEPNCLib.Process      process = new STEPNCLib.Process();

            stnc.NewProjectWithCCandWP(metadata.PartNo.partno(), 1, "Main Workplan");//make new project
            //feature.OpenNewWorkpiece("mastercam");
            process.BlockRawpiece("mastercam block", 0, 0, 0, 70, 100, 50);

            //if (metadata.Units == "IN" || metadata.Units == "Inches")
            //    stnc.Inches();
            //else
            //    stnc.Millimeters();

            stnc.Millimeters();

            if (metadata.Multax.multax() == "ON")
            {
                stnc.MultaxOn();
            }

            stnc.CamModeOn();
            stnc.MultaxOn();

            stnc.SetModeMill();

            CutterTool[] tools = new CutterTool[metadata.CutterTools.Keys.Count];

            metadata.CutterTools.Values.CopyTo(tools, 0);

            for (int i = 0; i < tools.Length; i++)//define all tools
            {
                stnc.DefineTool(tools[i].Tparams.Diameter * multiplier, tools[i].Tparams.Diameter / 2 * multiplier, 10.0 * multiplier, 10.0 * multiplier, 1.0 * multiplier, 0.0, 45.0 * multiplier);
            }
            //stnc.Millimeters();
            foreach (MachineGroup machineGroup in metadata.MachineGroups)
            {
                stnc.NestWorkplan("Machine Group-" + machineGroup.ID.ToString());

                foreach (ToolpathGroup toolpahtGroup in machineGroup.Operations)
                {
                    stnc.LoadTool(toolpahtGroup.Tool);//load tool associated with the current operation
                    stnc.Workingstep("WS-" + toolpahtGroup.ID.ToString());

                    foreach (APT mchData in toolpahtGroup.MachiningData)
                    {
                        if (mchData is Rapid)
                        {
                            stnc.Rapid();
                        }
                        if (mchData is GoTo)
                        {
                            GoTo temp = mchData as GoTo;
                            stnc.GoToXYZ("point", temp.X * multiplier, temp.Y * multiplier, temp.Z * multiplier);
                            //Console.WriteLine("{0},{1},{2}",temp.X,temp.Y,temp.Z);
                        }
                        if (mchData is Circle)
                        {
                            Circle temp = mchData as Circle;
                            //Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}", temp.X, temp.Y, temp.Z, temp.Cx, temp.Cy, temp.Cz, temp.Radius, temp.Direction);
                            stnc.ArcXYPlane("arc", temp.X * multiplier, temp.Y * multiplier, temp.Z * multiplier, temp.Cx * multiplier, temp.Cy * multiplier, temp.Cz * multiplier, temp.Radius * multiplier, temp.Direction);
                        }
                        if (mchData is Feedrate)
                        {
                            Feedrate temp = mchData as Feedrate;
                            stnc.Feedrate(temp.Fedrat);
                        }
                        if (mchData is SpindleSpeed)
                        {
                            SpindleSpeed temp = mchData as SpindleSpeed;
                            stnc.SpindleSpeed(temp.Spindlespeed);
                        }
                        if (mchData is Coolant)
                        {
                            Coolant temp = mchData as Coolant;
                            if (temp.Activation)
                            {
                                stnc.CoolantOn();
                            }
                            else
                            {
                                stnc.CoolantOff();
                            }
                        }
                    }
                }
                stnc.EndWorkplan();
            }
            //stnc.SaveFastAsModules(outname);
            stnc.SaveAsP21(outname);
            //stnc.SaveAsModules(outname);
            return;
        }