forked from McCulloughRT/Revit2glTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommand.cs
57 lines (48 loc) · 1.92 KB
/
Command.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
using System;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Microsoft.Win32;
namespace glTFRevitExport
{
[Transaction(TransactionMode.Manual)]
class Command : IExternalCommand
{
public void ExportView3D(View3D view3d, string filename, string directory)
{
Document doc = view3d.Document;
// Use our custom implementation of IExportContext as the exporter context.
glTFExportContext ctx = new glTFExportContext(doc, filename, directory);
// Create a new custom exporter with the context.
CustomExporter exporter = new CustomExporter(doc, ctx);
exporter.ShouldStopOnError = true;
exporter.Export(view3d);
}
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
View3D view = doc.ActiveView as View3D;
if (view == null)
{
TaskDialog.Show("glTFRevitExport", "You must be in a 3D view to export.");
return Result.Failed;
}
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.FileName = "NewProject"; // default file name
fileDialog.DefaultExt = ".gltf"; // default file extension
bool? dialogResult = fileDialog.ShowDialog();
if (dialogResult == true)
{
string filename = fileDialog.FileName;
string directory = Path.GetDirectoryName(filename) + "\\";
ExportView3D(view, filename, directory);
}
return Result.Succeeded;
}
}
}