首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过RevitPythonShell/IronPython访问活动Revit计划中的字段?

如何通过RevitPythonShell/IronPython访问活动Revit计划中的字段?
EN

Stack Overflow用户
提问于 2016-08-19 17:45:42
回答 1查看 1.4K关注 0票数 1

我正在为2016年版本编写一个IronPython脚本。首先,我试图访问active Revit计划中的值(作为文本),并将它们加载到变量中。对于未计算的值来说,这是非常有效的。

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

时间表片段

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

代码语言:javascript
复制
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中)将产生以下输出:

代码语言:javascript
复制
88-06134-01
Calculated Qty is: 
Calculated Value Name is: 

我想指出的是,使用TableView.GetCellText()实际上是对计算值起作用的,但这是我真正想在这里发挥作用的GetCalculatedValueName()

EN

回答 1

Stack Overflow用户

发布于 2019-04-23 10:58:00

我也做过同样的事情,但在c#为Revit2019。我希望你能理解。

您可以不导出就可以访问计划数据的值。首先,获取所有的计划,并逐个读取数据单元。其次,创建字典并以键、值对的形式存储数据。现在,您可以根据需要使用计划数据。我在2019年的Revit上试过这个。以下是实现。

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39044976

复制
相关文章

相似问题

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