Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
        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);
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        /***************************************************/

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