private List <SpatialElementProperties> FindSpatialElements(ParameterMapProperties pmp, bool includeLinks) { List <SpatialElementProperties> sepList = new List <SpatialElementProperties>(); try { FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <SpatialElement> spatialElements = collector.OfCategoryId(pmp.SpatialCategory.CategoryObj.Id).WhereElementIsNotElementType().Cast <SpatialElement>().ToList(); foreach (SpatialElement se in spatialElements) { SpatialElementProperties sep = new SpatialElementProperties(se); sep.IsLinked = false; sepList.Add(sep); } if (includeLinks) { FilteredElementCollector linkCollector = new FilteredElementCollector(m_doc); List <RevitLinkInstance> linkInstances = linkCollector.OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().Cast <RevitLinkInstance>().ToList(); foreach (RevitLinkInstance instance in linkInstances) { LinkedInstanceProperties lip = new LinkedInstanceProperties(instance); if (null != lip.LinkedDocument && null != lip.DocumentTitle) { FilteredElementCollector spaceCollector = new FilteredElementCollector(lip.LinkedDocument); List <SpatialElement> elements = spaceCollector.OfCategoryId(pmp.SpatialCategory.CategoryObj.Id).WhereElementIsNotElementType().Cast <SpatialElement>().ToList(); if (elements.Count > 0) { foreach (SpatialElement se in elements) { SpatialElementProperties sep = new SpatialElementProperties(se); sep.IsLinked = true; sep.LinkProperties = lip; if (sep.SpaceArea > 0) { sepList.Add(sep); } } } } } } } catch (Exception ex) { errorMessages.AppendLine("Cannot find spatial elements from " + pmp.SpatialCategory.CategoryName); errorMessages.AppendLine(ex.Message); } return(sepList); }
private bool WriteParameter(ParameterMapProperties pmp, SpatialElementProperties sep, List <Element> revitElements) { bool result = false; try { SpatialElement spatialElement = sep.ElementObj; if (null != spatialElement) { Parameter sParam = spatialElement.LookupParameter(pmp.SpatialParamName); if (null != sParam) { using (Transaction trans = new Transaction(m_doc)) { trans.Start("Write Parameters"); try { foreach (Element re in revitElements) { if (re.GroupId != ElementId.InvalidElementId) { groupExist = true; continue; } //elements in group Parameter rParam = re.LookupParameter(pmp.RevitParamName); if (null == rParam) { ElementType elementType = m_doc.GetElement(re.GetTypeId()) as ElementType; if (null != elementType) { rParam = elementType.LookupParameter(pmp.RevitParamName); } } if (null != rParam) { if (rParam.IsReadOnly) { continue; } switch (rParam.StorageType) { case StorageType.Double: try { rParam.Set(sParam.AsDouble()); } catch { } break; case StorageType.ElementId: try { rParam.Set(sParam.AsElementId()); } catch { } break; case StorageType.Integer: try { rParam.Set(sParam.AsInteger()); } catch { } break; case StorageType.String: try { rParam.Set(sParam.AsString()); } catch { } break; } } } trans.Commit(); } catch (Exception ex) { string message = ex.Message; trans.RollBack(); } } result = true; } } } catch (Exception ex) { errorMessages.AppendLine("Cannot write parameter values of family instances inside - " + sep.ElementObj.Number + " : " + sep.ElementObj.Name); errorMessages.AppendLine(ex.Message); } return(result); }
private List <Element> FindRevitElements(ParameterMapProperties pmp, SpatialElementProperties sep) { List <Element> revitElements = new List <Element>(); try { BoundingBoxXYZ boundingBox = null; Room room = null; Space space = null; if (sep.CategoryId == (int)BuiltInCategory.OST_Rooms) { room = sep.ElementObj as Room; boundingBox = room.get_BoundingBox(null); } else if (sep.CategoryId == (int)BuiltInCategory.OST_MEPSpaces) { space = sep.ElementObj as Space; boundingBox = space.get_BoundingBox(null); } if (null != boundingBox) { XYZ minXYZ = boundingBox.Min; XYZ maxXYZ = boundingBox.Max; if (sep.IsLinked && null != sep.LinkProperties) { minXYZ = sep.LinkProperties.TransformValue.OfPoint(minXYZ); maxXYZ = sep.LinkProperties.TransformValue.OfPoint(maxXYZ); } //bounding box quick filter Outline outline = new Outline(minXYZ, maxXYZ); BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline); BoundingBoxIsInsideFilter insideFilter = new BoundingBoxIsInsideFilter(outline); LogicalOrFilter orFilter = new LogicalOrFilter(intersectFilter, insideFilter); FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <Element> elements = collector.OfCategoryId(pmp.RevitCategory.CategoryObj.Id).WherePasses(orFilter).ToElements().ToList(); if (checkBoxIntersect.IsChecked == true) { revitElements.AddRange(elements); } else { //slow solid filter if (elements.Count > 0) { foreach (Element element in elements) { LocationPoint locationPt = element.Location as LocationPoint; if (null != locationPt) { XYZ point = locationPt.Point; if (sep.IsLinked && null != sep.LinkProperties) { point = sep.LinkProperties.TransformValue.Inverse.OfPoint(point); } if (null != room) { if (room.IsPointInRoom(point)) { revitElements.Add(element); } } else if (null != space) { if (space.IsPointInSpace(point)) { revitElements.Add(element); } } } LocationCurve locationCurve = element.Location as LocationCurve; if (null != locationCurve) { Curve curve = locationCurve.Curve; XYZ firstPt = curve.GetEndPoint(0); XYZ secondPt = curve.GetEndPoint(1); XYZ centerPt = curve.Evaluate(0.5, true); if (sep.IsLinked && null != sep.LinkProperties) { firstPt = sep.LinkProperties.TransformValue.Inverse.OfPoint(firstPt); secondPt = sep.LinkProperties.TransformValue.Inverse.OfPoint(secondPt); } if (null != room) { //modification: pick centroid if (room.IsPointInRoom(centerPt)) { revitElements.Add(element); } /* * if (room.IsPointInRoom(firstPt) || room.IsPointInRoom(secondPt)) * { * revitElements.Add(element); * }*/ } else if (null != space) { if (space.IsPointInSpace(centerPt)) { revitElements.Add(element); } } } } } } } } catch (Exception ex) { errorMessages.AppendLine("Cannot find model elements from - " + sep.ElementObj.Number + " : " + sep.ElementObj.Name); errorMessages.AppendLine(ex.Message); } return(revitElements); }