using System; using Hi.Milling.Apts; using Hi.Common.XmlUtils; using Hi.Geom; using Hi.Machining; using Hi.Mech.Topo; using Hi.Milling.Cutters; using Hi.Milling.FluteContours; using Hi.MillingForces.Fittings; using Hi.NcMech.Fixtures; using Hi.NcMech.Holders; using Hi.NcMech.Workpieces; using Hi.NcMech.Xyzabc; using Hi.NcOpt; using Hi.Physics; using Hi.MachiningProcs; using System.IO; using Hi.HiNcKits; using Hi.Milling.MillingTools; using Microsoft.Extensions.Logging; namespace Sample.Machining; /// /// Demonstrates how to create and configure a programmatically. /// This sample shows how to set up , , /// , , , /// and save the project configuration to a file. /// /// /// ### Source Code /// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildMachiningProject.cs)] /// public static class DemoBuildMachiningProject { internal static CylindroidHolder CreateCylindroidHolder() { #region ConfigureHolder CylindroidHolder cylindroidHolder = new CylindroidHolder() { Note = "BT40", Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12), new PairZr(20,16),new PairZr(30,16)]) }; #endregion return cylindroidHolder; } #region CreateMillingCutter1 internal static MillingCutter CreateMillingCutter1() { double diameter_mm = 12; double roundRadius_mm = 0.5; MillingCutter millingCutter = new MillingCutter() { ShaperProfile = new AptProfile( new ColumnApt() { Diameter_mm = diameter_mm, Rc_mm = roundRadius_mm, FluteHeight_mm = 40 }), UpperBeamGeom = new ExtendedCylinder(90), InnerBeamProfile = new FluteDependentRatioProfile(), MillingCutterOptLimit = new MillingCutterOptOption(), }; //build Fluting property double helixAngle_deg = 50; double radialRakeAngle_deg = 15; double bottomOuterRadius_mm = diameter_mm / 2 - roundRadius_mm; millingCutter.Fluting = new UniformFluting() { TrackNum = 3, BaselineOneContour = new FluteContour() { BaseSideContour = new ConstHelixSideContour(millingCutter) { Helix_deg = helixAngle_deg, RadialRakeAngle_deg = radialRakeAngle_deg }, BaseBottomContour = new SlideBottomContour() { //In most case, helix angle from side equal to rake angle from bottom. AxialRakeAngle_deg = MathUtil.ToDeg(helixAngle_deg), DiskAngle_deg = 1.5, //In most case, rake angle from side equal to eccentric angle from bottom. EccentricAngle_deg = radialRakeAngle_deg, CutterLengthOnBottomProjection_mm = bottomOuterRadius_mm * 0.9, OuterRadius_mm = bottomOuterRadius_mm } } }; return millingCutter; } #endregion #region CreateMillingCutter2 internal static MillingCutter CreateMillingCutter2() { MillingCutter millingCutter = new MillingCutter() { ShaperProfile = new AptProfile(new ColumnApt() { Diameter_mm = 12, FluteHeight_mm = 40 }), UpperBeamGeom = new Cylindroid( [new PairZr(40, 6), new PairZr(90, 6)]), InnerBeamProfile = new FluteDependentRatioProfile(), MillingCutterOptLimit = new MillingCutterOptOption() }; //build Fluting property double helixAngle_deg = 50; double radialRakeAngle_deg = 15; millingCutter.Fluting = new UniformFluting() { TrackNum = 3, BaselineOneContour = new FluteContour() { BaseSideContour = new ConstHelixSideContour(millingCutter) { Helix_deg = helixAngle_deg, RadialRakeAngle_deg = radialRakeAngle_deg }, //since no bottom cut, set bottom contour to null. BaseBottomContour = null } }; return millingCutter; } #endregion internal static CustomSpinningProfile CreateCustomSpinningProfile() { return new CustomSpinningProfile( new Cylindroid(new PairZr(0, 4), new PairZr(50, 4))); } #region TestMethod [STAThread] static void Main() { using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole()); LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample")); LocalProjectService localProjectService = new LocalProjectService(); var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj"; var projectDirectory = Path.GetDirectoryName(projectPath); Console.WriteLine($"Directory of the New Project: {projectDirectory}"); localProjectService.LoadProject(projectPath); MachiningProject machiningProject = localProjectService.MachiningProject; IProgress progress = null; #region ConfigureMachiningToolHouse localProjectService.MachiningToolHouse = new MachiningToolHouse() { [1] = new MillingTool() { Note = "T1", PreservedDistanceBetweenFluteAndSpindleNose_mm = 8, Holder = CreateCylindroidHolder(), Cutter = CreateMillingCutter1() }, [2] = new MillingTool() { Note = "T2", PreservedDistanceBetweenFluteAndSpindleNose_mm = 8, Holder = CreateCylindroidHolder(), Cutter = CreateMillingCutter2() }, [3] = new MillingTool() { Note = "T3", PreservedDistanceBetweenFluteAndSpindleNose_mm = 8, Holder = CreateCylindroidHolder(), Cutter = CreateMillingCutter1() }, }; #endregion #region ConfigureFixture //The fixture topology is free; the default shape has one branch from the //geometry anchor to each mount, so the workpiece mount is placed by the //transformer of the branch to it: on top of the 10 mm thick fixture geom. Fixture fixture = Fixture.CreateDefault(); fixture.Geom = new Box3d(new vec3d_t(-40, -40, 0), new vec3d_t(40, 40, 10)); Branch.Get(fixture.GeomAnchor, fixture.WorkpieceMount).Transformer = new StaticTranslation(new vec3d_t(0, 0, 10)); localProjectService.Fixture = fixture; #endregion #region ConfigureWorkpiece //The default shape already leads from the geometry anchor to the fixture //mount and to program zero by zero translations. Workpiece workpiece = Workpiece.CreateDefault(); workpiece.InitResolution = 0.25; workpiece.InitGeom = new Box3d(0, 0, -50, 70, 50, 0); workpiece.IdealGeom = null; workpiece.CuttingPara = XFactory.GenByFile( "Resource/CuttingParameter", "Al6061T6.default.mp", progress); workpiece.WorkpieceMaterial = XFactory.GenByFile( "Resource/WorkpieceMaterial", "Al6061T6.default.WorkpieceMaterial", progress); localProjectService.Workpiece = workpiece; #endregion #region ConfigureMachineChain localProjectService.MachiningChain = XFactory.GenByFile( "Resource", "MachineTool/Table-B1.default/Table-B1.mt", progress); #endregion machiningProject.MakeXmlSourceToFile(projectPath); machiningProject.Dispose(); LocalApp.AppEnd(); } #endregion }