Are rooms making it too slow to modify walls in your Revit model? An advanced Revit user recently contacted me to ask what could be done about it taking 10 seconds to move a wall because of Revit’s room calculations.
This demonstration shows how data about all rooms in the model can saved to file and the rooms deleted so that you can work without the room-associated performance penalty. Then when you want the rooms back, run the Import command to re-create the rooms based on the data that was saved to file.
The Revit API has two similar seeming versions of GetElement
- Document.GetElement Method (String)
- Document.GetElement Method (ElementId)
To use the string version, you must have a Element.UniqueId. This is not the same as the ElementID. The UniqueID is a hexadecimal GUID such as 4f2cb6f4-bd46-4877-8bd9-3dae7acfdfae-0002d7f3. Its usefulness is that it is stable across upgrades and workset operations such as Save To Central, while the ElementId property may change.
But what if you have an element ID stored as a string? Perhaps you read the ID as a string from a text file or the user entered the ID value in a text box of your user interface. As a human you would look at the number and see an integer. But if it is stored as a string in your code, then the computer will see a string and if you try to use it with GetElement then it will expect it to be a UniqueID GUID. You can’t use an element ID value as a string in Document.GetElement Method (String).
In this case, you will need to convert the id value from a string to an integer, use ElementId Constructor (Int32), and then use this element ID with GetElement. Here’s a bit of code showing how to do this conversion.
// Find the first wall in the project for testing
Element e = new FilteredElementCollector(doc).OfClass(typeof(Wall)).First();
string uniqueIDstring = e.UniqueId;
// a GUID such as 4f2cb6f4-bd46-4877-8bd9-3dae7acfdfae-0002d7f3
Element eFromString = doc.GetElement(uniqueIDstring);
string idFromString = e.Id.ToString();
// a string storing a value such as 186354
int idInt = Convert.ToInt32(idFromString);
ElementId id = new ElementId(idInt);
Element eFromId = doc.GetElement(id);
TaskDialog.Show("Elements", eFromString.Id + "\n" + eFromId.Id);
- Create toposurface from detail lines
- Create toposurface from curves in DWG import
- Update toposurface after line geometry changes
Get the install at the Boost Your BIM Revit API course at https://www.udemy.com/revitapi/?couponCode=149
Still debating if you should check out my great Revit API course at udemy.com?
Can’t wait to try the File Version Check tool that I wrote yesterday?
I’ve uploaded a special “sneak peek” installer for Revit 2013 and 2014 to the course at http://bit.ly/1dbiK5D. Please give it a try and let me know what you think.
Steve recently noted that “waiting for a Revit project to upgrade unnecessarily because I don’t know what version it was created in is a drag”. He mentioned two wishes:
“I’ve got a couple wishes. First I’d love it if Revit would store a value in the file properties that indicates Revit version. Second I’d love for Revit to ask first, “Do You WANT to UPGRADE? and a “NO, NOOOO, please on all things holy NOOOO” button.”
Sean rightfully suggested this would be a great opportunity for the Revit API to come to the rescue.
You know I love to grant a good wish!
Comments welcome as always… The install is available in my Revit API course at https://www.udemy.com/revitapi/?couponCode=149
I’ve had a great time speaking at two Revit Technology Conferences in 2013 and look forward to doing so again next year. The application deadline is December 16, and I’d love to know what format and content would interest you? A hands-on lab? A lecture? More technical or less technical?
Thanks for making Topo From Lines one of the Most Downloaded apps in the Revit App Store. Glad you like it!