c# - 如何使用 C# 将过滤后的数据从 Autodesk Revit 导出到 MS-Access?
问题描述
我需要使用 C# 编程将一些族类型的参数从 Revit 文档导出到 ms-access。
我用谷歌搜索并阅读了几页,并观看了几个视频。然后我写了下面的代码。但它不起作用。(我还检查了所有设置以连接 Revit API)有人可以帮我吗?
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System.Data.OleDb;
namespace MyRevitCommands
{
[TransactionAttribute(TransactionMode.ReadOnly)]
public class GetWindows : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements, params string[] parameters)
{
//Get Document
Document oDoc = commandData.Application.ActiveUIDocument.Document;
//Get UIDocument
UIDocument uidoc = new UIDocument(oDoc);
//Create Filtered Element Collector
FilteredElementCollector WinCollector = new FilteredElementCollector(oDoc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Windows);
//Create Filter
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
IList<Element> windows = WinCollector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
TaskDialog.Show("Windows", string.Format("{0} windows counted!", windows.Count));
private Document oDoc;
// parameters for database connection
private OleDbConnection myAccessConn;
private string connectionString;
private OleDbDataAdapter Adapter;
public DataSet myDataset = new DataSet();
private ModelItemCollection MySearchResult = new ModelItemCollection();
{
oDoc = Document;
MySearchResult = oDoc.CurrentSelection.SelectedItems;
DataTable Mydatatable = new DataTable();
DataRow MyDataRow;
try
{
connectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;" + ("Data Source=" + "D:\\Data.accdb"));
myAccessConn = new OleDbConnection(connectionString);
myAccessConn.Open();
Adapter = new OleDbDataAdapter("SELECT * FROM Windows;", myAccessConn);
Adapter.Fill(myDataset, "Windows");
Mydatatable = myDataset.Tables["Windows"];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString);
}
int counter = 0;
string str;
DataProperty classproperty;
Mydatatable.Clear();
foreach (Element e in WinCollector)
{
counter=counter+1
MyDataRow = Mydatatable.NewRow;
}
return Result.Succeeded;
}
}
}
}
解决方案
我猜你把数据放在这个 foreach 里面
foreach (Element e in WinCollector)
{
//Get the value from the parameter
string paramValue = e.LookupParameter("parameter_name").AsValueString();
counter=counter+1
MyDataRow = Mydatatable.NewRow;
//Set the value in the data table
MyDataRow["some_col"] = paramValue;
}
有关 revit API 的更多信息,请查看此链接。
推荐阅读
- date - 提供唯一时间戳以重命名批量文件的批处理脚本
- android-studio - GradleException:Crashlytics 无法确定已剥离/未剥离的本机库目录
- javascript - Javascript - 枚举对象中的键、值对并转换与 ISO 时间戳格式匹配的键、值对
- node.js - TypeError:要求确认时无法读取未定义的属性“内容”
- reactjs - 如何在父 setState 上停止子组件重置
- powershell - 通过 P/S 设置 NTFS 权限并获取 Canonical Form 错误
- typescript - Webpack 5 SplitChunksPlugin 不生成块文件
- r - 将字符串的 MD5 和与文件的内容进行比较
- angular - 检测在 iframe 中运行的 Angular 应用程序外部的点击
- php - 使用 PHP SDK,我如何在创建信封时替换我的模板基础文档?