G'day Jeremey, thanks. Your help is greatly apprecitaed.
The 'general' problem I'm trying to solve is the the running of new functions defined interactivly at runtime using the F# compiler service.
I think this approach has a lot of advantages.
It would allow me to to build this but for Revit. https://www.youtube.com/watch?v=McJKA9OODyk&feature=youtu.be
I'm getting a managed exception thrown message when I try to set the view.
#r @"C:\Program Files\Autodesk\Revit 2016\RevitAPI.dll"
#r @"C:\Program Files\Autodesk\Revit 2016\RevitAPIUI.dll"
#r @"C:\EE\Git\Tsunami-main\bin\Debug\Tsunami.IDEDesktop.dll"
open Autodesk.Revit
open Autodesk.Revit.UI
open System
open System.Collections.Generic
open Autodesk.Revit.DB
open Autodesk.Revit.DB.Architecture
open Autodesk.Revit.UI
open Autodesk.Revit.UI.Selection
open Autodesk.Revit.ApplicationServices
open Autodesk.Revit.Attributes
let mutable app = Plugin.Mantis.Global.App
let mutable doc = Plugin.Mantis.Global.Document
module Seq =
let tryHead (xs:'a seq) =
let ys = xs.GetEnumerator()
if ys.MoveNext() then Some(ys.Current) else None
try
let getView =
use xs = new FilteredElementCollector(doc);
xs.OfClass(typeof<View3D>)
|> Seq.tryHead
|> function
| None -> ()
| Some(view) ->
let uiDoc = app.ActiveUIDocument
uiDoc.ActiveView <- view
let sel = uiDoc.Selection
let ref = sel.PickObject(ObjectType.Element, "Please select a group")
let elem = doc.GetElement(ref.ElementId);
Windows.Forms.MessageBox.Show(ref.ElementId.ToString()) |> ignore
with
| e -> Windows.Forms.MessageBox.Show(e.Message) |> ignore
This is after setting it up with a normal plugin...
interface IExternalCommand with
member this.Execute(commandData : ExternalCommandData, message: byref<string>, element : ElementSet) =
Plugin.Mantis.Global.App <- commandData.Application
Plugin.Mantis.Global.Document <- commandData.Application.ActiveUIDocument.Document
let win = Windows.Window()
Mantis.window <- Some(win)
let cont = runControl()
win.Content <- cont
win.Show();
Result.Succeeded