Quick way of counting rows in a schedule?

Quick way of counting rows in a schedule?

daniel
Enthusiast Enthusiast
12,268 Views
9 Replies
Message 1 of 10

Quick way of counting rows in a schedule?

daniel
Enthusiast
Enthusiast

HI, 

I was trying to get hold of the number of elements visible in a schedule. 

First I thought that I just could check if a spesific element was visible in the spesific schedule, but that turnd out not work, due to 

"non view spesific" behavior of som elements. 

 

Does anyone have a tip on how to do this? 

 

I really want the schedule api to expose a counter of some kind, but until that happens, some workaround needs to be found ? 

 

Any tips ? 

 

Daniel 

0 Likes
Accepted solutions (2)
12,269 Views
9 Replies
Replies (9)
Message 2 of 10

Revitalizer
Advisor
Advisor
Accepted solution

Hi daniel,

 

as far as I know, there is no way to get the ElementId of a schedule's row.

 

There is an ugly workaround:

Add a new schedule field containing a newly added parameter.

Fill that parameter with the ElementId's value.

 

Now you have the row/element relation which can be used to count displayed elements.

 

After doing so, rollback your transaction.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 10

arnostlobel
Alumni
Alumni
Accepted solution

If all you want is the number of rows in a shcedule, why don't you use the TableData?

 

TableData table = schedule.GetTableData();
Assert.IsNotNull(table);

TableSectionData section = table.GetSectionData(SectionType.Body);
Assert.IsNotNull(section);

in nRows = section.NumberOfRows;
// note: the rows include the first blank one, if there is any
Arnošt Löbel
Message 4 of 10

Revitalizer
Advisor
Advisor

Hi Arnost,

 

of course you are right.

I thought that daniel wanted the element relation, too.

 

 

Have a nice weekend,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 10

daniel
Enthusiast
Enthusiast

tnx.. 

 

Both solutions is needed I guess.. Am going to Count number of rows, and then get the value of the n^th element to make a new filer and create a duplicate schedule so that it fits a spesific sheet. 

 

I think this is a major missing feature in Revit, the ability to easy print a schedule over multiple sheets.. 

 

 

Message 6 of 10

CJModis
Advocate
Advocate

What to do in case if IsItemized = False?

0 Likes
Message 7 of 10

Revitalizer
Advisor
Advisor

Hi,

 

that's  a good question (and I wonder why nobody asked it before).

I think the relation (element->row) is lost in that case.

One could get the parameter values in the desired row and get the matching elements by parameter comparison.

 

As there may be formula fields in a row, it needs to be tested if one can reproduce an element's proposed value by getting the List of TableCellCombinedParameterData from a given cell,

IList<TableCellCombinedParameterData> TableSectionData.GetCellCombinedParameters(int nRow,int nCol)

 

Not tested, yet.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 8 of 10

FAIR59
Advisor
Advisor

You can find all the elements in a schedule using a FilteredElementCollector(document, scheduleview.Id).

Delete a row from the schedule in a temporary transaction and compare the elements before and after to determine the Elements on a row in the schedule.

 

public void CountScheduleEntriesOnRow()
 {
   StringBuilder sb = new StringBuilder();
   Document doc = this.ActiveUIDocument.Document;
   ViewSchedule view = doc.ActiveView as ViewSchedule;
   if (view==null) return;
   TableData table =  view.GetTableData();
   TableSectionData section = table.GetSectionData(SectionType.Body);

   List<ElementId> elems = new FilteredElementCollector(doc,view.Id)
        	.ToElementIds()
        	.ToList();
   List<Element> ElementsOnRow = new List<Element>();
   List<ElementId> Remaining = null;
   int RowToAnalyse = 2;

   using(Transaction t = new Transaction(doc,"dummy"))
	{
		t.Start();
		using (SubTransaction st = new SubTransaction(doc))
		{
			st.Start();
			section.RemoveRow(RowToAnalyse);
			st.Commit();
		}
		Remaining = new FilteredElementCollector(doc,view.Id)
			.ToElementIds()
			.ToList();
		t.RollBack();
	}
   foreach(ElementId id in elems)
   {
      	if(Remaining.Contains(id)) continue;
       	ElementsOnRow.Add(doc.GetElement(id));
   }
   sb.AppendLine(string.Format("{0} elements on row {1}",ElementsOnRow.Count,RowToAnalyse));
   foreach(Element e in ElementsOnRow)
   {
      	sb.AppendLine(string.Format("<{0}> {1} {2}",e.Id,e.Name, e.GetType()));
   }
   TaskDialog.Show("debug",sb.ToString());
}
Message 9 of 10

Bishesh.M
Contributor
Contributor

I have a very quick non-traditional solution to this. This is for those people who just want to count the number of rows just to find the number of items. Not for extracting the numbers or Ids for programming.

 

  1. Go to your schedule. (I'm using a space schedule for this example.)
  2. Select cells from any columns of all the rows that you want counted. (Click and drag)
  3. Right click on one of the cells and select "Delete Row"(You're not actually deleting them) from drop down menu. Then a dialog box appears that says "This will delete 32 selected spaces and any associated space tags". (There's your number of rows.) Make sure you hit cancel so you don't actually delete them. Or in case you did click "Ok" you can always undo it.

 

Like I said, it's not an ideal solution. But its quick and doesn't require you to follow lots of extra steps.

Message 10 of 10

Anonymous
Not applicable

Hi 

The proposed technique byFAIR59 is not applicable for Material Takeoff schedules.

Does anybody have any other suggestions?

 https://forums.autodesk.com/t5/revit-api-forum/quick-way-of-counting-rows-in-a-schedule/td-p/5800112