Hello,
I've already created a stackoverflow question for this, but I figured I'd cross-post here. I'm using IronPython to create a basic script that accesses values in an active schedule, and having trouble using the TableView.GetCalculatedValueText() and TableView.GetCalculatedValueName() methods. I don't get errors, but when trying to access the values in calculated cells, the function seems to return '' (empty string). Oddly enough, TableView.GetCellText() does in fact work on these calculated cells, but what I'm really looking for is the NAME of the value.
Help would be appreciated!! Thanks!
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Dear Johny,
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
Thank you!
Cheers,
Jeremy
Hi Jeremy! Thanks for the response... the attached zip file has a .txt file with the revit python code, and a simple Revit file with a schedule that leverages calculated values.
Your help is much appreciated!
Thank you, I will take a look.
Meanwhile, have you seen this?
http://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html
Is that of any use to you?
Does that include the calculated values you are after?
Cheers,
Jeremy
SWEET! I'm actually doing something very similar to this for comparing schedules and BOMs (strictly in ironpython and winforms, though -- I can't quite code in .NET).
This really may come in handy down the line... thanks a ton.
Dear Johny,
Cool, glad you like it. Please let us know how you can make use of it.
Thank you for the sample code and model to run it in.
For the sake of completeness and legibility, here is your Python Code:
# IronPython Pad. Write code snippets here and F5 to run. doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument schedule = doc.ActiveView tableData = schedule.GetTableData() tableName = schedule.GetCellText(SectionType.Header,0,0) qty = schedule.GetCalculatedValueText(SectionType.Body,2,2) calcValName = schedule.GetCalculatedValueName(SectionType.Body,2,2) print(tableName) print("Calculated Qty is: " + qty) print("Calculated Value Name is: " + calcValName)
I created a C# add-in to test it in that environment.
My code looks like this after some debugging and one little addition:
UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; ViewSchedule schedule = doc.ActiveView as ViewSchedule; Result rc = Result.Failed; if(null == schedule) { message = "Please launch this command in a schedule view."; } else { TableData tableData = schedule.GetTableData(); //TableView tableView = null; int row = 2; int col = 2; string tableName = schedule.GetCellText( SectionType.Header, 0, 0 ); string qty = schedule.GetCalculatedValueText( SectionType.Body, row, col ); string calcValName = schedule.GetCalculatedValueName( SectionType.Body, row, col ); Debug.Print( tableName ); Debug.Print( "Calculated Qty is: " + qty ); Debug.Print( "Calculated Value Name is: " + calcValName ); Debug.Print( "Cell text " + schedule.GetCellText( SectionType.Body, row, col ) ); rc = Result.Succeeded; } return rc;
I have no idea what the purpose of GetCalculatedValueText and GetCalculatedValueName is.
However, if what you want is what you see in the schedule, the last call in my code to GetCellText returns exactly that:
MS-06362-01 Calculated Qty is: Calculated Value Name is: Cell text 19.177083
I am attaching my C# sample to this message in GetScheduleCalculatedValue.zip.
I hope this helps.
Ooops... I just noticed that you say GetCellText works, and you want the name... name of the value?! What is that? What is the name of a value?
Cheers,
Jeremy
Not to derail this thread, but have a tangential question. How can I get the "selected" cell in the schedule. I can use GetCalculatedValueText to get the text, but I can't figure out how to use the Selection to return where in the table (column and row numbers) it is selected.
When I use the Revit Selection object, it returns the actually FamilyInstance, and not the parameter that is selected, nor the table location (column and row number). How can I do this?
Hey Jeremy,
I assumed (perhaps incorrectly) that the GetCalculatedValueName method would return the value in the RED field below -- it also happens to be the first row in this schedule.
In other words, the "name" of the caclulated value is the text in the first row of the corresponding column...
Dear Johny,
In that case, meseems the simplest solution would be to query the value of the cell in the first row to retrieve the name with no further fuss.
Cheers,
Jeremy
Dear @Anonymous,
Sorry, I do not believe this is supported right now by the Revit API.
Cheers,
Jeremy
Hey Jeremy,
In fact, that's what I've wound up doing instead -- I mainly wanted to prepare for situations where the first row doesn't contain this property, or where the row is hidden, etc. -- and this method just seemed like a more robust solution. Part of me also just wanted to know what the purpose of these methods are if they don't do anything!
Thanks a ton for your help, and the link as well! I'm very new to this API (and programming in general), so every bit helps.
Johnny
Dear Johny,
Thank you for your appreciation.
My pleasure entirely.
Good luck and have fun with your further exploration of the Revit API!
Cheers,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.