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); }
/// <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); }
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); } }