Giter Site home page Giter Site logo

bim-net-interactive's Introduction

BIM Interactive Notebooks

This is a personal project that explores the possibility to run live Revit C#-scripts inside notebooks bundled with visualizations and narrative text.

This has resulted in different parts:

  1. A Revit Addin (Technically a implementation of a NET interactive kernel)
  2. Visual Studio Code Polyglot Notebooks extension
  3. A collection of showcase notebooks (see /samples/) (IN PROGRESS)

Revit addin

There is a quite stable version of the addin. I am working on an installer.

System Prompting LLM

When using CHAT-GPT to write revit API Code for use in the notebook you would probably want to steer it's behaviour to minimize editing the code for use in an interactive context. See System Promts for some initial drafts.

Begin conversation by:

[SYSTEM] {System prompt text}

Extension to VS Code Polyglot Notebook

The idea is to run scripts with Polyglot Notebook Extension, an extension to Visual Studio Code, a free code editor.

In Visual Studio Code, open a new notebook and create a code cell to enable the revit interaction using the #r directive.

#r "nuget:RevitInteractive"

Use the #connect-directive to establish live connection to revit. This requires an addin.

#!connect revit --kernel-name revit24 --revit-version 2024

Then inside a code cell, execute the code inside Revit using a magic command for the kernel:

#!revit24   
var collector = new FilteredElementCollector( doc, uidoc.ActiveView.Id);

var query = collector
        .WhereElementIsNotElementType()
        .WhereElementIsViewIndependent()
        .ToElements();

var result = query.GroupBy(x => x.Category.Name).Select(y => new {
    Id = y.Key,
    Count = y.Count()
}).ToList();

display(result);
result

Examples

Extracting profile geometry from floor and export to shapefile for GIS-visualization using C# and Python (with Shapely and Geopandas).

See samples/GIS/GIS Visualization Building Footprint.ipynb

Limitations

The Revit API is tightly coupled with the Revit UI and the Revit document data structures and operates on the assumption that it's being called within the same process where the UI and the document are loaded. This prevents you from calling the API from for example a polyglot notebook without some kind of middle-man or dispatcher.

Current solution

NET interactive operates with kernels. A kernel is simply a process that receives execution instructions from clients and communicates the results back to them. The decopuled two-process model where you separate execution from evaluation allows for an approach where an evaluator can live inside Autodesk Revit as an addin and receives code from frontend clients such as Polyglot Notebook, Azure Data Studio or Jupyter.

In .NET Interactive a proxy kernel is a concept that describes a subkernel that proxies a remote kernel. We can add a proxy kernel to the composite kernel that routes commands to the actual implementation written as a Revit Addin. The revit addin implements a NET Interactive kernel process and executes code in the Revit API thread using external events(check Jeremy Tammik's arcticle External Access to the Revit API for more info on this topic).

However, due to the issues with third-party conflicts regarding the Roslyn API:s it was a hurdle to compile the code in the Revit addin so I tested to move the compilation before the code is sent to the embedded kernel in Revit. Technically, it is done using a registered middleware on the proxykernel that compiles the code and then send the path to the compiled assembly to the revit addin which loads it into memory and executes a method defined in a common interface with a list of common variables.

Resources

Aknowledgements and third-party dependencies

License

MIT

bim-net-interactive's People

Contributors

chuongmep avatar jowsy avatar sweco-sejsau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.