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; }
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; }
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; }
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; }