skip to Main Content

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:UsersBEN.DENNISONsourcereposRevitScheduleImportExportRevitScheduleImportExportbinDebugnet7.0RevitScheduleImportExport.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.

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search