/*-------------------------------------------------------------------------
* 功能描述:TestExport
* 作者:xulisong
* 创建时间: 2019/6/18 15:43:54
* 版本号:v1.0
* -------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using RevitExport;
using RevitToJBim.ComponentParse;
using SAGA.RevitUtils;
using SAGA.RevitUtils.Extends;
namespace RevitToJBim
{
public class TestExport
{
public static Document Document { get; set; }
public static void Export()
{
var elements = Document.GetElements(typeof(Pipe));
var wrappers = elements.Select(e => new ElementWrapper(e)).ToList();
ExportInstance report = new ExportInstance(wrappers);
JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
var dd = false;
context.Parser.Parse(report);
var result = context.Serialize();
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
string path = Path.Combine("C", $"{fileName}.json");
File.WriteAllText(path, result);
}
}
///
/// 增加缺失元空间
///
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class AddSiSpaceCommand : IExternalCommand, IExternalCommandAvailability
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
TestExport.Document = commandData.Application.ActiveUIDocument.Document;
TestExport.Export();
TaskDialog dialog = new TaskDialog("导出");
dialog.MainInstruction ="导出成功";
dialog.Show();
}
catch (Exception e)
{
TaskDialog dialog = new TaskDialog("导出");
dialog.MainInstruction =e.Message+"\n\t"+ e.StackTrace.ToString();
dialog.Show();
return Result.Cancelled;
}
return Result.Succeeded;
}
///
/// Onlys show the dialog when a document is open, as Dockable dialogs are only available
/// when a document is open.
///
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
{
return false;
}
}
}