How to use the Revit 2023 API in a WPF solution (.NET Framework 4.8)

How to use the Revit 2023 API in a WPF solution (.NET Framework 4.8)

Enzo_MAZZONEPGPQ5
Observer Observer
983 Views
4 Replies
Message 1 of 5

How to use the Revit 2023 API in a WPF solution (.NET Framework 4.8)

Enzo_MAZZONEPGPQ5
Observer
Observer

Hello,

 

I recently started using the Revit API.

 

I've already been able to carry out a first plug-in test using a "Class Library" project.

 

I'm developing a WPF application that interfaces with several software packages. I'm trying to connect it to Revit via the API, but I'm facing a number of problems.

 

To carry out my tests, I start from a blank application.

I add the references "AdWindows/RevitAPI/RevitAPIUI/UIFramework" from "C:\Program FilesAutodesk\Revit 2023".

In my project properties I uncheck the "Prefer 32-bit" option.


I add my manifesr.addin :

 

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
    <AddIn Type="Command">
      <Name>Nom de l'app</Name>
      <FullClassName>TEST_WPF_REVIT.Class1</FullClassName>
      <Text>ExtractConcreteData</Text>
      <Description>Description du plug-in</Description>
      <VisibilityMode>AlwaysVisible</VisibilityMode>
      <Assembly>TEST_WPF_REVIT.dll</Assembly>
      <AddInId>E3694029-EF96-45E2-B5A6-36D3C1B810FB</AddInId>
      <VendorId>ADSK</VendorId>
      <VendorDescription>Autodesk, Inc, www.autodesk.com</VendorDescription>
   </AddIn>
</RevitAddIns>

 

 

 

I add a class to my project and name it "Class1.cs":

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Numerics;

namespace TEST_WPF_REVIT
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    class Class1 : IExternalCommand
    {
       public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
       {
             UIApplication uiapp = commandData.Application;
             UIDocument uidoc = uiapp.ActiveUIDocument;
             Autodesk.Revit.DB.Document doc = uidoc.Document;
             return Result.Succeeded;

       }
    }
}

 


I call this class in MainWindow.cs :

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Autodesk.Revit.DB;
namespace asuppp
{

    public partial class MainWindow : Window
    {
          public MainWindow()
          {
                InitializeComponent();
                Class1 test = new Class1();
                Close();
          }
    }
}

 

When I run my code, I get the following error:

 

FileNotFoundException : Unable to load file or assembly 'RevitAPIUI, Version=23.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The specified file cannot be found.

 

 

Would you have a solution to my problem please ?

 

I thank you in advance and I apologize if I have not respected some rules of the forum do not hesitate to tell me so I can improve me in the future.

0 Likes
984 Views
4 Replies
Replies (4)
Message 2 of 5

studio-a-int
Advocate
Advocate

Your solution is missing RevitAPIUI.dll

Under References, right click "Add Reference" navigate to your local and load the missing library.

Typically they are located:

C:\Program Files\Autodesk\Revit 20xx\RevitAPIUI.dll

After is loaded, chose "Copy Local" = "False"

0 Likes
Message 3 of 5

ricaun
Advisor
Advisor

I suppose that you created a new solution for WPF, and you are trying to run Revit API outside Revit.

 

If that's the case, the only place you are allowed to run Revit API is inside Revit, you could add the other missing reference but your MainWindow fails anyway.

 

PS: You could edit your post and add your code inside a CodeBlock, which usually is nicer to visualize in the forum.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 4 of 5

Enzo_MAZZONEPGPQ5
Observer
Observer

Thank you very much for your reply.

Sorry I forgot to mention the RevitAPIUI dll which is present in my solution with CopoyLocal = "False".

0 Likes
Message 5 of 5

Enzo_MAZZONEPGPQ5
Observer
Observer

Thank you very much for your reply.

 

I think last night I wasn't clear enough about what I'm trying to do.

I have a parent application that acts outside Revit and would have a button to connect to it as follows:
Click on the button, I itnitalize an instance of my class that uses Revit's API.
I display a box message so that the user can go to revit and run the plug-in to create an instance of the model in "Doc".
The user clicks on the messagebox to continue the code that will use revit's API from the Document retrieval.

Don't hesitate to let me know if it doesn't work.

I've already thought of another solution, which is to create a separate plug-in that, when run, uses the Revit API to retrieve the data I need and serializes the results in an XML file that I then retrieve with my WPF application.

We also go from "Clic App/Clic Revit/Clip App" to "Clic Revit/Clic App".

0 Likes