Error in REVITAPIUI version

Error in REVITAPIUI version

ecjnfp
Explorer Explorer
706 Views
3 Replies
Message 1 of 4

Error in REVITAPIUI version

ecjnfp
Explorer
Explorer

Hello, I have the following WPF application that selects the pipes in a Revit project.

 

 

<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Content="Button" Click="OpenModelButton_Click"/>
        <Button Content="Button" Click="SelectPipesButton_Click"/>
    </Grid>
</Window>
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection.Metadata;
using System.Transactions;
using System.Windows;
using System.Xml.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace WpfApp2
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class MyExternalCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            Reference pickedObj = uidoc.Selection.PickObject(ObjectType.Element, "Select element");
            ElementId id = pickedObj.ElementId;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("IdentifyTrechoTransaction");
                if (pickedObj != null)
                {
                    Element element = doc.GetElement(id);
                    Parameter trechoParameter = element.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
                    trechoParameter.Set("Funcionouuuuuuu");
                }
                tx.Commit();
            }

            return Result.Succeeded;
        }
    }

    public partial class MainWindow : Window
    {
        private const string RevitPath = @"C:\Program Files\Autodesk\Revit 2024\Revit.exe";
        private const string ModelPath = @"D:\Revit Arquivos\Modelo Hidrante 2024.rvt";

        public MainWindow()
        {
            InitializeComponent();
        }

        private void OpenModelButton_Click(object sender, RoutedEventArgs e)
        {
            if (File.Exists(RevitPath))
            {
                if (File.Exists(ModelPath))
                {
                    Process.Start(RevitPath, $"\"{ModelPath}\"");
                }
                else
                {
                    MessageBox.Show("Arquivo do modelo não encontrado.");
                }
            }
            else
            {
                MessageBox.Show("Caminho do Revit inválido.");
            }
        }

        private void SelectPipesButton_Click(object sender, RoutedEventArgs e)
        {
            MyExternalCommand externalCommand = new MyExternalCommand();
            string message = string.Empty;
            ElementSet elements = new ElementSet();
            Result result = externalCommand.Execute(null, ref message, elements);
            if (result != Result.Succeeded)
            {
                MessageBox.Show("Erro ao executar o comando externo.");
            }
        }
    }
}

 

 

 

 

The above code is displaying the following error:

 

System.IO.FileNotFoundException: 'Could not load file or assembly 'RevitAPIUI, Version=24.0.0.0, Culture=neutral, PublicKeyToken=null'. O sistema não pode encontrar o arquivo especificado.'

 

I have revitapiui.dll version 24.0.4.427

 

Captura de tela 2023-05-11 185424.png

Captura de tela 2023-05-11 185557.png

How can I resolve this issue?

0 Likes
707 Views
3 Replies
  • WPF
Replies (3)
Message 2 of 4

ricaun
Advisor
Advisor

Usually, the Revit API Forum is in English, if you ask something in Portuguese probably gonna have a hard time getting help with your problem.

 

By looking at your code looks like you create a WPF Application project with net 6.0 maybe. Revit 2024 works in Net Framework 4.8 which is not compatible.


Probably Visual Studio is warning you that that was not possible to find the package for that version. If you look in the package: https://www.nuget.org/packages/Revit_All_Main_Versions_API_x64/2024.0.0#supportedframeworks-body-tab...

 

Second, what you trying you do is not possible. You can't start Revit.exe and run some code in that Revit process, is not possible to run Revit API outside Revit.

 

You need to create a Library NET Framework project: https://help.autodesk.com/view/RVT/2024/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Introduction_...

 

PS: You could edit your post and put your code inside the code sample block in the Forum, which makes easier to read.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 3 of 4

jeremy_tammik
Alumni
Alumni

Thanks to ricaun for the very complete and insightful answer!

  

I would also like to add the suggestion never to copy the Revit API .NET assemblies anywhere, unless you know very well what you are doing. When compiling and executing your add-in, it normally makes most sense to set the Copy Local flag on these to false:

  

  

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

ecjnfp
Explorer
Explorer
Thank you very much for the reply