public static string StringFor(CeilingType type) { switch (type) { case CeilingType.Blank: return("Blank"); case CeilingType.Chandelier: return("Chandelier"); case CeilingType.Vent: return("Vent"); case CeilingType.Fan: return("Fan"); case CeilingType.FireAlarm: return("FireAlarm"); case CeilingType.HangingBanner: return("HangingBanner"); default: return("Unknown"); } }
private void SetProperties() { BoundingBoxXYZ = _element.get_BoundingBox(null); if (_element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Walls) { HostType = HostType.Wall; Wall wall = _element as Wall; Thickness = Math.Round(UnitUtils.ConvertFromInternalUnits(wall.Width, DisplayUnitType.DUT_MILLIMETERS), 1); } if (_element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Floors) { HostType = HostType.Floor; Floor floor = _element as Floor; Thickness = Math.Round(UnitUtils.ConvertFromInternalUnits(floor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM).AsDouble(), DisplayUnitType.DUT_MILLIMETERS), 1); } if (_element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Ceilings) { HostType = HostType.Ceiling; Ceiling ceiling = _element as Ceiling; ElementId typeId = ceiling.GetTypeId(); CeilingType cType = _document.GetElement(typeId) as CeilingType; Thickness = Math.Round(UnitUtils.ConvertFromInternalUnits(cType.get_Parameter(BuiltInParameter.CEILING_THICKNESS).AsDouble(), DisplayUnitType.DUT_MILLIMETERS), 1); } if (_element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Roofs) { HostType = HostType.Roof; Thickness = Math.Round(UnitUtils.ConvertFromInternalUnits(_element.get_Parameter(BuiltInParameter.ROOF_ATTR_THICKNESS_PARAM).AsDouble(), DisplayUnitType.DUT_MILLIMETERS), 1); } }
public void ByName_ValidArgs() { var ceilingTypeName = "Generic - 4\""; var ceilingType = CeilingType.ByName(ceilingTypeName); Assert.NotNull(ceilingType); Assert.AreEqual(ceilingTypeName, ceilingType.Name); }
public bool CreateCeilingFromLink() { var created = false; using (var tg = new TransactionGroup(Doc)) { tg.Start("Create Ceilings"); var failureMessages = new StringBuilder(); try { foreach (var lrp in selectedLinkedRooms) { var room = lrp.LinkedRoom; var ceilingsFound = new List <Ceiling>(); CeilingType ceilingType = null; using (var trans = new Transaction(Doc)) { trans.Start("Create a Ceiling"); try { ceilingsFound = FindCeilings(room, lrp.TransformValue); if (ceilingsFound.Count > 0) { ceilingType = FindCeilingType(room); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); failureMessages.AppendLine(room.Name + ": " + ex.Message); } } if (ceilingsFound.Count > 0 && null != ceilingType) { var copiedCeilings = CreateCeilings(room, ceilingsFound, ceilingType, ref failureMessages); if (copiedCeilings.Count > 0 && !createdCeilings.ContainsKey(room.Id.IntegerValue)) { createdCeilings.Add(room.Id.IntegerValue, copiedCeilings); created = true; } } } tg.Assimilate(); } catch (Exception ex) { tg.RollBack(); MessageBox.Show("Cannot create ceilings from the selected rooms.\n" + ex.Message, "Create Ceilings", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } return(created); }
internal static void UpdateTag(ElementId modifiedElmId, Autodesk.Revit.DB.Document doc) { StringBuilder strBld = new StringBuilder(); int rows = 0; int shelfLength = 0; Element modifiedElm = doc.GetElement(modifiedElmId); switch (modifiedElm.Category.Name) { case "Walls": Wall wl = modifiedElm as Wall; WallType wlType = wl.WallType; CompoundStructure cmpStr_wl = wlType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_wl, doc, out shelfLength); rows = wlType.GetCompoundStructure().LayerCount; break; case "Floors": Floor fl = modifiedElm as Floor; FloorType flType = fl.FloorType; CompoundStructure cmpStr_fl = flType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_fl, doc, out shelfLength); rows = flType.GetCompoundStructure().LayerCount; break; case "Ceilings": Ceiling cl = modifiedElm as Ceiling; CeilingType clType = doc.GetElement(cl.GetTypeId()) as CeilingType; CompoundStructure cmpStr_cl = clType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_cl, doc, out shelfLength); rows = clType.GetCompoundStructure().LayerCount; break; case "Roofs": RoofBase rf = modifiedElm as RoofBase; RoofType rfType = rf.RoofType; CompoundStructure cmpStr_rf = rfType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_rf, doc, out shelfLength); rows = rfType.GetCompoundStructure().LayerCount; break; } FamilyInstance tag = doc.GetElement(new ElementId(modifiedElm.LookupParameter("LinkedTag").AsInteger())) as FamilyInstance; try { tag.LookupParameter("multilineText").Set(strBld.ToString()); tag.LookupParameter("# of Rows").Set(rows); tag.LookupParameter("Shelf Length").Set(ToFt(shelfLength)); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static List <BH.oM.Geometry.Line> CeilingPattern(this Ceiling ceiling, RevitSettings settings, PlanarSurface surface = null) { CeilingType ceilingType = ceiling.Document.GetElement(ceiling.GetTypeId()) as CeilingType; CompoundStructure comStruct = ceilingType.GetCompoundStructure(); Material material = null; if (comStruct != null && comStruct.GetLayers().Count > 0) { material = ceiling.Document.GetElement(comStruct.GetLayers().Last().MaterialId) as Material; } else { ElementId materialId = ceiling.GetMaterialIds(false)?.FirstOrDefault(); if (materialId != null) { material = ceiling.Document.GetElement(materialId) as Material; } } if (material == null) { BH.Engine.Reflection.Compute.RecordWarning(String.Format("Ceiling patterns could not be pulled because there is no material assigned to the ceiling. Revit ElementId: {0}", ceiling.Id)); return(new List <oM.Geometry.Line>()); } double rotation; XYZ alignment = ceiling.CeilingPatternAlignment(material, settings, out rotation); List <oM.Geometry.Line> result = new List <oM.Geometry.Line>(); if (surface == null) { //This would need to be extended to take openings from Values into account foreach (PlanarSurface srf in ceiling.PanelSurfaces(ceiling.FindInserts(true, true, true, true), settings).Keys) { result.AddRange(material.CeilingPattern(srf, settings, alignment, rotation)); } } else { result.AddRange(material.CeilingPattern(surface, settings, alignment, rotation)); } return(result); }
public void ByOutlineTypeAndLevel_CurveArrayCeilingTypeLevel_ThrowsExceptionWithNullArgument() { var elevation = 100; var level = Level.ByElevation(elevation); var outline = new[] { Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(100, 0, 0)), Line.ByStartPointEndPoint(Point.ByCoordinates(100, 0, 0), Point.ByCoordinates(100, 100, 0)), Line.ByStartPointEndPoint(Point.ByCoordinates(100, 100, 0), Point.ByCoordinates(0, 100, 0)), Line.ByStartPointEndPoint(Point.ByCoordinates(0, 100, 0), Point.ByCoordinates(0, 0, 0)) }; var ceilingType = CeilingType.ByName("Generic"); Assert.Throws(typeof(ArgumentNullException), () => Ceiling.ByOutlineTypeAndLevel(outline, null, level)); Assert.Throws(typeof(ArgumentNullException), () => Ceiling.ByOutlineTypeAndLevel(outline, ceilingType, null)); }
public void ByOutlineTypeAndLevel_CurveArrayCeilingTypeLevel_ProducesCeilingWithCorrectArea() { var elevation = 100; var level = Level.ByElevation(elevation); var outline = new[] { Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(100, 0, 0)), Line.ByStartPointEndPoint(Point.ByCoordinates(100, 0, 0), Point.ByCoordinates(100, 100, 0)), Line.ByStartPointEndPoint(Point.ByCoordinates(100, 100, 0), Point.ByCoordinates(0, 100, 0)), Line.ByStartPointEndPoint(Point.ByCoordinates(0, 100, 0), Point.ByCoordinates(0, 0, 0)) }; var ceilingType = CeilingType.ByName("Generic"); var ceiling = Ceiling.ByOutlineTypeAndLevel(outline, ceilingType, level); BoundingBoxVolume(ceiling.BoundingBox).ShouldBeApproximately(100 * 100, 1e-3); }
/// <summary> /// /// </summary> /// <param name="room"></param> /// <returns></returns> private CeilingType FindCeilingType(Room room) { CeilingType ceilingType = null; try { var typeName = "Ceiling Finish"; if (!room.Document.IsLinked) { var param = room.get_Parameter(BuiltInParameter.ROOM_FINISH_CEILING); if (null != param) { if (param.HasValue) { typeName = param.AsString(); } } } var query = CeilingTypes.FirstOrDefault(x => x.Name == typeName); if (query != null) { ceilingType = query; } else { //create a ceiling type CeilingType typeToCopy; var materialId = ElementId.InvalidElementId; foreach (var cType in CeilingTypes) { if (!cType.CanBeCopied) { continue; } if (cType.GetCompoundStructure() != null) { var cStructure = cType.GetCompoundStructure(); foreach (var layer in cStructure.GetLayers()) { if (layer.Function == MaterialFunctionAssignment.Finish1 || layer.Function == MaterialFunctionAssignment.Finish2) { typeToCopy = cType; ceilingType = typeToCopy.Duplicate(typeName) as CeilingType; materialId = layer.MaterialId; break; } } } if (ceilingType != null) { break; } } var compoundStructure = ceilingType.GetCompoundStructure(); const double layerThickness = 0.020833; var layerIndex = compoundStructure.GetFirstCoreLayerIndex(); compoundStructure.SetLayerFunction(layerIndex, MaterialFunctionAssignment.Finish1); compoundStructure.SetLayerWidth(layerIndex, layerThickness); compoundStructure.SetMaterialId(layerIndex, materialId); for (var i = compoundStructure.LayerCount - 1; i > -1; i--) { if (i == layerIndex) { continue; } compoundStructure.DeleteLayer(i); } compoundStructure.StructuralMaterialIndex = 0; ceilingType.SetCompoundStructure(compoundStructure); } } catch (Exception ex) { MessageBox.Show(room.Name + ": Cannot find a ceiling type.\n" + ex.Message, "Find Ceiling Type", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(ceilingType); }
private List <Ceiling> CreateCeilings(Room room, List <Ceiling> ceilingsFound, CeilingType ceilingType, ref StringBuilder msgBuilder) { var copiedCeilings = new List <Ceiling>(); try { foreach (var ceiling in ceilingsFound) { using (var trans = new Transaction(Doc)) { trans.Start("Copy Ceiling"); try { double finishThickness = 0; var param = ceilingType.get_Parameter(BuiltInParameter.CEILING_THICKNESS); if (null != param) { if (param.HasValue) { finishThickness = param.AsDouble(); } } var copiedIds = ElementTransformUtils.CopyElement(Doc, ceiling.Id, new XYZ(0, 0, -finishThickness)); trans.Commit(); trans.Start("Change Ceiling Type"); if (copiedIds.Count > 0) { var copiedCeilingId = copiedIds.First(); var copiedCeiling = Doc.GetElement(copiedCeilingId) as Ceiling; if (null != copiedCeiling) { var changedTypeId = copiedCeiling.ChangeTypeId(ceilingType.Id); copiedCeilings.Add(copiedCeiling); } } trans.Commit(); } catch (Exception ex) { msgBuilder.AppendLine(ceiling.Name + " [" + ceiling.Id.IntegerValue + "]: cannot be copied\n" + ex.Message); trans.RollBack(); } } } } catch (Exception ex) { MessageBox.Show("Cannot create ceilings from the selected rooms.\nRoom Id:" + room.Id.IntegerValue + "\n\n" + ex.Message, "Create Ceilings", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(copiedCeilings); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region Get access to the current document and aplication. UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document; #endregion // Try to create a project parameter. try { Category walls = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Walls); Category floors = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Floors); Category ceilings = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Ceilings); Category roofs = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Roofs); CategorySet catSet = new CategorySet(); catSet.Insert(walls); catSet.Insert(floors); catSet.Insert(ceilings); catSet.Insert(roofs); using (Transaction t = new Transaction(doc, "Add project parameter")) { t.Start(); CreateProjectParam(app, "LinkedTag", ParameterType.Integer, false, catSet, BuiltInParameterGroup.INVALID, true); if (t.Commit() == TransactionStatus.Committed) { } else { t.RollBack(); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } if (Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")) == null) { BuildNewSchema(doc); } // Retrieving a specific family from the database. try { // Create a new FilteredElementCollector FilteredElementCollector collector = new FilteredElementCollector(doc); // Define and apply one or more filters to it. ElementCategoryFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericAnnotation); ParameterValueProvider pvp_1 = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME)); ParameterValueProvider pvp_2 = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME)); FilterStringEquals equals = new FilterStringEquals(); string familyName = "Z-M2-MultilayerMaterialTag-LOD1"; string typeName = "2.5mm"; FilterRule fRule_1 = new FilterStringRule(pvp_1, equals, familyName, false); FilterRule fRule_2 = new FilterStringRule(pvp_2, equals, typeName, false); IList <FilterRule> fRules = new List <FilterRule> { fRule_1, fRule_2 }; ElementParameterFilter filters = new ElementParameterFilter(fRules); // Collect the familySymbol's id ICollection <ElementId> id = collector.WherePasses(categoryFilter).WherePasses(filters).ToElementIds(); if (id.Count == 0) { message = "No FamilyType has been detected."; return(Result.Failed); } AnnotationSymbolType materialTag = doc.GetElement(id.First()) as AnnotationSymbolType; if (CreateWorkPlane(doc) != true) { return(Result.Failed); } // Prompt the user to select select the element to be tagged. Reference pickedRef = null; pickedRef = uidoc.Selection.PickObject(ObjectType.Element, new MultilayerStrFilter(), "Please select a multilayer element."); Element selectedElm = doc.GetElement(pickedRef.ElementId); XYZ point = uidoc.Selection.PickPoint("Please pick a point to place the family"); StringBuilder strBld = new StringBuilder(); int rows; int shelfLength; switch (selectedElm.Category.Name) { case "Walls": Wall wl = selectedElm as Wall; WallType wlType = wl.WallType; CompoundStructure cmpStr_wl = wlType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_wl, doc, out shelfLength); rows = wlType.GetCompoundStructure().LayerCount; break; case "Floors": Floor fl = selectedElm as Floor; FloorType flType = fl.FloorType; CompoundStructure cmpStr_fl = flType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_fl, doc, out shelfLength); rows = flType.GetCompoundStructure().LayerCount; break; case "Ceilings": Ceiling cl = selectedElm as Ceiling; CeilingType clType = doc.GetElement(cl.GetTypeId()) as CeilingType; CompoundStructure cmpStr_cl = clType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_cl, doc, out shelfLength); rows = clType.GetCompoundStructure().LayerCount; break; case "Roofs": RoofBase rf = selectedElm as RoofBase; RoofType rfType = rf.RoofType; CompoundStructure cmpStr_rf = rfType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_rf, doc, out shelfLength); rows = rfType.GetCompoundStructure().LayerCount; break; default: TaskDialog.Show("Warning!", "This category is not supported."); return(Result.Failed); } using (Transaction trn_1 = new Transaction(doc, "Materials Mark")) { FamilyInstance createdElm = null; if (trn_1.Start() == TransactionStatus.Started) { createdElm = doc.Create.NewFamilyInstance(point, materialTag, doc.ActiveView); selectedElm.LookupParameter("LinkedTag").Set(createdElm.Id.IntegerValue); if (trn_1.Commit() == TransactionStatus.Committed) { Transaction trn_2 = new Transaction(doc, "Set parameters"); try { trn_2.Start(); createdElm.LookupParameter("multilineText").Set(strBld.ToString()); createdElm.LookupParameter("# of Rows").Set(rows); createdElm.LookupParameter("Shelf Length").Set(ToFt(shelfLength)); XYZ vec; if (selectedElm.Category.Name != "Walls") { vec = new XYZ(0, 0, createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale); createdElm.LookupParameter("Down Arrow Direction").Set(1); } else { vec = new XYZ(-createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale, 0, 0); createdElm.LookupParameter("Down Arrow Direction").Set(0); } ElementTransformUtils.MoveElement(doc, createdElm.Id, vec); trn_2.Commit(); AddElementToSchema(Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")), createdElm, selectedElm.Id); } finally { if (trn_2 != null) { trn_2.Dispose(); } } } else { trn_1.RollBack(); return(Result.Failed); } } else { trn_1.RollBack(); return(Result.Failed); } return(Result.Succeeded); } } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
public Ceiling(CeilingType type, Direction direction) { this.type = type; this.direction = direction; }
public Ceiling(CeilingType type) { this.type = type; }
public void ByName_NullArgument() { Assert.Throws(typeof(ArgumentNullException), () => CeilingType.ByName(null)); }
/***************************************************/ public static List <oM.Environment.Elements.Panel> EnvironmentPanelsFromRevit(this Ceiling ceiling, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); List <oM.Environment.Elements.Panel> panels = refObjects.GetValues <oM.Environment.Elements.Panel>(ceiling.Id); if (panels != null && panels.Count != 0) { return(panels); } Dictionary <PlanarSurface, List <PlanarSurface> > surfaces = ceiling.PanelSurfaces(ceiling.FindInserts(true, true, true, true), settings); if (surfaces == null) { return(panels); } CeilingType ceilingType = ceiling.Document.GetElement(ceiling.GetTypeId()) as CeilingType; BH.oM.Physical.Constructions.Construction construction = ceilingType.ConstructionFromRevit(null, settings, refObjects); panels = new List <oM.Environment.Elements.Panel>(); foreach (PlanarSurface surface in surfaces.Keys) { //Create the BuildingElement oM.Environment.Elements.Panel panel = new oM.Environment.Elements.Panel() { ExternalEdges = surface.ExternalBoundary.ToEdges(), Name = ceiling.FamilyTypeFullName(), }; //Set ExtendedProperties OriginContextFragment originContext = new OriginContextFragment() { ElementID = ceiling.Id.IntegerValue.ToString(), TypeName = ceiling.FamilyTypeFullName() }; originContext.SetProperties(ceilingType, settings.ParameterSettings); originContext.SetProperties(ceiling, settings.ParameterSettings); panel.AddFragment(originContext); PanelAnalyticalFragment panelAnalytical = new PanelAnalyticalFragment(); panelAnalytical.SetProperties(ceilingType, settings.ParameterSettings); panelAnalytical.SetProperties(ceiling, settings.ParameterSettings); panel.AddFragment(panelAnalytical); PanelContextFragment panelContext = new PanelContextFragment(); panelContext.SetProperties(ceilingType, settings.ParameterSettings); panelContext.SetProperties(ceiling, settings.ParameterSettings); panel.AddFragment(panelContext); BuildingResultFragment buildingResults = new BuildingResultFragment(); buildingResults.SetProperties(ceilingType, settings.ParameterSettings); buildingResults.SetProperties(ceiling, settings.ParameterSettings); panel.AddFragment(buildingResults); panel.Construction = construction; panel.Type = oM.Environment.Elements.PanelType.Ceiling; //Set identifiers, parameters & custom data panel.SetIdentifiers(ceiling); panel.CopyParameters(ceiling, settings.ParameterSettings); panel.SetProperties(ceiling, settings.ParameterSettings); refObjects.AddOrReplace(ceiling.Id, panel); panels.Add(panel); } return(panels); }