-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.cs
151 lines (127 loc) · 5.03 KB
/
App.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright notice
// Archilizer Family Interface
// to be used in conjunction with Revit Family Editor
// Femily Editor Interface is ease of use type of plug-in -
// it main purpose is to make the process of creating and editting
// of Revit families smoother and more pleasent (less time consuming too)
#region Namespaces
using System;
using System.Reflection;
using System.IO;
using System.Windows.Media.Imaging;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;
using System.Collections;
using FBXExporter.Helpers;
#endregion
namespace FBXExporter
{
/// <summary>
/// Implements the Revit add-in interface IExternalApplication
/// </summary>
class App : IExternalApplication
{
private static UIControlledApplication MyApplication { get; set; }
private static Assembly assembly;
private static object TheInternalDoingPart(UIControlledApplication CApp, string TabName, string PanelName)
{
IList ERPs = null;
ERPs = CApp.GetRibbonPanels(TabName);
Autodesk.Revit.UI.RibbonPanel NewOrExtgRevitPanel = null;
foreach (Autodesk.Revit.UI.RibbonPanel Pan in ERPs)
{
if (Pan.Name == PanelName)
{
NewOrExtgRevitPanel = Pan;
goto FoundSoJumpPastNew;
}
}
Autodesk.Revit.UI.RibbonPanel NewRevitPanel = null;
NewRevitPanel = CApp.CreateRibbonPanel(TabName, PanelName);
NewOrExtgRevitPanel = NewRevitPanel;
FoundSoJumpPastNew:
return NewOrExtgRevitPanel;
}
// class instance
internal static App thisApp = null;
public const string Message = "Batch exporter for FBX files.";
/// <summary>
/// Get absolute path to this assembly
/// </summary>
static string path = Assembly.GetExecutingAssembly().Location;
static string contentPath = Path.GetDirectoryName(Path.GetDirectoryName(path)) + "/";
static string helpFile = "file:///C:/ProgramData/Autodesk/ApplicationPlugins/FBXExporter.bundle/Content/Help/FBX%20Exporter%20_%20Revit%20_%20Autodesk%20App%20Store.html";
#region Ribbon
/// <summary>
/// Use embedded image to load as an icon for the ribbon
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
static private BitmapSource GetEmbeddedImage(string name)
{
try
{
Assembly a = Assembly.GetExecutingAssembly();
Stream s = a.GetManifestResourceStream(name);
return BitmapFrame.Create(s);
}
catch
{
return null;
}
}
/// <summary>
/// Add ribbon panel
/// </summary>
/// <param name="a"></param>
private void AddRibbonPanel(UIControlledApplication a)
{
// Create a custom ribbon panel
var tabName = "Archilizer";
var panelName = "Miscellaneous";
try
{
a.CreateRibbonTab(tabName);
}
catch (Exception)
{
}
var ribbonPanel = (RibbonPanel)TheInternalDoingPart(a, tabName, panelName);
// Get dll assembly path
var thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
assembly = Assembly.GetExecutingAssembly();
var assemblyVersion = assembly.GetName().Version;
var ch = new ContextualHelp(ContextualHelpType.Url, @helpFile);
CreatePushButton(ribbonPanel, string.Format("FBX{0}Exporter", Environment.NewLine), thisAssemblyPath, "FBXExporter.Command",
string.Format("Exports each element of a 3D view to a separate FBX file.{0}{0}v{1}", Environment.NewLine, assemblyVersion), "FBXExporter.Resources.icon_FBXExport.png", ch);
}
private static void CreatePushButton(RibbonPanel ribbonPanel, string name, string path, string command, string tooltip, string icon, ContextualHelp ch)
{
BitmapIcons bitmapIcons = new BitmapIcons(assembly, icon, MyApplication);
PushButtonData pbData = new PushButtonData(
name,
name,
path,
command);
PushButton pb = ribbonPanel.AddItem(pbData) as PushButton;
pb.ToolTip = tooltip;
var largeImage = bitmapIcons.LargeBitmap();
var smallImage = bitmapIcons.SmallBitmap();
pb.LargeImage = largeImage;
pb.Image = smallImage;
pb.SetContextualHelp(ch);
}
#endregion
public Result OnStartup(UIControlledApplication a)
{
ControlledApplication c_app = a.ControlledApplication;
MyApplication = a;
AddRibbonPanel(a);
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication a)
{
return Result.Succeeded;
}
}
}