-
Notifications
You must be signed in to change notification settings - Fork 2
/
AddIn.cs
56 lines (45 loc) · 1.75 KB
/
AddIn.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
using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using DesignAutomationFramework;
using Autodesk.Revit.ApplicationServices;
using System.IO;
namespace Revit2Svg
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class AddIn : IExternalDBApplication
{
public ExternalDBApplicationResult OnStartup(Autodesk.Revit.ApplicationServices.ControlledApplication app)
{
DesignAutomationBridge.DesignAutomationReadyEvent += HandleDesignAutomationReadyEvent;
return ExternalDBApplicationResult.Succeeded;
}
public void HandleDesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e)
{
e.Succeeded = true;
ExportToSvg(e.DesignAutomationData);
}
public static void ExportToSvg(DesignAutomationData data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
var rvtApp = data.RevitApp;
if (rvtApp == null) throw new InvalidDataException(nameof(rvtApp));
string modelPath = data.FilePath;
if (string.IsNullOrWhiteSpace(modelPath)) throw new InvalidDataException(nameof(modelPath));
var doc = data.RevitDoc;
if (doc == null) throw new InvalidDataException(nameof(doc));
using (var tx = new Transaction(doc))
{
tx.Start("Export to Svg");
var renderer = new SvgRenderer();
renderer.Render(doc);
tx.RollBack();
}
}
public ExternalDBApplicationResult OnShutdown(ControlledApplication application)
{
return ExternalDBApplicationResult.Succeeded;
}
}
}