Skip to content

Instantly share code, notes, and snippets.

@giobel
Created May 21, 2019 23:18
Show Gist options
  • Save giobel/9b495f26df733c0be1f365826c5e068c to your computer and use it in GitHub Desktop.
Save giobel/9b495f26df733c0be1f365826c5e068c to your computer and use it in GitHub Desktop.
# Collection of methods to export analytical elements from Revit.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using SpeckleCore;
using SpeckleCoreGeometryClasses;
using SpeckleElements;
namespace SpeckleElementsRevit
{
public static partial class Conversions
{
public static SpeckleElements.AnalyticalFloor ToSpeckle(this Autodesk.Revit.DB.Structure.AnalyticalModelSurface myFloor)
{
var speckleAnalyticalFloor = new SpeckleElements.AnalyticalFloor();
speckleAnalyticalFloor.parameters = GetElementParams(myFloor);
GeometryElement geo = myFloor.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Medium });
List<Solid> solids = new List<Solid>();
foreach (GeometryObject g in geo)
{
try
{
if (g is Line)
{
Line gLine = g as Line;
//TaskDialog.Show("aa", gLine.Length.ToString());
}
if (g is Solid)
{
solids.Add(g as Solid);
}
}
catch { }
}
(speckleAnalyticalFloor.Faces, speckleAnalyticalFloor.Vertices) = GetFaceVertexArrFromSolids(solids);
speckleAnalyticalFloor.baseCurve = getAnalyticalFloorOutline(myFloor);
speckleAnalyticalFloor.ApplicationId = myFloor.UniqueId;
speckleAnalyticalFloor.GenerateHash();
return speckleAnalyticalFloor;
}
public static SpecklePolycurve getAnalyticalFloorOutline(Autodesk.Revit.DB.Structure.AnalyticalModelSurface myFloor)
{
GeometryElement geometry = myFloor.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Medium });
var poly = new SpecklePolycurve();
poly.Segments = new List<SpeckleObject>();
foreach (var g in geometry)
{
try
{
//if (g.GetType().Name == "Line") {
if (g is Line)
{
Line gLine = g as Line;
var mySpeckleLine = new SpeckleLine()
{
ApplicationId = gLine.Reference.ElementId.ToString(), // element id is not unique!!
Value = new List<double>() { gLine.GetEndPoint(0).X, gLine.GetEndPoint(0).Y, gLine.GetEndPoint(0).Z, gLine.GetEndPoint(0).X, gLine.GetEndPoint(0).Y, gLine.GetEndPoint(0).Z },
};
//poly.Segments.Add(SpeckleCore.Converter.Serialise(gLine));
poly.Segments.Add(mySpeckleLine);
}
}
catch {}
}
return poly;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment