Preparing the environment
The following is an example of how to prepare environment to work with SprutCAM X machining tools import API, using the example of creating a console application in Visual Studio in C#.
- Download and install .NET SDK x64 from the official site. The latest version of .NET 6.0 is recommended for SprutCAM X 17.
- To work with the source files, download and install the latest available version of Visual Studio Code.
- Run the installed Visual Studio Code and install "C# Dev Kit for Visual Studio Code" extension.
If you have not yet, download and install the latest SprutCAM X (version 17 or higher required) from the official resource.
In Visual Studio Code, open an existing or create a new directory for your new project. When prompted to "Do you trust the authors of the files in this folder?", click on "Yes, I trust the authors".
Open the VS Code terminal view.
In the terminal view insert the "dotnet new console --framework net6.0" command and press enter (change the net6.0 version if you have a different SDK version).
After executing this command, the following source files should appear in your working directory:
The .csproj file will have the same name as the working folder.
- Open the .csproj source file and change its contents as shown below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="SprutCAMTech.MachinigToolsImportTypes">
<HintPath>C:\Program Files\SprutCAM Tech\SprutCAM X 17\Bin64\SprutCAMTech.MachinigToolsImportTypes.dll</HintPath>
</Reference>
<Reference Include="STMachiningToolsImportHelper">
<HintPath>C:\Program Files\SprutCAM Tech\SprutCAM X 17\Bin64\STMachiningToolsImportHelper.dll</HintPath>
</Reference>
<Reference Include="SprutCAMTech.STTypes">
<HintPath>C:\Program Files\SprutCAM Tech\SprutCAM X 17\Bin64\SprutCAMTech.STTypes.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
- Set existing DLL location paths according to your SprutCAM environment. If you cannot find the DLL libraries, make sure the client SprutCAM X version 17 and above is installed.
- Pay attention to the target framework of your solution, it must match the format net6.0-windows (or higher SDK version).
- Open the Program.cs source file and change its contents as shown below:
using System;
using System.IO;
using SprutCAMTech.MachinigToolsImportTypes;
using SprutCAMTech.STMachiningToolsImportHelper;
using SprutCAMTech.STTypes;
namespace STConsoleApp
{
class Program
{
private static string assemblyPath =
@"C:\Program Files\SprutCAM Tech\SprutCAM X 17\Bin64\" + MTIMachiningToolsImportHelper.DllName;
static void Main(string[] args)
{
if (!File.Exists(assemblyPath)) {
Console.WriteLine("The {0} source file is not found", assemblyPath);
return;
}
try {
var importer = MTIMachiningToolsImportHelper.CreateImporter(assemblyPath);
//Use "importer" to create new tool items, to open an existing or create new machining tools libraries
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
finally {
MTIMachiningToolsImportHelper.FinalizeImporter();
}
}
}
}
Change the "assemblyPath" variable to existing the "Bin64" folder location path according to your SprutCAM environment. Now you can use the "importer" instance to create new tool items, to open an existing or create new machining tools libraries, and more. Pay attention to the call of the FinalizeImporter function, this function is always called before exiting the main program.
- Switch to the "Run and Debug" panel and press to the "Generate C# Assets for Build and Debug" button.
- Now you can start debugging your application:
If you have set all the paths correctly, then this example should work without an error.
⭐ Congratulations, you have set up your development environment. ⭐