/
spruttechnology
/
cam-api-examples
Обзор
Документация
Войти
/
spruttechnology
/
cam-api-examples
Код
Запросы
3
Задачи
Пакеты
0
Релизы
1
Аналитика
v19/develop
UI/SelectedFeaturesViewerNet/project/main/SelectedFeaturesExtension.cs
49 строк
2 KB
renal
Новые примеры CAMAPI
22 июн 2026, 15:53
22 июн 2026, 15:53
a5f6d2b
Код
Авторство
О чём код?
using CAMAPI.Application; using CAMAPI.DotnetHelper; using CAMAPI.Extensions; using CAMAPI.ResultStatus; namespace SelectedFeaturesViewerNet; /// <summary> /// Toolbar utility that opens a non-modal window listing the features recognized on the /// geometry nodes currently selected in the viewport. /// Implements <see cref="IExtensionLazyUnloadable"/> so CAM defers DLL unloading until the /// window closes — the window keeps living after <see cref="Run"/> returns. /// </summary> public class SelectedFeaturesExtension : IExtension, IExtensionUtility, IExtensionLazyUnloadable { private readonly ExtensionWindowLazyUnloadable _windowManager = new(); /// <inheritdoc /> public IExtensionInfo? Info { get; set; } /// <inheritdoc /> public bool CanUnload { get => _windowManager.CanUnload; set { } } /// <inheritdoc /> public void Run(IExtensionUtilityContext context, out TResultStatus resultStatus) { resultStatus = default; try { using var applicationCom = ComWrapper.Create(context.CamApplication); _windowManager.SetOwnerHandle(applicationCom); // Second wrapper — no 'using' — ownership transferred to the window, // which disposes it in SelectedFeaturesWindow.Dispose(). var appForWindow = ComWrapper.Create(context.CamApplication); _windowManager.ShowWindow(() => new SelectedFeaturesWindow(appForWindow)); // Run returns immediately; the window lives on its own STA thread. } catch (Exception e) { resultStatus.Code = TResultStatusCode.rsError; resultStatus.Description = e.Message; } } }