-
Notifications
You must be signed in to change notification settings - Fork 1
/
Application.cs
89 lines (80 loc) · 2.93 KB
/
Application.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Diagnostics;
using System.Reflection;
namespace SimpleHouseProject
{
/// <summary>
/// External application class to initialize and manage the Revit add-in.
/// </summary>
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Application : IExternalApplication
{
/// <summary>
/// Called when Revit is shutting down.
/// </summary>
/// <param name="application">The controlled application.</param>
/// <returns>Result.Succeeded if successful.</returns>
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
/// <summary>
/// Called when Revit starts up.
/// </summary>
/// <param name="application">The controlled application.</param>
/// <returns>Result.Succeeded if successful.</returns>
public Result OnStartup(UIControlledApplication application)
{
// Create the ribbon panel and add the push button to it
RibbonPanel panel = RibbonPanel(application);
string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
if (panel.AddItem(new PushButtonData("main", "Create House", thisAssemblyPath, "SimpleHouseProject.main"))
is PushButton button)
{
button.ToolTip = "Creating a house";
}
return Result.Succeeded;
}
/// <summary>
/// Creates or retrieves the ribbon panel for the add-in.
/// </summary>
/// <param name="application">The controlled application.</param>
/// <returns>The ribbon panel for the add-in.</returns>
public RibbonPanel RibbonPanel(UIControlledApplication application)
{
string tab = "HOUSE";
RibbonPanel ribbonPanel = null;
// Attempt to create a new ribbon tab
try
{
application.CreateRibbonTab(tab);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
// Attempt to create a new ribbon panel
try
{
application.CreateRibbonPanel(tab, "Create House");
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
// Retrieve the ribbon panel
List<RibbonPanel> panelList = application.GetRibbonPanels(tab);
foreach (RibbonPanel panel in panelList.Where(p => p.Name == "Create House"))
{
ribbonPanel = panel;
}
return ribbonPanel;
}
}
}