Table of Contents

Getting Started with HiAPI

What a first HiAPI application needs: where the packages come from, what the program has to initialise, and the shape every HiNC program follows once it runs.

Installation

  1. Create a dotnet project. A console or service project targets net10.0. A project that also takes one of the Windows UI packages targets net10.0-windows — that is what Hi.WinForm and Hi.WpfPlus are built for, and a plain net10.0 project cannot reference them. An earlier target framework cannot reference any of the packages.

  2. Register the HiAPI package source on the machine.

    The feed requires authentication, and the same account that gives you the sample repositories gives you the packages. One command registers the source and its credentials, which is the whole of what a restore needs:

    dotnet nuget add source https://superhightech-gitea.webredirect.org/api/packages/HiAPI/nuget/index.json --name HiAPI --username <your-account> --password <your-token> --store-password-in-clear-text
    

    Run it once per machine. Customers served by the mainland mirror register the feed address issued with their account in place of the URL above; nothing else changes.

    Prefer this to a project-local nuget.config, and never declare the feed in both places. NuGet resolves credentials by source name, and the match is case-sensitive, so a file that declares the same URL under a name the machine holds no credentials for adds a second, credential-less source. NuGet asks every source about every package, and one 401 fails the whole restore instead of falling through — so the packages it then reports as missing are the public nuget.org ones, and the cause is nowhere near the symptom. A credential-free file cannot stand in for the command either: the feed rejects anonymous requests, so it carries a fresh clone no further than having no source at all.

    Where a per-machine source is genuinely unavailable — an ephemeral build agent, say — a nuget.config beside the project file does the job, provided it is the only declaration of that URL and carries its own credentials under exactly the key it gave the source:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="HiAPI" value="https://superhightech-gitea.webredirect.org/api/packages/HiAPI/nuget/index.json" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
      </packageSources>
      <packageSourceCredentials>
        <HiAPI>
          <add key="Username" value="xxxxxx" />
          <add key="ClearTextPassword" value="xxxxxx" />
        </HiAPI>
      </packageSourceCredentials>
    </configuration>
    

    That file holds a password in clear text: keep it out of version control.

  3. In the dotnet project file, add the package reference.

    <ItemGroup>
      <PackageReference Include="HiNc" Version="3.2.*" />
      <!--optional; needs a net10.0-windows project-->
      <PackageReference Include="Hi.WpfPlus" Version="3.2.*" /> 
    </ItemGroup>
    
  4. In the program file, setting the HiNC application initialization and finalization.

    using Hi.HiNcKits;
    using Microsoft.Extensions.Logging;
    using System;
    
    namespace Sample
    {
        /// <summary>
        /// A sample class demonstrating initialization and usage of the HiAPI framework.
        /// Shows the basic setup of display engine, MongoDB server, licensing, and other core functionality.
        /// </summary>
        /// <remarks>
        /// This example serves as an entry point for those getting started with HiAPI.
        /// It demonstrates proper initialization and teardown of key components.
        /// ### Source Code
        /// [!code-csharp[SampleCode](~/../Hi.Sample/HelloHiAPI.cs)]
        /// </remarks>
        public static class HelloHiAPI
        {
            static int Main(string[] args)
            {
                Console.WriteLine("HiAPI starting.");
                using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
                LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
    
                Console.WriteLine("Hello World! HiAPI.");
    
                LocalApp.AppEnd();
                Console.WriteLine("HiAPI exited.");
    
                return 0;
            }
        }
    }
    

The Shape of a HiNC Program

Every HiNC program, whether it is the shipped application or twenty lines in a console project, runs the same five steps. DemoBuildMachiningProject in the Hi.Sample repository is the complete worked example.

graph TD
    A["Create MachiningProject"] --> B["Setting Environment"]
    B --> C["Setting Project Tasks"]
    C --> D["Run Tasks"]
    D --> E["View Analysis Results"]

1. Create MachiningProject

Creating a machining project is the first step in the HiNC workflow, accomplished by initializing a MachiningProject object.

2. Setting Environment In MachiningProject

The equipment has two faces. SetupEquipment is the authored one — the only face a project file persists, and the one every setting below is written to. MachiningEquipment is the runtime face the runner, physics, collision and execution display read; it is rebuilt from the authored face at project assignment and at session boundaries, so a value written onto it is discarded rather than saved.

3. Setting Project Tasks

Set sequential tasks using PlayerCommand:

  • Set NC Files - Set the file path and customize simulation and optimization settings for each NC file
  • Configure NC optimization - Configure NC code optimization parameters
  • Set GeomDiffCommand - Configure geometry comparison functionality to compare target workpiece shape with simulated shape
  • Set MillingTraining - Configure milling parameter training to calibrate simulation parameters based on actual machining data
  • Other task configurations…

The PlayerCommand is typically a ListCommand that contains a sequence of command entries to be executed during the simulation.

4. Run the Tasks (Simulation and Optimization)

Run PlayerCommand through PacePlayer.

At this stage, the simulation process is similar to video playback, which can be:

  • Started
  • Stopped
  • Paused
  • Run one line
  • Run one step
  • Reset

The PacePlayer controls the execution pace of the simulation, allowing you to observe the machining process in detail or run it at full speed.

View the Analysis During Process or Result

ShellProgress contains a sequence of simulation messages and step data, which can be used to monitor and analyze the simulation process and results.

Sample Code to Start a MachiningProject

See the following sample code to start a HiAPI application.

  • DemoBuildMachiningProject Build a MachiningProject.
  • DemoUseMachiningProject Load a MachiningProject and run NC simulation.
  • DemoRenderingMachiningProcessAndStripPosSelection Apply MachiningProject to 3D canvas with user-interaction in windows platform.

See Also