1

我正在为 Revit 2016 编写 IronPython 脚本。对于初学者,我正在尝试访问活动 Revit 计划中的值(作为文本),并将它们加载到变量中。这对于非计算值来说足够好。

但是,我的一些计划字段计算出来的。这是一个示例时间表(此处的所有值都是计算的):

计划片段

Revit API 显示了 2 个方法,称为TableView.GetCalculatedValueName()and TableView.GetCalculatedValueText(),我想使用它们,但似乎不像宣传的那样工作。

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

schedule = doc.ActiveView
tableData = schedule.GetTableData()
print(tableData)

tableName = schedule.GetCellText(SectionType.Header,0,0)
qty = schedule.GetCalculatedValueText(SectionType.Body,4,1)
calcValName = schedule.GetCalculatedValueName(SectionType.Body,4,1)
print(tableName)
print("Calculated Qty is: " + qty)
print("Calculated Value Name is: " + calcValName)

运行此代码(在 Revit 中)会产生以下输出:

88-06134-01
Calculated Qty is: 
Calculated Value Name is: 

我想指出,使用TableView.GetCellText()实际适用于计算值,但这GetCalculatedValueName()是我真正想在这里工作的。

4

1 回答 1

0

我在 C# for Revit 2019 中做过同样的事情。希望你能理解。

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

public void getScheduleData(Document doc)
{
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    IList<Element> collection = collector.OfClass(typeof(ViewSchedule)).ToElements();

    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)
        {
            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);
}
于 2019-04-23T10:58:00.473 回答