Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Schedule Grand Totals and GetCellCalculatedValue

2 REPLIES 2
Reply
Message 1 of 3
esatis
128 Views, 2 Replies

Get Schedule Grand Totals and GetCellCalculatedValue

Hi, 

I am trying to gather Grand Totals from multiple Schedules for Calculated Fields.

Revit natively does not support multi-category schedule where I could aggregate for example cost for different values. For example Cost per piece, Cost per meter, Cost per square meter etc. So I have multiple schedules and then I am trying to get Grand totals for each of these schedules.

The Column is Calculated Field with Type: Currency, set to "Calculate Totals".
The Field is also Formatted in Schedule to use Unit symbol 123€.

 

I can get string value of the Grand Total like this:

 

TableData tableData = schedule.GetTableData();
TableSectionData tableSection = tableData.GetSectionData(SectionType.Body);
string cellText = schedule.GetCellText(SectionType.Body, tableSection.LastRowNumber, tableSection.LastColumnNumber);

 

But with this there are few problems:

1) It's hard to Parse the string to add multiple int of multiple schedules. If the User Formats the Field with different Prefix/Suffix there might be problems.

2) If the Grand Total Column is not the last column, it won't read the value. (ok, I can set instructions, but it is still very constrained)

 

To tackle first problem, I try to use 

 

TableCellCalculatedValueData tableCellCalculatedValueData = tableSection.GetCellCalculatedValue(rowIndex, columnIndex);

 

But this just returns Null for every cell - although I clearly have Calculated Fields. And even if it returned value, the TableCellCalculatedValueData is nonsense Type with no value Properties.

 

So the questions are -

1) Is there a way to get Grand Totals for schedules as values?
2) how to get Calculated Cell Value without formatting? 

 

p.s. I have read the https://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html

 

edit: After iterating through all cells to get: CellType cellType = tableSection.GetCellType(rowIndex, columnIndex);

it seems like the Grand Total is CellType .Text. But the same Column Cell with value is CellType.ParameterText (Read only parameter which only show formatted string)

2 REPLIES 2
Message 2 of 3
jeremy_tammik
in reply to: esatis

Not being a Revit power end-user, my approach would be to just grab the data that you can get, regardless of formatting, suffixes, and other junk, and then deal with that as it comes. For me, handling the string formatting and parsing sounds like a simpler task than trying to coerce Revit to do the job for you. I will happily hear what the power users can suggest to further simplify things for you, though.

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 3 of 3
esatis
in reply to: jeremy_tammik

This is what I come up so far. It works, but it does not fix the issue that Grand Total should be the last Column.

public double ExtractGrandTotal(ViewSchedule schedule)
{
	ScheduleDefinition scheduleDefinition = schedule.Definition;
	if (!scheduleDefinition.ShowGrandTotal)
	{
		return 0.0;
	}

	TableData tableData = schedule.GetTableData();
	TableSectionData bodySection = tableData.GetSectionData(SectionType.Body);
	if (bodySection == null)
	{
		return 0.0;
	}

	return TryGetGrandTotalFromLastCell(schedule, bodySection);
}

private double TryGetGrandTotalFromLastCell(ViewSchedule schedule, TableSectionData bodySection)
{
	int lastRowNumber = bodySection.LastRowNumber;
	int lastColumnNumber = bodySection.LastColumnNumber;

	string cellText = schedule.GetCellText(SectionType.Body, lastRowNumber, lastColumnNumber);
	ForgeTypeId cellSpec = bodySection.GetCellSpec(lastRowNumber, lastColumnNumber);

	if (IsCellValidForParsing(cellSpec))
	{
		Units documentUnits = _document.GetUnits();
		Debug.WriteLine($"Trying to parse string: {cellText}");

		if (UnitFormatUtils.TryParse(documentUnits, cellSpec, cellText, out double grandTotal))
		{
			Debug.WriteLine($"Parsed value: {grandTotal}");
			return grandTotal;
		}
	}

	return 0.0;
}

private bool IsCellValidForParsing(ForgeTypeId cellSpec)
{
	return cellSpec != null && !string.IsNullOrEmpty(cellSpec.TypeId) && UnitUtils.IsMeasurableSpec(cellSpec);
}

Indeed it would be great to hear from Revit power end-users.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community