コード例 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            Element element = null;

            if (!dataAccess.GetData(0, ref element) || element == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            if (((BuiltInCategory)element.Category.Id.IntegerValue) != BuiltInCategory.OST_VolumeOfInterest)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            BoundingBoxXYZ boundingBoxXYZ = Core.Revit.Query.BoundingBoxXYZ(element);

            if (boundingBoxXYZ == null || boundingBoxXYZ.Min.DistanceTo(boundingBoxXYZ.Max) < Tolerance.Distance)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Outline outline = new Outline(boundingBoxXYZ.Transform.OfPoint(boundingBoxXYZ.Min), boundingBoxXYZ.Transform.OfPoint(boundingBoxXYZ.Max));

            List <Element> elements = new FilteredElementCollector(document).WherePasses(new LogicalOrFilter(new BoundingBoxIsInsideFilter(outline, Tolerance.MacroDistance), new BoundingBoxIntersectsFilter(outline, Tolerance.MacroDistance))).ToElements()?.ToList();

            List <RhinoInside.Revit.GH.Types.Element> elements_Result = elements.ConvertAll(x => RhinoInside.Revit.GH.Types.Element.FromElement(x));

            elements_Result.RemoveAll(x => x == null || !x.IsValid);

            dataAccess.SetDataList(0, elements_Result);
        }
コード例 #2
0
        public static List <ViewPlan> DuplicateViewPlan(this ViewPlan viewPlan, IEnumerable <Level> levels = null, bool useExisting = false)
        {
            if (viewPlan == null || !viewPlan.IsValidObject || viewPlan.IsTemplate)
            {
                return(null);
            }

            Document document = viewPlan.Document;

            if (document == null)
            {
                return(null);
            }

            List <Level> levels_Temp = null;

            if (levels != null)
            {
                levels_Temp = new List <Level>(levels);
            }

            if (levels_Temp == null)
            {
                levels_Temp = new FilteredElementCollector(document).OfClass(typeof(Level)).Cast <Level>().ToList();
            }

            List <Element> elements_ColorFillLegend = new FilteredElementCollector(document, viewPlan.Id).OfCategory(BuiltInCategory.OST_ColorFillLegends).ToList();

            List <ViewPlan> result = new List <ViewPlan>();

            foreach (Level level in levels_Temp)
            {
                if (level.Id == viewPlan.GenLevel.Id)
                {
                    continue;
                }

                ViewPlan viewPlan_New = null;

                List <ViewPlan> viewPlans = new FilteredElementCollector(document).OfClass(typeof(ViewPlan)).Cast <ViewPlan>().ToList();
                string          name      = level.Name;
                if (useExisting)
                {
                    viewPlan_New = viewPlans.Find(x => x.Name == name);
                }

                if (viewPlan_New == null)
                {
                    viewPlan_New = ViewPlan.Create(document, viewPlan.GetTypeId(), level.Id);

                    // Check name uniqueness
                    string name_Temp = name;
                    int    count     = 0;
                    while (viewPlans.Find(x => x.Name == name_Temp) != null)
                    {
                        count++;
                        name_Temp = string.Format("{0} {1}", name, count);
                    }

                    viewPlan_New.Name = name_Temp;
                }

                foreach (Parameter parameter in viewPlan.ParametersMap)
                {
                    if (parameter.Id.IntegerValue == (int)BuiltInParameter.VIEW_NAME)
                    {
                        continue;
                    }

                    Definition definition = parameter?.Definition;
                    if (definition == null)
                    {
                        continue;
                    }

                    Parameter parameter_New = viewPlan_New.get_Parameter(parameter.Definition);
                    if (parameter_New == null)
                    {
                        continue;
                    }

                    CopyValue(parameter, parameter_New);
                }

                if (elements_ColorFillLegend != null && elements_ColorFillLegend.Count != 0)
                {
                    ElementTransformUtils.CopyElements(viewPlan, elements_ColorFillLegend.ConvertAll(x => x.Id), viewPlan_New, null, new CopyPasteOptions());
                }

                result.Add(viewPlan_New);

                IEnumerable <ElementId> elementIds_Dependent = viewPlan.GetDependentViewIds();
                if (elementIds_Dependent != null && elementIds_Dependent.Count() != 0)
                {
                    foreach (ElementId elementId_Dependent in elementIds_Dependent)
                    {
                        ViewPlan viewPlan_Dependent = document.GetElement(elementId_Dependent) as ViewPlan;
                        if (viewPlan_Dependent == null)
                        {
                            continue;
                        }

                        viewPlans = new FilteredElementCollector(document).OfClass(typeof(ViewPlan)).Cast <ViewPlan>().ToList();
                        string name_Dependent = name;
                        if (viewPlan_Dependent.Name.StartsWith(viewPlan.Name))
                        {
                            name_Dependent = level.Name + viewPlan_Dependent.Name.Substring(viewPlan.Name.Length);
                        }
                        else
                        {
                            Element scopeBox = viewPlan_Dependent.ScopeBox();
                            if (scopeBox != null)
                            {
                                name_Dependent = level.Name + " - " + scopeBox.Name;
                            }
                        }

                        ViewPlan viewPlan_Dependent_New = null;

                        if (useExisting)
                        {
                            viewPlan_Dependent_New = viewPlans.Find(x => x.Name == name_Dependent);
                        }

                        if (viewPlan_Dependent_New == null)
                        {
                            ElementId elementId_Dependent_New = viewPlan_New.Duplicate(ViewDuplicateOption.AsDependent);
                            if (elementId_Dependent_New == null || elementId_Dependent_New == ElementId.InvalidElementId)
                            {
                                continue;
                            }

                            viewPlan_Dependent_New = document.GetElement(elementId_Dependent_New) as ViewPlan;
                            if (viewPlan_Dependent_New == null)
                            {
                                continue;
                            }

                            // Check name uniqueness
                            string name_Dependent_Temp = name_Dependent;
                            int    count = 0;
                            while (viewPlans.Find(x => x.Name == name_Dependent_Temp) != null)
                            {
                                count++;
                                name_Dependent_Temp = string.Format("{0} {1}", name_Dependent, count);
                            }

                            viewPlan_Dependent_New.Name = name_Dependent_Temp;
                        }

                        foreach (Parameter parameter in viewPlan_Dependent.ParametersMap)
                        {
                            if (parameter.Id.IntegerValue == (int)BuiltInParameter.VIEW_NAME)
                            {
                                continue;
                            }

                            Definition definition = parameter?.Definition;
                            if (definition == null)
                            {
                                continue;
                            }

                            Parameter parameter_New = viewPlan_Dependent_New.get_Parameter(parameter.Definition);
                            if (parameter_New == null)
                            {
                                continue;
                            }

                            CopyValue(parameter, parameter_New);
                        }

                        result.Add(viewPlan_Dependent_New);
                    }
                }
            }

            return(result);
        }