private void CollectAreas() { try { progressForm = new Form_ProgressBar(); progressForm.LabelText = "Collecting Information from the Revit Project.."; progressForm.LabelCount = collectedAreas.Count + " areas found"; progressForm.Show(); progressForm.MaxValue = collectedAreas.Count; progressForm.Refresh(); foreach (Area area in collectedAreas) { progressForm.PerformStep(); AreaProperties ap = new AreaProperties(doc, area); if (!areaDictionary.ContainsKey(ap.ID) && !ap.CurveArrArray.IsEmpty) { areaDictionary.Add(ap.ID, ap); if (!areaTypeNames.Contains(ap.AreaType)) { areaTypeNames.Add(ap.AreaType); } } } } catch (Exception ex) { MessageBox.Show("Failed to collect Areas data. \n" + ex.Message, "Form_AreaMass:CollectAreas", MessageBoxButtons.OK, MessageBoxIcon.Warning); progressForm.Close(); } }
private void CollectFloors() { try { progressForm = new Form_ProgressBar(); progressForm.LabelText = "Collecting Information from the Revit Project.."; progressForm.LabelCount = collectedFloors.Count + " floors found"; progressForm.Show(); progressForm.MaxValue = collectedFloors.Count; progressForm.Refresh(); foreach (Floor floor in collectedFloors) { progressForm.PerformStep(); FloorProperties fp = new FloorProperties(doc, floor); if (!floorDictionary.ContainsKey(fp.ID)) { floorDictionary.Add(fp.ID, fp); if (!levelNames.Contains(fp.Level)) { levelNames.Add(fp.Level); } } } } catch (Exception ex) { progressForm.Close(); MessageBox.Show("Failed to collect Floors data. \n" + ex.Message, "Form_FloorMass:CollectFloors", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void CollectRooms() { try { progressForm = new Form_ProgressBar(); progressForm.LabelText = "Collecting Information from the Revit Project.."; progressForm.LabelCount = collectedRooms.Count + " rooms found"; progressForm.Show(); progressForm.MaxValue = collectedRooms.Count; progressForm.Refresh(); foreach (Room room in collectedRooms) { progressForm.PerformStep(); RoomProperties rp = new RoomProperties(doc, room); if (!roomDictionary.ContainsKey(rp.ID) && null != room.Location) { roomDictionary.Add(rp.ID, rp); if (!departmentNames.Contains(rp.Department)) { departmentNames.Add(rp.Department); } } } } catch (Exception ex) { MessageBox.Show("Failed to collect Rooms data. \n" + ex.Message, "Form_RoomMass:CollectRooms", MessageBoxButtons.OK, MessageBoxIcon.Warning); progressForm.Close(); } }
//find elements which intersect more than two mass elements. private void FindOverlaps() { try { if (elementDictionary.Count > 0) { progressForm = new Form_ProgressBar(); progressForm.Text = "Finding Overlapping Conditions"; progressForm.LabelText = "Finding elements intersecting with more than two mass elements..."; progressForm.LabelCount = elementDictionary.Count.ToString() + " elements found"; progressForm.MaxValue = elementDictionary.Count; progressForm.Show(); progressFormOpend = true; progressForm.Refresh(); } List <int> elementIds = elementDictionary.Keys.ToList(); foreach (int elementId in elementIds) { progressForm.PerformStep(); ElementProperties ep = elementDictionary[elementId]; if (ep.MassContainers.Count > 0) { Solid unionSolid = null; Options opt = m_app.Application.Create.NewGeometryOptions(); opt.ComputeReferences = true; opt.DetailLevel = Autodesk.Revit.DB.ViewDetailLevel.Fine; GeometryElement geomElement = ep.ElementObj.get_Geometry(new Options(opt)); geomElement = geomElement.GetTransformed(ep.TransformValue); foreach (GeometryObject obj in geomElement) { Solid solid = obj as Solid; if (null != solid) { if (solid.Volume > 0) { if (unionSolid == null) { unionSolid = solid; } else { try { unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(solid, unionSolid, BooleanOperationsType.Union); } catch { } } } } } ep.ElementSolid = unionSolid; Dictionary <int, double> overlapMap = new Dictionary <int, double>(); if (unionSolid != null) { if (unionSolid.Volume > 0) { foreach (int massId in ep.MassContainers.Keys) { Solid massSolid = ep.MassContainers[massId]; Solid intersectSolid = null; try { intersectSolid = BooleanOperationsUtils.ExecuteBooleanOperation(massSolid, unionSolid, BooleanOperationsType.Intersect); } catch { intersectSolid = null; } if (null != intersectSolid) { if (intersectSolid.Volume > 0) { double ratio = intersectSolid.Volume / unionSolid.Volume; if (!overlapMap.ContainsKey(massId)) { overlapMap.Add(massId, ratio); } } } } } } ep.OpverappingMaps = overlapMap; elementDictionary.Remove(ep.ElementId); elementDictionary.Add(ep.ElementId, ep); } } if (progressFormOpend) { progressForm.Close(); progressFormOpend = false; } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
private void CollectLinkedMass() { try { List <int> selectedMass = new List <int>(); foreach (TreeNode typeNode in treeViewLinkedFile.Nodes) { foreach (TreeNode instanceNode in typeNode.Nodes) { int instanceId = int.Parse(instanceNode.Name); bool massChecked = false; foreach (TreeNode massNode in instanceNode.Nodes) { if (massNode.Checked) { selectedMass.Add(int.Parse(massNode.Name)); massChecked = true; } } if (!massChecked) { linkedMassDictionary.Remove(instanceId); } } } if (selectedMass.Count > 0) { progressForm = new Form_ProgressBar(); progressForm.Text = "Finding Elements"; progressForm.LabelText = "Finding elements intersecting with 3D mass in linked files . . ."; progressForm.LabelCount = selectedMass.Count.ToString() + " mass found"; progressForm.MaxValue = selectedMass.Count; progressForm.Show(); progressFormOpend = true; progressForm.Refresh(); List <int> instanceIds = linkedMassDictionary.Keys.ToList(); foreach (int instanceId in instanceIds) { LinkedInstanceProperties lip = linkedMassDictionary[instanceId]; Dictionary <int, MassProperties> massDictionary = new Dictionary <int, MassProperties>(); foreach (Element massElement in lip.MassElements) { if (!selectedMass.Contains(massElement.Id.IntegerValue)) { continue; } progressForm.PerformStep(); MassProperties mp = new MassProperties(massElement); Solid unionSolid = null; Options opt = m_app.Application.Create.NewGeometryOptions(); opt.ComputeReferences = true; opt.DetailLevel = Autodesk.Revit.DB.ViewDetailLevel.Fine; GeometryElement geomElement = massElement.get_Geometry(new Options(opt)); if (null != lip.TransformValue) { geomElement = geomElement.GetTransformed(lip.TransformValue); } foreach (GeometryObject obj in geomElement) { Solid solid = obj as Solid; if (null != solid) { if (solid.Volume > 0) { if (unionSolid == null) { unionSolid = solid; } else { unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(unionSolid, solid, BooleanOperationsType.Union); } } } } mp.MassSolid = unionSolid; if (null != unionSolid) { if (unionSolid.Volume > 0) { mp.ElementContainer = FindElementsInMass(m_doc, mp.MassSolid, mp.MassId, false); List <Element> linkedElements = FindElementsInLInkedFiles(massElement, geomElement); mp.ElementContainer.AddRange(linkedElements); mp.ElementCount = mp.ElementContainer.Count; } } if (mp.MassParameters.Count > 0) { foreach (Parameter param in mp.MassParameters) { if (!massParameters.Contains(param.Definition.Name)) { massParameters.Add(param.Definition.Name); } } } mp.IsHost = false; mp.LInkedFileName = lip.FileName; if (!massDictionary.ContainsKey(mp.MassId)) { massDictionary.Add(mp.MassId, mp); } integratedMassList.Add(mp); } lip.MassContainers = massDictionary; linkedMassDictionary.Remove(instanceId); linkedMassDictionary.Add(instanceId, lip); } progressForm.Close(); progressFormOpend = false; } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
private void CollectHostMass(List <Element> massElements) { try { progressForm = new Form_ProgressBar(); if (massElements.Count > 0) { progressForm.Text = "Finding Elements"; progressForm.LabelText = "Finding elements intersecting with 3D mass in the host project . . ."; progressForm.LabelCount = massElements.Count.ToString() + " mass found"; progressForm.MaxValue = massElements.Count; progressForm.Show(); progressFormOpend = true; progressForm.Refresh(); } foreach (Element element in massElements) { progressForm.PerformStep(); MassProperties mp = new MassProperties(element); mp.WorksetId = element.WorksetId.IntegerValue; //from host project Solid unionSolid = null; Options opt = m_app.Application.Create.NewGeometryOptions(); opt.ComputeReferences = true; opt.DetailLevel = Autodesk.Revit.DB.ViewDetailLevel.Fine; GeometryElement geomElement = element.get_Geometry(new Options(opt)); foreach (GeometryObject obj in geomElement) { Solid solid = obj as Solid; if (null != solid) { if (solid.Volume > 0) { if (unionSolid == null) { unionSolid = solid; } else { unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(solid, unionSolid, BooleanOperationsType.Union); } } } } mp.MassSolid = unionSolid; if (null != unionSolid) { if (unionSolid.Volume > 0) { mp.ElementContainer = FindElementsInMass(m_doc, mp.MassSolid, mp.MassId, false); List <Element> linkedElements = FindElementsInLInkedFiles(element, geomElement); mp.ElementContainer.AddRange(linkedElements); mp.ElementCount = mp.ElementContainer.Count; } } if (mp.MassParameters.Count > 0) { foreach (Parameter param in mp.MassParameters) { if (!massParameters.Contains(param.Definition.Name)) { massParameters.Add(param.Definition.Name); } } } mp.IsHost = true; integratedMassList.Add(mp); } if (progressFormOpend) { progressForm.Close(); progressFormOpend = false; } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }