英文:
Getting the following 'Could not load type "System.IO.Directory" from assembly "System.Runtime, Version = 4.0.0.0"'
问题
目前,每当我启动 Revit 来测试我的插件,该插件应该将 Revit 文档中的 ViewSchedules 内容导出到 txt 格式时,我怀疑我的项目引用存在问题,但我已链接了 RevitAPI 和 RevitUIAPI。
以下是插件的代码:
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;
}
}
}
这是我的 .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>
我正在使用 Visual Studio 2022。
我已尝试注释掉导出函数,但未能解决问题,这表明问题可能出现在如何构建项目上。
英文:
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
得分: 1
这似乎是你可能违反了Revit API基本系统要求:
> Autodesk Revit API 需要 Microsoft .NET Framework 4.8。
英文:
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.
答案2
得分: 0
Jeremy在这里是正确的。您需要编辑.csproj
文件并修改您的目标框架。如果您只是在Visual Studio的Application: General
中选择它,那是行不通的。如果需要修改您的目标框架,请查看来自Microsoft的此链接。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论