Message 1 of 5
Retrive In-Place Mass Reference Level

Not applicable
02-22-2016
08:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone.
I'm working with in place masses to make functional diagrams in which each mass represents a room.
But to do this I need to get 2 parameters that we can't retrieve from in place Masses by default. Floor Area and Reference Plane.
To do this I'm creating an updater that works in two steps:
1- gets the floor area applying a floor for each mass at the right level.
2- Set the level name to a new shared Parameter in the document.
The problems are:
1- First time I edit a mass it gives me an error message, but if I copy and paste one element it works properly.
2- I can't set information to any parameter.
Here by the code, sorry if it is not clean, I'm just starting with programming.
public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application) { // Register wall updater with Revit MassUpdater updater = new MassUpdater(application.ActiveAddInId); UpdaterRegistry.RegisterUpdater(updater); // Change Scope = any Part element ElementCategoryFilter filterMass = new ElementCategoryFilter(BuiltInCategory.OST_Mass); // Add Trigger UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filterMass, Element.GetChangeTypeElementAddition()); UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filterMass, Element.GetChangeTypeGeometry()); return Result.Succeeded; } public Result OnShutdown(Autodesk.Revit.UI.UIControlledApplication application) { MassUpdater updater = new MassUpdater(application.ActiveAddInId); UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId()); return Result.Succeeded; } } public class MassUpdater : IUpdater { static AddInId m_appId; static UpdaterId m_updaterId; // constructor takes the AddInId for the add-in associated with this updater public MassUpdater(AddInId id) { m_appId = id; m_updaterId = new UpdaterId(m_appId, new Guid("C40D8B95-7897-4ED4-A57F-EC53FDC1DFCB")); } public void Execute(UpdaterData data) { Document doc = data.GetDocument(); // Get level ID FilteredElementCollector lvlCollector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels); ElementId lvlId = null; string lvlName = ""; List<ElementId> listElId = new List<ElementId>(); //Get Masses in model FilteredElementCollector docCollector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Mass); //Filter selection by type Name foreach (Element massPieces in docCollector) { ElementId typeId = massPieces.GetTypeId(); Element type = doc.GetElement(typeId); string typeName = type.Name; if (typeName == "Room") { foreach (Element el in docCollector) { listElId.Add(el.Id); } //Select only valid Masses ( I don't Know why but for each mass in place revit gives me 2 ID here I select only the even Elements var evenCategories = listElId.Where((c, i) => i % 2 != 0); List<ElementId> filter = new List<ElementId>(evenCategories); foreach (ElementId mass in filter) { //Get Mass Position Element piece = doc.GetElement(mass); Parameter PPlevel = piece.LookupParameter("LEVEL"); BoundingBoxXYZ bounding = piece.get_BoundingBox(null); XYZ point = bounding.Min; double elLvl = point.Z; foreach (Element l in lvlCollector) { Level lvl = l as Level; MassInstanceUtils.RemoveMassLevelDataFromMassInstance(doc, mass, lvl.Id); if (lvl.Elevation == elLvl) { lvlId = lvl.Id; lvlName = lvl.Name; MassInstanceUtils.AddMassLevelDataToMassInstance(doc, mass, lvlId); string name = lvlName.ToString(); PPlevel.Set(name); } } } } } } public string GetAdditionalInformation() { return "Mass area updater example: updates all Masses' area"; } public ChangePriority GetChangePriority() { return ChangePriority.Masses; } public UpdaterId GetUpdaterId() { return m_updaterId; } public string GetUpdaterName() { return "Mass Area Updater"; }