/
spruttechnology
/
cam-api-examples
Обзор
Документация
Войти
/
spruttechnology
/
cam-api-examples
Код
Запросы
3
Задачи
Пакеты
0
Релизы
1
Аналитика
v19/develop
Geometry/AddinImportObjNet/project/main/Program.cs
90 строк
3 KB
renal
Stabilization with fresh update of CAM
10 апр 2026, 15:28
10 апр 2026, 15:28
ff452f8
Код
Авторство
О чём код?
using CAMHelper.NativeLibUtils; using Geometry.VecMatrLib; using STGeomApiTypes; namespace AddinImportObjNet; /// <summary> /// Addin to import .obj files into CAM geometry /// </summary> public static class Program { private delegate IntPtr GetGeomFilerDelegate(); /// <summary> /// Using STGeomFile.dll, this addin imports OBJ files into CAM geometry. /// </summary> public static void Main(string [] args) { // read params if (args.Length < 1) throw new Exception("Usage: AddinImportObjNet <in-file> <out-file>"); var objFile = args[0]; var sgfFilePath = args.Length > 1 ? args[1] : "temp.sgf"; // connect STGeomFile.dll var dllPath = Path.Combine(@"C:\Program Files\Sprut Technology\SprutCAM 19\Bin64", "STGeomFile.dll"); if (!File.Exists(dllPath)) throw new Exception($"{dllPath} not found"); if (!File.Exists(dllPath)) throw new Exception("STGeomFile.dll not found: " + dllPath); var geomFile = NativeLibLoader.CreateComObject<ISTGeomFiler, GetGeomFilerDelegate>(dllPath, "CreateGeomFiler", out var objectPointer, out var dllPointer) ?? throw new Exception("Error creating geomFiler"); try { Import(geomFile, objFile, sgfFilePath); } finally { NativeLibLoader.FreeDll(geomFile, objectPointer, dllPointer); } } private static bool Import(ISTGeomFiler geomFile, string inputFile, string outputFile) { bool succeed; if (File.Exists(outputFile)) File.Delete(outputFile); // try to read file first var objReader = new ObjReader(inputFile); // beginning of the file if (!geomFile.StartFile(outputFile)) throw new Exception("Can't start file: " + outputFile); if (geomFile is not ISTGeomReceiver geomReceiver) throw new Exception("Can`t cast geomFile to geomReceiver"); try { try { // set point, we are going to use it as a coordinate system geomReceiver.SetCurrentTransform(T3DMatrix.Unit.vT, T3DMatrix.Unit.vZ, T3DMatrix.Unit.vX); // item in geometry objects tree geomReceiver.StartGroupEntity("obj_entities"); try { objReader.BuildModel(geomReceiver); succeed = true; } finally { geomReceiver.CloseGroupEntity(); } } finally { geomReceiver.CloseModel(); } } finally { geomFile.CloseFile(); } return succeed; } }