1

I'm working on an IronPython script for Revit 2016. For starters, I'm trying to access values (as text) in an active Revit schedule, and load them into a variable. This works well enough for non-calculated values.

However, some of my schedule fields are calculated. Here's a sample schedule (all values here are calculated):

Schedule Snippet

The Revit API shows 2 methods, called TableView.GetCalculatedValueName()and TableView.GetCalculatedValueText(), which I'd like to use, but don't seem to work as advertised.

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)

Running this code (in Revit) produces the following output:

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

I'd like to point out that using TableView.GetCellText() actually works on calculated values, but it's the GetCalculatedValueName() that I'd really like to make work here.

Johnny B
  • 31
  • 5
  • Can you please provide a minimal reproducible case? Minimal Revit model with just a cell or two plus the embedded Python macro? c.f. http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b – Jeremy Tammik Sep 12 '16 at 06:50
  • Did you ever get this working? It was a while ago, but no answer has been accepted... – Callum Jul 02 '19 at 22:52

1 Answers1

0

I have done the same thing but in c# for Revit 2019. I hope you will understand it.

You can access the values of schedule data without exporting. Firstly, get all the schedules and read the data cell by cell. Secondly, create dictionary and store data in form of key, value pairs. Now you can use the schedule data as you want. I have tried this in Revit 2019. Here is the implementation.

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);
}
Mah Noor
  • 83
  • 1
  • 11