Creating a C++ plugin

Creating a C++ plugin

ebarMLN7G
Enthusiast Enthusiast
8,278 Views
7 Replies
Message 1 of 8

Creating a C++ plugin

ebarMLN7G
Enthusiast
Enthusiast

I am trying to create a C++ revit plugin and the only source that I could have found is this old post from Jeremy:

 

https://thebuildingcoder.typepad.com/blog/2010/10/c-revit-add-in.html

 

I tried to follow the steps, but since it has been a while since that post was written had to change a few things:

 

1- The blog posts guides to create a Visual C++ Class Library project.  I couldn't find a class library option under Visual C++ in VS 2019. So I created a Visual C++ > Windows Desktop > Dynamic-Link Library (DLL) project. The structure seems pretty similar to yours, but I has to add the header file myself.

2- To add the dependencies (RevitAPI, and RevitAPIUI) I had to enable CLR Support in Project Properties.

3- I had to change the TransactionMode to manual/Readonly

Other than that it compiled with no problem. When executing the command from Revit, Revit just hangs and the mouse pointer turns into a spinner. That lasts for about 2 minutes and then it goes away. If I add a TaskDialog to see if anything gets executed, it seems like nothing gets executed. I am buiding the dll with x64 configuration and I tried both Release and Debug (I tried win32 and the generated DLL doesn't do anything)

I am not quite sure what I am doing wrong, any help is highly appreciated.

0 Likes
Accepted solutions (1)
8,279 Views
7 Replies
Replies (7)
Message 2 of 8

jeremytammik
Autodesk
Autodesk

Dear Ehsan,

 

Thank you for raising your query here as well as in your comment on The Building Coder:

 

https://thebuildingcoder.typepad.com/blog/2010/10/c-revit-add-in.html#comment-4252013168

 

For the sake of completeness and for other readers, let me reiterate what I explained to you there:

 

Sorry to hear that there is so little other information on this.

 

On the other hand, it is pretty straightforward, more or less as you describe.

 

You need CLR, yes, and you produce a 'managed' C++ DLL.

 

Your DLL can be 'mixed mode' as well, if you need both CLR and non-CLR functionality.

 

I don't know exactly what Visual Studio settings need to be defined, though.

 

Did you try running it from the Visual Studio debugger, or loading the DLL straight into Revit with no VS interaction?

 

I'll happily look into this further... however, it may take some time, maybe until next year.

 

Here is some C++ Revit add-in code working in Revit 2018:

 

https://thebuildingcoder.typepad.com/blog/2018/01/create-swept-blend-in-c.html

 

No full project included, though, so it does not say much about the settings used.

 

Here is a pointer to another one, Max Thumfart's sample using the C++ Boost library Voronoi implementation in a Revit add-in:

 

https://thebuildingcoder.typepad.com/blog/2017/06/finding-an-exit-path-and-elementid-parameter-value...

 

I hope this helps.

 

Please do share your final complete VS solution if you get it running for others to enjoy.

 

Thank you!

 

Best regards,

 

Jeremy

 



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

Message 3 of 8

jeremy_tammik
Alumni
Alumni
Accepted solution

Happy New Year!

 

Any luck yet your end?

  

I heard back from the development team, and they say: 

  

I was able to create a working C++ add-in project. Things to remember:

 

  • You need C++/CLI support. This is an optional install in VS2017 when installing C++.
  • You need to use 64-bit configuration.

 

That seemed to be it for the settings required.

 

The project was created as New Project -> Visual C++ -> CLR -> ClassLibrary.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 4 of 8

ebarMLN7G
Enthusiast
Enthusiast

Hi Jeremy,

 

Hope you enjoyed the holidays.  Thank you so much for following up on this. you saved me hours (if not days) of head scratching. I just got back from the holidays myself and gave your solution a shot. The problem appeared to be in the project type. My non-working project was created as: Visual C++ > Windows Desktop > Dynamic-Link Library (DLL). Using CLR ClassLibrary fixed the issue (New Project -> Visual C++ -> CLR -> ClassLibrary) fixed the issue

 

I will update this thread if I ran into any issue since the reason that I am creating a C++ plugin instead of C# is to use some unmanaged C++ libraries. 

 

Best,

Message 5 of 8

jeremytammik
Autodesk
Autodesk

Congratulations on solving this and thank you for sharing your solution.

 

I'll also add a link to your solution to the comment that you posted on The Building Coder:

 

https://thebuildingcoder.typepad.com/blog/2010/10/c-revit-add-in.html#comment-4386715790

 

Welcome to the Revit API!

 

Much success and have fun,

 

Jeremy

 



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

Message 6 of 8

jeroen.van.halderen
Advocate
Advocate

Hello everyone,

 

I'm trying to learn how to make a Revit plugin in C++, but whatever I try it just doesn't seem to work. I've looked at the buildingcoder sample (also the only sample for a C++ plugin I could find) but it only implements the Autodesk::Revit::UI::Command method so I'm know sure if it works. Could someone please provide a sample that also implements the TaskDialog::Show(string, string) method, that would make me very happy.

Thanks in advance!

0 Likes
Message 7 of 8

jeremy_tammik
Alumni
Alumni

Here is a sample using MessageBox::Show; that ought to be similar:

 

https://thebuildingcoder.typepad.com/blog/2011/05/iteration-and-springtime-change-is-the-only-consta...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 8

halukuzuner
Advocate
Advocate

Hi ebarMLN7G have you got any improvement on Revit api c++ coding. I am also workin on it. I have some difficulties. Do you have any knowledge about LINQ in managed c+cc?

0 Likes