CEFSharp Integration into Revit

CEFSharp Integration into Revit

paul.vesey
Participant Participant
4,473 Views
12 Replies
Message 1 of 13

CEFSharp Integration into Revit

paul.vesey
Participant
Participant

I am trying to integrate CEF Sharp WPF (Chromeium Browser) control into Jeremy Tammik's Dockable Dialog.  I seem to be able to integrate the package, but the browser will not render.  Has anyone else tryed to do this?  Any pointers would be appreciated.  Thanks..

 

CEF Sharp is here: https://www.nuget.org/packages/CefSharp.Wpf/49.0.0-pre02

Dockable Dialog is here: https://github.com/jeremytammik/DockableDialog

 

The image below shows the current status... Thanks..

 

 

 

 

CEF.JPG

4,474 Views
12 Replies
Replies (12)
Message 2 of 13

jeremytammik
Autodesk
Autodesk

Dear Paul,

 

Thank you for your query.

 

Yes, I spent a significant amount of time working on that exact topic.

 

Actually, I was working on displaying the Autodesk View and Data API viewer inside a Chrome or CefSharp control in a Windows form in a Revit add-in.

 

I gave it up in the end, though, and apparently never published that work.

 

I got bits and pieces to run, but it was very fiddly indeed.

 

CEF depends on a number of DLLs, and is extremely picky in the versions it requires.

 

As far as I remember, I got it to run using certain specific release DLLs, but not the debug ones, or vice versa.

 

I was also unable to integrate the CEF stuff to compile in the same project as my Revit add-in.

 

I am appending the state of my work as I left it when I gave it up in December 2014 to this message in cefsharp_RvtChrome.zip.

 

To make your mouth water, I am also attaching some images that I made back then.

 

The situation is probably much better today that it was back then, though.

 

I hope this helps.

 

Good luck!

 

Best regards,

 

Jeremy

 

cefsharp_wpf_viewer_example_2d.png

 

cefsharp_wpf_viewer_example_3d.png

 

 

cefsharp_wpf_viewer_example_3d_2.png

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 13

paul.vesey
Participant
Participant

Thanks Jeremy.  

 

I will have a go.  If anything comes of it I will let you know.  

 

Cheers, Paul

0 Likes
Message 4 of 13

Anonymous
Not applicable

Not sure if this is still outstanding.  But through many trials determined the DLLs and their placement in the solution via the nuget package manager work fine as of this writing.  The extra step to get them functioning is to properly set the following paths in the CefSettings:

 

the folders below will be defined programmatically in strings... but for my quick test I hard-coded the file and folder paths.

 

var settings = new CefSettings

                {

                    BrowserSubprocessPath = @"C:\Users\Nathan Lowe WW\Documents\Visual Studio 2015\Projects\RevitCefSharpTest3\RevitCefSharpTest3\bin\x64\Debug\CefSharp.BrowserSubprocess.exe",

                    LocalesDirPath = @"C:\Users\Nathan Lowe WW\Documents\Visual Studio 2015\Projects\RevitCefSharpTest3\packages\cef.redist.x64.3.2623.1401\CEF\locales",

                    ResourcesDirPath = @"C:\Users\Nathan Lowe WW\Documents\Visual Studio 2015\Projects\RevitCefSharpTest3\RevitCefSharpTest3\bin\x64\Debug" ,            

                };

 

Once those are set... instantiate your ChromiumWebBrowser with the settings and you should be good to go.

Message 5 of 13

Anonymous
Not applicable
Dear Paul: How about your progress of CEFSharp Integration into Revit ? I am trying same work too, in a wpf application, the cefsharp is work, but after intertated into Revit, it's did not work. I guess there may have two problem below. 1.Revit api did not support mutil threading program, but Cef required it. 2.The assembly path are very important , sometime the path will be as some as revit.exe 's path, but in this project, I put dlls in Revit path, it did not work and no warnings. If you have and progress, hope you share it,thanks a lot. RGS Andy
0 Likes
Message 6 of 13

paul.vesey
Participant
Participant

Hi Andy,

 

I dropped in favour of DotNetBrowser.  (see https://www.teamdev.com/dotnetbrowser).  you can get a free licence if you OS your project; otherwise you have to pay.  In the end it turned out to be the fastest way to move forward.

 

0 Likes
Message 7 of 13

Anonymous
Not applicable

Hi Paul,thanks a lot, I will try it.

0 Likes
Message 8 of 13

Anonymous
Not applicable

Andy,

 

What issues are you having? Did the strategies in my post solve the issue for you?

 

Multi-threading is a separate issue as you can use multi-threading in an Revit API application... you just can't make calls involving Revit's document context outside of the main application thread context... meaning you can call the uiApp / document in the main thread (via external event/idle event/Command) and then once you've extracted information, you can process it on another thread or in an async callback, etc. provided you don't attempt to merge it back with the main thread context. The confusion can sometimes arise because it's not always clear which API objects require calls to the main document context (for instance, elements have properties in both camps).  My comment assumes that you've converted any Revit API objects to a POCO object before continuing to manipulate them.

 

Anyway, back to the issue, CEF, at least, at the time of my last post, required that you have a specific targeted platform (x86 or 64)... whereas, the Revit API allows targeting multiple target platforms. In order to use CEF and Revit API together, it just requires targeting specific builds for the sake of CEF and then configuring the few settings I highlighted in my previous post.

 

Let me know if you have any questions.

Message 9 of 13

Anonymous
Not applicable

Dear Nathan:

 

         Use code to set apps setting is good idea. I will try.

 

         And thanks for your explanation of multi-threading program in Revit ,as same as I think about revit, but your explanation really let me will not be  worried about it.

 

         Use DotNetBrowser it is worked, and satisfy my requirement, but I will do it in your way.  For the platforms, perhaps we can judge it by the method of Environment.Is64BitProcess() before set cefsharp setting.

 

         Thanks a lot!

 

RGS

Andy 

0 Likes
Message 10 of 13

boostyourbim
Advocate
Advocate

Hi Nathan,

 

If you got CEFSharp to work with Revit 2017, could you let me know what version of CefSharp and cef.redist you used?

 

Thanks

Harry

0 Likes
Message 11 of 13

Anonymous
Not applicable

Hi Jeremy,

 

Any updates on this? We are trying to create an addin with CefSharp Chromium browser inside dockable pane.

0 Likes
Message 12 of 13

s.hamel
Community Manager
Community Manager

I took a look, to get the RVTChrome project working with Revit 2020 I needed to do the following:

Update Revit api references of course (Set copy locals to false)

Switch to using nuget packages of CefSharp.Common and CefSharp.Winforms (Version 65.0.1 which is what Revit2020 uses)

Change WebView to ChromiumWebBrowser

Commented out the OnPropertyChanged since those events now get handled individually instead of as a group

Update build events since it was copying the old cefsharp folder

Thanks,



Shayne Hamel
Manager, Principal Software Engineering
0 Likes
Message 13 of 13

Mark.Ackerley
Advocate
Advocate

Hi Shayne, (thanks Jeremy for the .zip),

 

Thanks for those hints, really useful, unfortunately, though I have managed to get it to build, and though it is an option for me in External Tools and there are no exceptions... nothing opens!

 

I'm trying with vs2019, Revit 2021, CefSharp 81.3.100 (Redist 81.3.10) does that sound promising?

 

I have pruned browser.cs down to....

 

 

 

 

namespace RvtChrome
{
  public partial class Browser : Form
  {
    ChromiumWebBrowser _ChromiumWebBrowser;

    public Browser()
    {
      InitializeComponent();
    }

    private void Browser_Load( object sender, EventArgs e )
    {
      _ChromiumWebBrowser = new ChromiumWebBrowser("http://www.google.com");
      //_ChromiumWebBrowser.PropertyChanged += OnPropertyChanged; // += new PropertyChangedEventHandler( _ChromiumWebBrowser_PropertyChanged );
      _ChromiumWebBrowser.Dock = DockStyle.Fill;
      this.Controls.Add( _ChromiumWebBrowser );
    }

 

 

 

 

Having dug around in the CefSharp github seems like it should work.

 

I've attached my zip, I got to the stage of just copy pasting everything across to the addins\RvtChrome folder incase I had missed anything in the post build commands!  The files required seem to have changed a bit from the original? The built files were too big to attach, but I've uploaded a screenshot.

 

Any hints would be gratefully received, I am very inexperienced with this!

 

Mark

 

P.S.  DotNetBrowser doesn't seem to have an OS free option any more

 

 

0 Likes