问题如下:
我正在做我的项目,现在我想自动将时间表上传到我的数据库中,而不需要导出我的时间表。用户只需选择时间表,其中的数据应该被上传。
我已经能够将数据从网格视图/数据表上传到我的数据库。现在,我所需要的是一种将数据从计划获取到网格视图/数据表中的方法
有谁知道我是怎么做到的吗?api文档没有太多帮助(我正在使用C#和revit 2018.2)
谢谢您:)
发布于 2019-04-10 18:57:38
可以,您可以轻松访问计划数据,而无需导出。首先,获取所有的时间表并逐个单元地读取数据。其次,创建字典并以键、值对的形式存储数据。现在,您可以根据需要使用明细表数据。我已经在Revit 2019中尝试过了。
下面是实现
public void getScheduleData(Document doc)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> collection = collector.OfClass(typeof(ViewSchedule)).ToElements();
String prompt = "ScheduleData :";
prompt += Environment.NewLine;
foreach (Element e in collection)
{
ViewSchedule viewSchedule = e as ViewSchedule;
TableData table = viewSchedule.GetTableData();
TableSectionData section = table.GetSectionData(SectionType.Body);
int nRows = section.NumberOfRows;
int nColumns = section.NumberOfColumns;
if (nRows > 1)
{
//valueData.Add(viewSchedule.Name);
List<List<string>> scheduleData = new List<List<string>>();
for (int i = 0; i < nRows; i++)
{
List<string> rowData = new List<string>();
for (int j = 0; j < nColumns; j++)
{
rowData.Add(viewSchedule.GetCellText(SectionType.Body, i, j));
}
scheduleData.Add(rowData);
}
List<string> columnData = scheduleData[0];
scheduleData.RemoveAt(0);
DataMapping(columnData, scheduleData);
}
}
}
public static void DataMapping(List<string> keyData, List<List<string>>valueData)
{
List<Dictionary<string, string>> items= new List<Dictionary<string, string>>();
string prompt = "Key/Value";
prompt += Environment.NewLine;
foreach (List<string> list in valueData)
{
for (int key=0, value =0 ; key< keyData.Count && value< list.Count; key++,value++)
{
Dictionary<string, string> newItem = new Dictionary<string, string>();
string k = keyData[key];
string v = list[value];
newItem.Add(k, v);
items.Add(newItem);
}
}
foreach (Dictionary<string, string> item in items)
{
foreach (KeyValuePair<string, string> kvp in item)
{
prompt += "Key: " + kvp.Key + ",Value: " + kvp.Value;
prompt += Environment.NewLine;
}
}
Autodesk.Revit.UI.TaskDialog.Show("Revit", prompt);
}
发布于 2018-04-04 16:30:08
The Building Coder完整地回答了这个问题,并描述了如何使用Schedule API to access schedule data。
https://stackoverflow.com/questions/49631637
复制相似问题