-1

Currently, Whenever I launch revit to test my addin that is supposed to export the contents of ViewSchedules in a revit document to txt format. I suspect something is wrong with my project references, however I am linking RevitAPI and RevitUIAPI.

Below is the code for the addin:

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.IO;
using static System.Net.Mime.MediaTypeNames;

namespace RevitExportImportSchedule
{
    [TransactionAttribute(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {
        public string Export(Document doc, string export_folder_name, string extension)
        {
            FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule));

            ViewScheduleExportOptions opt = new ViewScheduleExportOptions();
            var output = "Exported Files:\n";
            try
            {
                foreach (ViewSchedule vs in col)
                {
                    Directory.CreateDirectory(export_folder_name);

                    vs.Export(export_folder_name, vs.Name + "_Schedule" + extension, opt);
                    output += export_folder_name + vs.Name + "_Schedule" + extension + "\n";
                }
                return output;
            }
            catch(Exception e)
            {
                output += e;
                return output;
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var export_folder = "C:\\Users\\BEN.DENNISON\\Documents\\revit_open_auto";
            var extension = ".txt";
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            var output = Export(doc, export_folder, extension);
            
            TaskDialog.Show("Export", output);
            return Result.Succeeded;
        }
    }
}`

Here is my .addin:

<RevitAddIns>   

<AddIn Type="Command">     

<Name>RevitImportExport</Name>    

<FullClassName>RevitExportImportSchedule.Class1</FullClassName>  

<Text>Import/Export</Text>     

<Description>Exports/Imports all Schedules present in a revit project</Description>     <VisibilityMode>AlwaysVisible</VisibilityMode>     

<Assembly>      C:\Users\BEN.DENNISON\source\repos\RevitScheduleImportExport\RevitScheduleImportExport\bin\Debug\net7.0\RevitScheduleImportExport.dll   

</Assembly>     

<AddInId>239BD853-36E4-461f-9171-C5ACEDA4E723</AddInId>     

<VendorId>COMPANY</VendorId>     

<VendorDescription>COMPANY</VendorDescription>   

</AddIn> 

</RevitAddIns> 

I am using visual studio 2022

I have tried commenting out the export function to no avail which indicated to me it is a problem with how I am building it.

  • 1
    (a) Why do you have the `using static System.Net.Mime.MediaTypeNames` in there? I have never seen that usage, and doubt that you really need it. (b) Can you successfully implement, load and execute a naked skeleton add-in? – Jeremy Tammik Jul 14 '23 at 09:24
  • Didn't mean to include it. I am able to implement this add-in as when I comment out Directory, it runs fine. I am running into the same issue when trying to just initialize a new list: 'List lines = new List();', I get the same PublicKeyToken, as well as the error: 'Could not load file or assembly System.Collections Version 7.0.0.0'. Since its the same style of error, I assume it is a result of the same issue. My currect guess is something with Revit's interaction with mscorlib.dll since all the errors result from System – Ben Dennison Jul 14 '23 at 13:28
  • Please be precise asking a question. Otherwise, it becomes difficult or impossible to answer. Precision includes removing all unnecessary junk. Furthermore, in your question title, you say version `4.0.0.0`. In your comment, you say version `7.0.0.0`. – Jeremy Tammik Jul 15 '23 at 16:57
  • Gotcha. Sorry about that. The main issue is whenever I use any class from the system namespace, I get an error that contains a different .NET version. In the original example, I get an error when using the 'Directory' object from 'System.IO.Directory' which gives me the 'System.Runtime = 4.0.0.0'. When I initialize a 'List' from 'System.Collection.Generic', I get the 'System.Runtime =7.0.0.0' error. I am currently using .NET 4.8 – Ben Dennison Jul 16 '23 at 19:38

2 Answers2

1

It sounds to me as if you may be violating the Revit API basic system requirements:

The Autodesk Revit API requires the Microsoft .NET Framework 4.8.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
0

Jeremy was correct here. You need to edit the .csproj file and modify your targeted framework. It won't work if you just select it in Application: General in Visual Studio. Check out this link from Microsoft if you need to modify your targeted framework.