Получить UIApplication в OnStartup

Автор Тема: Получить UIApplication в OnStartup  (Прочитано 3397 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Тема содержит сообщение с Решением. Нажмите здесь чтобы посмотреть его.

Оффлайн enotАвтор темы

  • ADN OPEN
  • *****
  • Сообщений: 525
  • Карма: 2
Получить UIApplication в OnStartup
« : 23-10-2018, 18:01:21 »
Корректно ли будет получить UIApplication  в OnStartup (если да , то как) ?
т.е.

Код - C# [Выбрать]
  1.     public Autodesk.Revit.UI.Result OnStartup(
  2.         Autodesk.Revit.UI.UIControlledApplication application)
  3.     {
  4.  
  5.         UIApplication uiapp = ???;

Оффлайн Александр Игнатович

  • Administrator
  • *****
  • Сообщений: 1152
  • Карма: 338
  • Skype: alexandr.ignatovich.itc
Re: Получить UIApplication в OnStartup
« Ответ #1 : 23-10-2018, 18:07:14 »
Нет. Чем UIControlledApplication, передаваемый параметром не устраивает?

Оффлайн enotАвтор темы

  • ADN OPEN
  • *****
  • Сообщений: 525
  • Карма: 2
Re: Получить UIApplication в OnStartup
« Ответ #2 : 23-10-2018, 18:10:46 »
хочу получить

Код - C# [Выбрать]
  1.     Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
  2.         UIDocument uidoc = uiapp.ActiveUIDocument;
  3.         Document doc = uidoc.Document;
  4.         Autodesk.Revit.DB.View view = doc.ActiveView;

Оффлайн enotАвтор темы

  • ADN OPEN
  • *****
  • Сообщений: 525
  • Карма: 2
Re: Получить UIApplication в OnStartup
« Ответ #3 : 23-10-2018, 18:12:18 »
вообще, основная цель это (Command_  выполнялась при запуске ревита)

внутри
Код - C# [Выбрать]
  1. public Autodesk.Revit.UI.Result OnStartup(
  2.         Autodesk.Revit.UI.UIControlledApplication application)
  3.     {

запустить
Код - C# [Выбрать]
  1.  [Transaction(TransactionMode.Manual)]
  2.     public class Command_ : IExternalCommand
  3.     {
  4.  
  5.         public Result Execute(
  6.                 ExternalCommandData commandData,
  7.                 ref string message,
  8.                 ElementSet elements)

Отмечено как Решение enot 23-10-2018, 18:17:40

Оффлайн Александр Игнатович

  • Administrator
  • *****
  • Сообщений: 1152
  • Карма: 338
  • Skype: alexandr.ignatovich.itc
Re: Получить UIApplication в OnStartup
« Ответ #4 : 23-10-2018, 18:12:54 »
А ничего, что в момент OnStartup еще никакого ActiveUIDocument в помине нет?

Оффлайн enotАвтор темы

  • ADN OPEN
  • *****
  • Сообщений: 525
  • Карма: 2
Re: Получить UIApplication в OnStartup
« Ответ #5 : 23-10-2018, 18:15:17 »
Прямо перед вашим ответом в голове промелькнула та же мысль. значит IExternalCommand запускаем только по клацанью кнопки...

Оффлайн enotАвтор темы

  • ADN OPEN
  • *****
  • Сообщений: 525
  • Карма: 2
Re: Получить UIApplication в OnStartup
« Ответ #6 : 23-10-2018, 18:36:48 »
Есть ли аналог public Autodesk.Revit.UI.Result OnStartup(
        Autodesk.Revit.UI.UIControlledApplication application)

но для момента открытия конкретного документа ? цель :В момент открытия запускаем некий IUpdater


Оффлайн Александр Игнатович

  • Administrator
  • *****
  • Сообщений: 1152
  • Карма: 338
  • Skype: alexandr.ignatovich.itc
Re: Получить UIApplication в OnStartup
« Ответ #7 : 23-10-2018, 18:40:20 »
ControlledApplication.DocumentOpened

Цитировать
This event is raised immediately after Revit has finished opening a document. It is raised even when document opening failed or was cancelled (during DocumentOpening event).

Handlers of this event are permitted to make modifications to any document (including the active document), except for documents that are currently in read-only mode.

Check the 'Status' field in event's argument to see whether the action itself was successful or not.

This event is not cancellable, for the process of opening document has already been finished.

If the action was not successful, the document may not be modified and new transactions may not be started.

The following API functions are not available for the current document during this event:

Close()()()() and similar overloads.

Exception InvalidOperationException will be thrown if any of the above methods is called during this event.

Оффлайн enotАвтор темы

  • ADN OPEN
  • *****
  • Сообщений: 525
  • Карма: 2
Re: Получить UIApplication в OnStartup
« Ответ #8 : 24-10-2018, 10:27:37 »
Александр, все получилось, спасибо вам)

Оффлайн Александр Игнатович

  • Administrator
  • *****
  • Сообщений: 1152
  • Карма: 338
  • Skype: alexandr.ignatovich.itc
Re: Получить UIApplication в OnStartup
« Ответ #9 : 24-10-2018, 10:28:27 »
Супер, рад за Вас. Обращайтесь

Оффлайн Agens

  • ADN OPEN
  • ***
  • Сообщений: 223
  • Карма: 0
Re: Получить UIApplication в OnStartup
« Ответ #10 : 05-01-2022, 12:15:50 »
Буду добавлять темы кусками кода, т.к. приходится разбираться самому. Решение выглядит так:
Код - C# [Выбрать]
  1. // создаем событие на открытие файла
  2.         public Result OnStartup(UIControlledApplication application)
  3.         {
  4.             try
  5.             {            
  6.                 // собственно само событие
  7.                 application.ControlledApplication.DocumentOpened += new EventHandler
  8.                      <Autodesk.Revit.DB.Events.DocumentOpenedEventArgs>(application_DocumentOpened);
  9.             }
  10.             catch (Exception)
  11.             {
  12.                 return Result.Failed;
  13.             }                                      
  14.  
  15.             return Result.Succeeded;
  16.         }
  17.  
  18.         public void application_DocumentOpened(object sender, DocumentOpenedEventArgs args)
  19.         {
  20.             Application app = sender as Application; // самая важная строчка :)
  21.             Document doc = args.Document;
  22.  
  23.            // ваш код
  24.         }
  25.  
VS2019, VBA 7.1, VB.NET, C#, ACAD2019, Revit 2020