首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在网格视图中显示计划的内容,而不导出计划

在网格视图中显示计划的内容,而不导出计划
EN

Stack Overflow用户
提问于 2018-04-03 21:40:45
回答 2查看 384关注 0票数 1

问题如下:

我正在做我的项目,现在我想自动将时间表上传到我的数据库中,而不需要导出我的时间表。用户只需选择时间表,其中的数据应该被上传。

我已经能够将数据从网格视图/数据表上传到我的数据库。现在,我所需要的是一种将数据从计划获取到网格视图/数据表中的方法

有谁知道我是怎么做到的吗?api文档没有太多帮助(我正在使用C#和revit 2018.2)

谢谢您:)

EN

回答 2

Stack Overflow用户

发布于 2019-04-10 18:57:38

可以,您可以轻松访问计划数据,而无需导出。首先,获取所有的时间表并逐个单元地读取数据。其次,创建字典并以键、值对的形式存储数据。现在,您可以根据需要使用明细表数据。我已经在Revit 2019中尝试过了。

下面是实现

代码语言:javascript
运行
复制
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);
}
票数 2
EN

Stack Overflow用户

发布于 2018-04-04 16:30:08

The Building Coder完整地回答了这个问题,并描述了如何使用Schedule API to access schedule data

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49631637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档