//FUNCTION FOR STAIR
        public void StairSelector(string activityDescription)
        {
            string             caTegory;
            List <ElementData> TempListofSafetyIssues = new List <ElementData>();
            ElementData        eachElementData        = new ElementData();
            Operate            elementOperate         = new Operate();
            string             elementID;

            DateTime tempDateTime = new DateTime();

            eachElementData.EleStartDate  = new DateTime();
            eachElementData.EleEndDate    = new DateTime();
            eachElementData.ProtStartDate = new DateTime();
            eachElementData.ProtEndDate   = new DateTime();

            SlabResult stairwallResult    = new SlabResult();
            SlabResult stairrailingResult = new SlabResult();

            foreach (Nw.ModelItem modelAncestors in modelItem.AncestorsAndSelf)
            {
                Nw.PropertyCategoryCollection familypropCatCollection = modelAncestors.PropertyCategories;
                foreach (Nw.PropertyCategory familypropCat in familypropCatCollection)
                {
                    if (familypropCat.DisplayName.ToString() == "Element" &&
                        null != familypropCat.Properties.FindPropertyByDisplayName("Category"))
                    {
                        caTegory = familypropCat.Properties.FindPropertyByDisplayName("Category").Value.ToString();
                        caTegory = caTegory.Substring(caTegory.IndexOf(":") + 1);

                        //if element is stair
                        if (caTegory == "Stairs")
                        {
                            //get start date of edge walls and railings
                            foreach (Nw.PropertyCategory innerpropCat in familypropCatCollection)
                            {
                                if (innerpropCat.DisplayName.ToString() == "Element ID" &&
                                    null != innerpropCat.Properties.FindPropertyByDisplayName("Value"))
                                {
                                    elementID          = innerpropCat.Properties.FindPropertyByDisplayName("Value").Value.ToString();
                                    elementID          = elementID.Substring(elementID.IndexOf(":") + 1);
                                    stairwallResult    = elementOperate.RoofOperations(elementID);
                                    stairrailingResult = elementOperate.RailingOperations(elementID);
                                    break;
                                }
                            }

                            //get element start date and end date
                            foreach (Nw.PropertyCategory innerpropCat in familypropCatCollection)
                            {
                                if (innerpropCat.DisplayName.ToString() == "TimeLiner" &&
                                    null != innerpropCat.Properties.FindPropertyByDisplayName("Contained in Task Start (Planned):1") &&
                                    null != innerpropCat.Properties.FindPropertyByDisplayName("Contained in Task End (Planned):1"))
                                {
                                    tempDateTime = (DateTime)innerpropCat.Properties
                                                   .FindPropertyByDisplayName("Contained in Task Start (Planned):1").Value.ToDateTime();
                                    eachElementData.ProtStartDate = (DateTime)innerpropCat.Properties
                                                                    .FindPropertyByDisplayName("Contained in Task End (Planned):1").Value.ToDateTime();
                                    break;
                                }
                            }

                            //get element level and elevation
                            foreach (Nw.PropertyCategory innerpropCat in familypropCatCollection)
                            {
                                if (innerpropCat.DisplayName.ToString() == "Top Level" &&
                                    null != innerpropCat.Properties.FindPropertyByDisplayName("Elevation") &&
                                    null != innerpropCat.Properties.FindPropertyByDisplayName("Name"))
                                {
                                    //elevation is returned in feet and not as double
                                    elevation = innerpropCat.Properties.FindPropertyByDisplayName("Elevation").Value.ToDoubleLength();
                                    elevation = elevation * (double)0.3048;

                                    eachElementData.Elevation = elevation;
                                    eachElementData.Level     = innerpropCat.Properties.FindPropertyByDisplayName("Name").Value.ToString();
                                    eachElementData.Level     = eachElementData.Level.Substring(eachElementData.Level.IndexOf(":") + 1);
                                    break;
                                }
                            }

                            //in case of walls along the stair edges
                            if (stairwallResult.stairstartDate.ToShortDateString() != "01-01-0001")
                            {
                                eachElementData.ProtEndDate = stairwallResult.stairstartDate;
                                eachElementData.Hazard      = "Unprotected Stairs";
                                eachElementData.Protection  = "Provide edge protection along the stair walls are to be built";
                                TempListofSafetyIssues.Add(eachElementData);
                            }

                            //in case of railings along the stair edges
                            if (stairrailingResult.stairstartDate.ToShortDateString() != "01-01-0001")
                            {
                                eachElementData.ProtEndDate = stairrailingResult.stairstartDate;
                                eachElementData.Hazard      = "Unprotected Stairs";
                                eachElementData.Protection  = "Provide edge protection along the stair where railings are to be built";
                                TempListofSafetyIssues.Add(eachElementData);
                            }
                            eachElementData.EleStartDate  = tempDateTime;
                            eachElementData.EleEndDate    = eachElementData.ProtStartDate;
                            eachElementData.ProtStartDate = eachElementData.EleEndDate;
                            eachElementData.ProtEndDate   = eachElementData.EleEndDate;
                            eachElementData.ActivityName  = activityDescription;
                            eachElementData.ElementType   = "Stair";
                            eachElementData.Hazard        = "Working at height";
                            eachElementData.Protection    = "See general guidelines for Construction of stairs";
                            TempListofSafetyIssues.Add(eachElementData);

                            Result.ListofSafetyIssues.AddRange(TempListofSafetyIssues);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        //Code for walls
        public SlabResult RoofOperations(string elementID)
        {
            List <DateTime> ListWallEdgeStartDate = new List <DateTime>();
            List <DateTime> ListWallOpeningStartDate = new List <DateTime>();
            List <DateTime> ListWallStairStartDate = new List <DateTime>();
            string          caTegory, protectionInfo = null, elementInfo = null;
            DateTime        StartDate = new DateTime();
            SlabResult      roofwallResult = new SlabResult();

            roofwallResult.elementCategory = null;

            //open the active document and get model items
            foreach (Nw.ModelItem modelItem in Nw.Application.ActiveDocument.Models.RootItemDescendantsAndSelf)
            {
                Nw.ModelItem modelParent = modelItem.Parent;

                if (modelItem.HasGeometry)
                {
                    //select all the property categories of the parent element
                    Nw.PropertyCategoryCollection propCatCollection = modelParent.PropertyCategories;

                    foreach (Nw.PropertyCategory propCat in propCatCollection)
                    {
                        //check for the element type to be wall by iterating through property categories
                        if (propCat.DisplayName.ToString() == "Element" && null != propCat.Properties.FindPropertyByDisplayName("Category"))
                        {
                            caTegory = propCat.Properties.FindPropertyByDisplayName("Category").Value.ToString();
                            caTegory = caTegory.Substring(caTegory.IndexOf(":") + 1);

                            if (caTegory == "Walls")
                            {
                                roofwallResult.elementCategory = "Walls";
                                Nw.PropertyCategoryCollection innerpropCatCollection = modelParent.PropertyCategories;

                                // for walls found check for the ehared parameter input from revit
                                foreach (Nw.PropertyCategory innerpropCat in innerpropCatCollection)
                                {
                                    if (innerpropCat.DisplayName.ToString() == "Element" &&
                                        null != innerpropCat.Properties.FindPropertyByDisplayName("ElementInfo") &&
                                        null != innerpropCat.Properties.FindPropertyByDisplayName("ProtectionInfo"))
                                    {
                                        elementInfo    = innerpropCat.Properties.FindPropertyByDisplayName("ElementInfo").Value.ToString();
                                        protectionInfo = innerpropCat.Properties.FindPropertyByDisplayName("ProtectionInfo").Value.ToString();
                                        elementInfo    = elementInfo.Substring(elementInfo.IndexOf(":") + 1);
                                        protectionInfo = protectionInfo.Substring(protectionInfo.IndexOf(":") + 1);

                                        //code for side protection type based on the shared parameter
                                        if (elementInfo == elementID && protectionInfo == "ExteriorWall")
                                        {
                                            Nw.PropertyCategoryCollection innermostpropCatCollection = modelParent.PropertyCategories;

                                            //get the start date of the wall elements and save it to a list
                                            foreach (Nw.PropertyCategory innermostpropCat in innermostpropCatCollection)
                                            {
                                                if (innermostpropCat.DisplayName.ToString() == "TimeLiner" &&
                                                    null != innermostpropCat.Properties.FindPropertyByDisplayName("Attached to Task Start (Planned):1"))
                                                {
                                                    StartDate = (DateTime)innermostpropCat.Properties
                                                                .FindPropertyByDisplayName("Attached to Task Start (Planned):1").Value.ToDateTime();
                                                    ListWallEdgeStartDate.Add(StartDate);
                                                }
                                            }
                                        }

                                        //code for opening protection
                                        if (elementInfo == elementID && protectionInfo == "Opening")
                                        {
                                            Nw.PropertyCategoryCollection innermostpropCatCollection = modelParent.PropertyCategories;

                                            //get the start date of the wall elements and save it to a list
                                            foreach (Nw.PropertyCategory innermostpropCat in innermostpropCatCollection)
                                            {
                                                if (innermostpropCat.DisplayName.ToString() == "TimeLiner" &&
                                                    null != innermostpropCat.Properties.FindPropertyByDisplayName("Attached to Task Start (Planned):1"))
                                                {
                                                    StartDate = (DateTime)innermostpropCat.Properties
                                                                .FindPropertyByDisplayName("Attached to Task Start (Planned):1").Value.ToDateTime();
                                                    ListWallOpeningStartDate.Add(StartDate);
                                                }
                                            }
                                        }

                                        //code for stair side protection
                                        if (elementInfo == elementID && protectionInfo == "Stair")
                                        {
                                            Nw.PropertyCategoryCollection innermostpropCatCollection = modelParent.PropertyCategories;

                                            //get the start date of the wall elements and save it to a list
                                            foreach (Nw.PropertyCategory innermostpropCat in innermostpropCatCollection)
                                            {
                                                if (innermostpropCat.DisplayName.ToString() == "TimeLiner" &&
                                                    null != innermostpropCat.Properties.FindPropertyByDisplayName("Attached to Task Start (Planned):1"))
                                                {
                                                    StartDate = (DateTime)innermostpropCat.Properties
                                                                .FindPropertyByDisplayName("Attached to Task Start (Planned):1").Value.ToDateTime();
                                                    ListWallStairStartDate.Add(StartDate);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // find the largest of the start dates and return it
            if (ListWallEdgeStartDate.Count != 0)
            {
                ListWallEdgeStartDate.Sort();
                roofwallResult.edgestartDate = new DateTime();
                roofwallResult.edgestartDate = ListWallEdgeStartDate.Last();
                ListWallEdgeStartDate.Clear();
            }
            if (ListWallOpeningStartDate.Count != 0)
            {
                ListWallOpeningStartDate.Sort();
                roofwallResult.openingstartDate = new DateTime();
                roofwallResult.openingstartDate = ListWallOpeningStartDate.Last();
                ListWallOpeningStartDate.Clear();
            }
            if (ListWallStairStartDate.Count != 0)
            {
                ListWallStairStartDate.Sort();
                roofwallResult.stairstartDate = new DateTime();
                roofwallResult.stairstartDate = ListWallStairStartDate.Last();
                ListWallStairStartDate.Clear();
            }
            return(roofwallResult);
        }
        //FUNCTION FOR ROOF
        public void RoofSelector(string activityDescription)
        {
            Nw.ModelItem       modelParent    = modelItem.Parent;
            Operate            elementOperate = new Operate();
            string             elementID;
            List <ElementData> TempListofSafetyIssues = new List <ElementData>();
            ElementData        eachElementData        = new ElementData();

            DateTime tempDateTime = new DateTime();

            eachElementData.EleStartDate  = new DateTime();
            eachElementData.EleEndDate    = new DateTime();
            eachElementData.ProtStartDate = new DateTime();
            eachElementData.ProtEndDate   = new DateTime();

            SlabResult slabwallResult    = new SlabResult();
            SlabResult slabrailingResult = new SlabResult();

            Nw.PropertyCategoryCollection innerpropCatCollection = modelParent.PropertyCategories;

            //get element start date and end date
            foreach (Nw.PropertyCategory innerpropCat in innerpropCatCollection)
            {
                if (innerpropCat.DisplayName.ToString() == "TimeLiner" &&
                    null != innerpropCat.Properties.FindPropertyByDisplayName("Attached to Task Start (Planned):1") &&
                    null != innerpropCat.Properties.FindPropertyByDisplayName("Attached to Task End (Planned):1"))
                {
                    tempDateTime = (DateTime)innerpropCat.Properties
                                   .FindPropertyByDisplayName("Attached to Task Start (Planned):1").Value.ToDateTime();
                    eachElementData.ProtStartDate = (DateTime)innerpropCat.Properties
                                                    .FindPropertyByDisplayName("Attached to Task End (Planned):1").Value.ToDateTime();
                    break;
                }
            }


            //get element level and elevation
            foreach (Nw.PropertyCategory innerpropCat in innerpropCatCollection)
            {
                if (innerpropCat.DisplayName.ToString() == "Base Level" &&
                    null != innerpropCat.Properties.FindPropertyByDisplayName("Elevation") &&
                    null != innerpropCat.Properties.FindPropertyByDisplayName("Name"))
                {
                    //elevation is returned in feet and not as double
                    elevation = innerpropCat.Properties.FindPropertyByDisplayName("Elevation").Value.ToDoubleLength();
                    elevation = elevation * (double)0.3048;

                    eachElementData.Elevation = elevation;
                    eachElementData.Level     = innerpropCat.Properties.FindPropertyByDisplayName("Name").Value.ToString();
                    eachElementData.Level     = eachElementData.Level.Substring(eachElementData.Level.IndexOf(":") + 1);
                    break;
                }
            }

            //get start date of edge walls and railings
            foreach (Nw.PropertyCategory innerpropCat in innerpropCatCollection)
            {
                if (innerpropCat.DisplayName.ToString() == "Element ID" &&
                    null != innerpropCat.Properties.FindPropertyByDisplayName("Value"))
                {
                    elementID         = innerpropCat.Properties.FindPropertyByDisplayName("Value").Value.ToString();
                    elementID         = elementID.Substring(elementID.IndexOf(":") + 1);
                    slabwallResult    = elementOperate.RoofOperations(elementID);
                    slabrailingResult = elementOperate.RailingOperations(elementID);
                    break;
                }
            }

            //in case of walls along the boundaries
            if (slabwallResult.edgestartDate.ToShortDateString() != "01-01-0001")
            {
                eachElementData.ProtEndDate = slabwallResult.edgestartDate;
                eachElementData.Hazard      = "Unprotected Slab Edges";
                eachElementData.Protection  = "Provide edge protection along the slab edges where exterior walls are to be built";
                TempListofSafetyIssues.Add(eachElementData);
            }

            //in case of railings along the boundaries
            if (slabrailingResult.edgestartDate.ToShortDateString() != "01-01-0001")
            {
                eachElementData.ProtEndDate = slabrailingResult.edgestartDate;
                eachElementData.Hazard      = "Unprotected Edges of Slab";
                eachElementData.Protection  = "Provide edge protection along the edges of the slab where railings are to be built";
                TempListofSafetyIssues.Add(eachElementData);
            }

            //in case of walls along openings
            if (slabwallResult.openingstartDate.ToShortDateString() != "01-01-0001")
            {
                eachElementData.ProtEndDate = slabwallResult.openingstartDate;
                eachElementData.Hazard      = "Unprotected Openings in slab";
                eachElementData.Protection  = "Provide edge protection along the opening edges where walls are to be built";
                TempListofSafetyIssues.Add(eachElementData);
            }

            //in case of railings along openings
            if (slabrailingResult.openingstartDate.ToShortDateString() != "01-01-0001")
            {
                eachElementData.ProtEndDate = slabrailingResult.openingstartDate;
                eachElementData.Hazard      = "Unprotected Openings in slab";
                eachElementData.Protection  = "Provide edge protection along the edges of openings where railings are to be built";
                TempListofSafetyIssues.Add(eachElementData);
            }


            eachElementData.EleStartDate  = tempDateTime;
            eachElementData.EleEndDate    = eachElementData.ProtStartDate;
            eachElementData.ProtStartDate = eachElementData.EleEndDate;
            eachElementData.ProtEndDate   = eachElementData.EleEndDate;
            eachElementData.ActivityName  = activityDescription;
            eachElementData.ElementType   = "Roof";
            eachElementData.Hazard        = "Unprotected Edges of Slab and slab openings";
            eachElementData.Protection    = "See general guidelines for Construction of slabs at height";
            TempListofSafetyIssues.Add(eachElementData);

            Result.ListofSafetyIssues.AddRange(TempListofSafetyIssues);
        }