Last active
April 12, 2017 13:44
-
-
Save goswinr/7ad3638e0caa161a999fe6cfee05f734 to your computer and use it in GitHub Desktop.
Generating the model of Louvre Abu Dhabi in Revit with Mantis in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generating the full model using my custom DLLs for geometry input | |
// F# editor: https://gist.github.com/moloneymb/5e5608c129337cfefa40 | |
#r @"C:\Program Files\Autodesk\Revit 2016\RevitAPI.dll" | |
#r @"C:\Program Files\Autodesk\Revit 2016\RevitDBAPI.dll" | |
#r @"C:\Program Files\Autodesk\Revit 2016\RevitAPIUI.dll" | |
#r @"C:\Program Files\Mantis\Tsunami.IDEDesktop.dll" | |
#r @"C:\work\goswin\30_F#\16-135_LAD\LAD\GosLib\bin\Release\GosLib.dll" | |
#r @"C:\work\goswin\30_F#\16-135_LAD\LAD\LAD\bin\Release\LAD.dll" | |
open Autodesk.Revit.DB | |
open Microsoft.FSharp.Collections | |
for he in LAD.Build.hedsAllSeq() do // building 8 layers | |
let gData = LAD.DrawData.wingsAsAssemblies he // getting Faces (4 points each) and Names from my DLL | |
Mantis.run (fun app -> | |
(fun (doc:Document) -> | |
use trans = new Transaction( doc, "LAD layer" ) // this gets called 8750 times | |
trans.Start() |> ignore | |
for i=0 to gData.Length-1 do | |
let builder = new TessellatedShapeBuilder() | |
builder.OpenConnectedFaceSet(false) | |
let ptss,name = gData.[i] // ptts is 16 Faces(4 points each), the Name is for each of the 8750 stars, it's something like "s3-1514" | |
for pts in ptss do | |
//pts reperesents a face, it is an Array of 4 3D point | |
let xyzs = pts |> Array.map (fun point -> XYZ(point.x , point.y, point.z)) // make a revit point from my point | |
let face = new TessellatedFace( xyzs, ElementId.InvalidElementId ) | |
builder.AddFace( face ) | |
builder.CloseConnectedFaceSet() | |
let result = builder.Build( TessellatedShapeBuilderTarget.AnyGeometry, | |
TessellatedShapeBuilderFallback.Mesh, | |
ElementId.InvalidElementId ) | |
let categoryId = new ElementId(BuiltInCategory.OST_GenericModel ) | |
let ds = DirectShape.CreateElement(doc, categoryId, "LADg","LADi") // this gets called 8750 times | |
ds.Name <- name // is there also a way to create more BIM like properties? | |
ds.SetShape( result.GetGeometricalObjects() ) | |
trans.Commit() |> ignore | |
) | |
app.ActiveUIDocument.Document) |> ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This simple example shows how the grid of LAD can be defined just with lines on a sphere. | |
// F# editor: https://gist.github.com/moloneymb/5e5608c129337cfefa40 | |
let pattern = | |
[| | |
[| 0,3 ; -2,2 ; -3,0 ; -2,-2 ; 0,-3 ; 2,-2 ; 3,0 ; 2,2 |] | |
[| 0,3 ; 2,2 ; 2,4 |] | |
[| 2,2 ; 3,0 ; 4,2 |] | |
[| 2,4 ; 4,4 ; 3,6 |] | |
[| 4,2 ; 6,3 ; 4,4 |] | |
[| 2,2 ; 4,2 ; 4,4 ; 2,4 |] | |
|] | |
let mapN f = Array.map (Array.map f) | |
#r @"C:\Program Files\Autodesk\Revit 2016\RevitAPI.dll" | |
#r @"C:\Program Files\Autodesk\Revit 2016\RevitDBAPI.dll" | |
#r @"C:\Program Files\Autodesk\Revit 2016\RevitAPIUI.dll" | |
open Autodesk.Revit.DB | |
let points = mapN (fun (u,v) -> XYZ(float u, float v, 0.0)) pattern | |
let edges = | |
[| for pts in points do | |
for i = 0 to pts.Length - 2 do | |
yield Line.CreateBound(pts.[i] , pts.[i+1]) | |
yield Line.CreateBound(pts.[pts.Length-1] , pts.[0] ) // connect last to first | |
|] | |
#r @"C:\Program Files\Mantis\Tsunami.IDEDesktop.dll" | |
let drawLines (lines:Line []) = | |
Mantis.run (fun app -> | |
(fun (doc:Document) -> | |
use t = new Transaction(doc, "draw Line") | |
t.Start() |> ignore | |
let ds = DirectShape.CreateElement(doc, ElementId(BuiltInCategory.OST_GenericModel), "ME", "MEo") | |
let linesGeoObj = [| for ln in lines -> ln :> GeometryObject |] | |
ds.SetShape(linesGeoObj) | |
t.Commit() |> ignore) | |
app.ActiveUIDocument.Document) |> ignore | |
drawLines edges | |
// draw grid | |
let shiftLine (offX, offY) (l:Line) = | |
let offset = XYZ(offX, offY , 0.0 ) | |
Line.CreateBound (l.GetEndPoint 0 + offset , l.GetEndPoint 1 + offset) | |
let uvs = | |
let ext = 6 * 8// step size 6*7, max 19 at 0.013 radians | |
[| for u in -ext..6..ext do | |
for v in -ext..6..ext do | |
yield float u, float v |] | |
let edgesShifted = | |
[| for uv in uvs do yield! Array.map (shiftLine uv) edges |] | |
edgesShifted | |
|> drawLines | |
// draw sphere | |
let setToSphere (pt:XYZ) = | |
let uRad = pt.X * 0.014 //to get angle in Radians | |
let vRad = pt.Y * 0.014 | |
let x = sin uRad / cos uRad | |
let y = sin vRad / cos vRad | |
let f = 65. / sqrt (x*x + y*y + 1.) // Radius of spheere // inverse length to get scaling factor for this vector | |
XYZ(x*f, y*f, f) | |
let setLineToSphere (l:Line) = Line.CreateBound (setToSphere (l.GetEndPoint 0) , setToSphere (l.GetEndPoint 1) ) | |
edgesShifted | |
|> Array.map setLineToSphere | |
|> drawLines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment