/
spruttechnology
/
cam-api-examples
Обзор
Документация
Войти
/
spruttechnology
/
cam-api-examples
Код
Запросы
3
Задачи
Пакеты
0
Релизы
1
Аналитика
v19/develop
ProjectMachine/ExtensionUtilityProjectMachineInfoNet/project/main/ExtensionProjectMachineInfo.cs
54 строки
2 KB
bond
Applied new SDK version
12 дек 2024, 16:18
12 дек 2024, 16:18
69550e4
Код
Авторство
О чём код?
using System.Diagnostics; using CAMAPI.Application; using CAMAPI.Extensions; using CAMAPI.Machine; using CAMAPI.Project; using CAMAPI.ResultStatus; using CAMAPI.DotnetHelper; namespace ExtensionUtilityProjectMachineInfoNet; /// <summary> /// Utility to get information about machine from the active project /// </summary> public class ExtensionProjectMachineInfo: IExtension, IExtensionUtility { /// <inheritdoc /> public IExtensionInfo? Info { get; set; } /// <inheritdoc /> public void Run(IExtensionUtilityContext context, out TResultStatus resultStatus) { resultStatus = default; try { using var applicationCom = new ComWrapper<ICamApiApplication>(context.CamApplication); var application = applicationCom.Instance; // active project using var activeProjectCom = new ComWrapper<ICamApiProject>(application.GetActiveProject(out resultStatus)); if (resultStatus.Code == TResultStatusCode.rsError) throw new Exception("Can't get active project: " + resultStatus.Description); if (activeProjectCom == null) throw new Exception("Active project is not found"); var activeProject = activeProjectCom.Instance; // machine information using var machineInfoCom = new ComWrapper<ICamApiMachineInfo>(activeProject.MachineInformation); var machineInfo = machineInfoCom.Instance; var tmpFileName = Path.GetTempFileName(); File.WriteAllText(tmpFileName, "Current project: " + activeProject.FilePath + Environment.NewLine + "Machine caption: " + machineInfo.MachineCaption + Environment.NewLine + "Machine GUID: " + machineInfo.GUID + Environment.NewLine + "Machine file path: " + machineInfo.SchemaFilePath + Environment.NewLine + "Machine xml node name: " + machineInfo.XMLNodeName + Environment.NewLine ); Process.Start("notepad.exe", tmpFileName); } catch (Exception e) { resultStatus.Code = TResultStatusCode.rsError; resultStatus.Description = e.Message; } } }