80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
|
using Autodesk.Revit.Attributes;
|
|||
|
using Autodesk.Revit.DB;
|
|||
|
using Autodesk.Revit.UI;
|
|||
|
using iText.Kernel.Pdf;
|
|||
|
using iText.Kernel.Pdf.Annot;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Reflection;
|
|||
|
|
|||
|
namespace PDF3D.Addin
|
|||
|
{
|
|||
|
[Transaction(TransactionMode.Manual)]
|
|||
|
public class ExportCmd : IExternalCommand
|
|||
|
{
|
|||
|
public static string PDF = @"D:\OneDrive\Code\Private\PDFGenerator\PDF3D.Addin\bin" + @"\\Pdf3D.pdf";
|
|||
|
public static string U3D = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\\test.u3d";
|
|||
|
public static string IDTF = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\\test.IDTF";
|
|||
|
public static string PDFTool = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\\PDFGenerator.exe";
|
|||
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|||
|
{
|
|||
|
UIDocument uIDocument = commandData.Application.ActiveUIDocument;
|
|||
|
Document doc = uIDocument.Document;
|
|||
|
|
|||
|
var elems = uIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element).Select(x => doc.GetElement(x)).ToList();
|
|||
|
|
|||
|
IDTFBuilder iDTFBuilder = new IDTFBuilder(doc);
|
|||
|
|
|||
|
var categorys = elems.GroupBy(x => x.Category.Name);
|
|||
|
foreach ( var category in categorys)
|
|||
|
{
|
|||
|
iDTFBuilder.InsertGroup(category.Key);
|
|||
|
}
|
|||
|
|
|||
|
foreach (var item in elems)
|
|||
|
{
|
|||
|
iDTFBuilder.InsertElement(item);
|
|||
|
}
|
|||
|
iDTFBuilder.Export(IDTF);
|
|||
|
|
|||
|
GeneratePDF();
|
|||
|
|
|||
|
return Result.Succeeded;
|
|||
|
}
|
|||
|
|
|||
|
public IEnumerable<Solid> GetSolids(GeometryObject go)
|
|||
|
{
|
|||
|
if (go is GeometryElement ge)
|
|||
|
{
|
|||
|
foreach (GeometryObject item in ge)
|
|||
|
{
|
|||
|
foreach (var g in GetSolids(item))
|
|||
|
{
|
|||
|
yield return g;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (go is Solid solid)
|
|||
|
{
|
|||
|
yield return solid;
|
|||
|
}
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
|
|||
|
public void GeneratePDF()
|
|||
|
{
|
|||
|
System.Diagnostics.Process exep = new System.Diagnostics.Process();
|
|||
|
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
|||
|
startInfo.FileName = PDFTool;
|
|||
|
startInfo.Arguments = $"\"{IDTF}\" \"{PDF}\"";
|
|||
|
startInfo.CreateNoWindow = true;
|
|||
|
startInfo.UseShellExecute = false;
|
|||
|
exep.StartInfo = startInfo;
|
|||
|
exep.Start();
|
|||
|
exep.WaitForExit();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|