Exemplo n.º 1
0
        // All Categories
        internal void ModellingTool()
        {
            CategorySet catSet = Utils.AssignableCategories(uiapp, doc);

            using (Transaction t = new Transaction(doc, "Modelling Tool Populate"))
            {
                int n = catSet.Size;

                string s       = "{0} of " + n.ToString() + " categories processed...";
                string caption = "Modelling Tools";

                t.Start();
                int count = 0;
                using (ProgressForm pf = new ProgressForm(caption, s, n))
                {
                    foreach (Category cat in catSet)
                    {
                        if (pf.getAbortFlag())
                        {
                            t.RollBack();
                            return;
                        }

                        pf.Increment();
                        try
                        {
                            IList <Element> collector = new FilteredElementCollector(doc).OfCategoryId(cat.Id).WhereElementIsElementType().ToElements();
                            if (collector.Count < 1)
                            {
                                continue;
                            }
                            foreach (Element el in collector)
                            {
                                Parameter p = el.LookupParameter("Modelling Tool");

                                if (p != null && !p.IsReadOnly)
                                {
                                    p.Set(cat.Name);
                                }
                            }
                            count++;
                        }
                        catch (Exception)
                        {
                            //TaskDialog.Show("Failed", cat.Name + " : " + ex);
                        }
                    }
                }
                if (count == 0)
                {
                    TaskDialog.Show("Modelling Tool failed to execute.", "No elements with Modelling Tool parameter found in this document.");
                    t.RollBack();
                }
                t.Commit();
            }
        }
Exemplo n.º 2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            var uiApp = commandData.Application;
            var doc   = uiApp.ActiveUIDocument.Document;

            // Obtain user confirmation
            var confirmation = new TaskDialog(Properties.Resources.DeleteBackups_MessageTitle)
            {
                MainIcon        = TaskDialogIcon.TaskDialogIconWarning,
                MainInstruction = Properties.Resources.DeleteBackups_MainInstruction
            };

            confirmation.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
                                        Properties.Resources.DeleteBackups_YesDelete,
                                        Properties.Resources.DeleteBackups_InstructionDescription);
            confirmation.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
                                        Properties.Resources.DeleteBackups_NoDontDelete);

            // Cancel if user hasn't explicitly clicked YES.
            if (confirmation.Show() != TaskDialogResult.CommandLink1)
            {
                return(Result.Cancelled);
            }

            try
            {
                FileInfo file;

                if (doc.PathName == string.Empty)
                {
                    throw new Exception(Properties.Resources.DeleteBackups_FileNotSavedException);
                }
                // Determine which document location to use.
                if (doc.IsWorkshared)
                {
                    var modelPathName = ModelPathUtils.ConvertModelPathToUserVisiblePath(doc.GetWorksharingCentralModelPath());
                    file = new FileInfo(modelPathName);
                }
                else
                {
                    file = new FileInfo(doc.PathName);
                }

                // Get all files from parent directory that match a regex pattern.
                var          parentDir    = file.Directory?.Parent;
                const string regexPattern = @".*\.\d{4}\.(rfa|rvt)";
                if (parentDir == null)
                {
                    return(Result.Succeeded);
                }
                var files = Directory.GetFiles(parentDir.FullName, "*.rfa", SearchOption.AllDirectories)
                            .Where(x => Regex.IsMatch(x, regexPattern)).ToList();

                var    familyCount  = 0;
                var    projectCount = 0;
                var    n            = files.Count;
                var    s            = "{0} of " + n + " Files processed...";
                string pfCaption    = Properties.Resources.DeleteBackups_ProgressFormTitle;
                using (var pf = new ProgressForm(pfCaption, s, n))
                {
                    pf.Show();
                    foreach (var f in files)
                    {
                        try
                        {
                            File.Delete(f);
                        }
                        catch
                        {
                            // ignored
                        }
                        pf.Increment();
                        if (f.Contains(".rvt"))
                        {
                            projectCount++;
                        }
                        if (f.Contains(".rfa"))
                        {
                            familyCount++;
                        }
                    }
                }
                TaskDialog.Show(Properties.Resources.DeleteBackups_MessageTitle,
                                string.Format("You have sucessfully deleted :" +
                                              Environment.NewLine +
                                              familyCount + " family backup files." +
                                              Environment.NewLine +
                                              projectCount + " project backup files"));
                return(Result.Succeeded);
            }
            catch (Exception x)
            {
                message = x.Message;
                return(Result.Failed);
            }
        }
Exemplo n.º 3
0
        internal void ParameterPopulate()
        {
            // UPDATE AFTER COLUMNS ADJUSTMENT
            parameterMap     = Parameters.parameterMap(num);
            parameterTypeMap = Parameters.parameterTypeMap(num);

            Dictionary <string, string> type = new Dictionary <string, string>();

            int n = projectDataArray.Count;

            string s       = "{0} of " + n.ToString() + " elements processed...";
            string caption = "Import from Excel";


            using (Transaction t = new Transaction(doc, "Import parameters"))
            {
                t.Start();

                using (ProgressForm pf = new ProgressForm(caption, s, n))
                {
                    foreach (string[] arr in projectDataArray)
                    {
                        Element el = null;

                        if (pf.getAbortFlag())
                        {
                            t.RollBack();
                            return;
                        }
                        pf.Increment();
                        try
                        {
                            el = doc.GetElement(arr[0]);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                        if (el == null)
                        {
                            continue;
                        }
                        try
                        {
                            for (int i = 1; i < parameterMap.Count - 2; i++)
                            {
                                string name = parameterMap[i];
                                if (Parameters.IsInsanceParameter(name, parameterTypeMap))
                                {
                                    Parameter p = el.LookupParameter(parameterMap[i]);
                                    if (p != null && !p.IsReadOnly)
                                    {
                                        p.Set(arr[i]);
                                    }
                                }
                                else
                                {
                                    type[String.Format("{0}:{1}", el.GetTypeId().IntegerValue.ToString(), parameterMap[i])] = arr[i];
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("Error", ex.Message);
                        }
                    }
                    t.Commit();
                }
            }
            using (Transaction t1 = new Transaction(doc, "Importe Type Parameters"))
            {
                t1.Start();

                n = type.Count;

                s = "{0} of " + n.ToString() + " type parameters processed...";

                using (ProgressForm pf = new ProgressForm(caption, s, n))
                {
                    foreach (var pair in type)
                    {
                        if (pf.getAbortFlag())
                        {
                            t1.RollBack();
                            return;
                        }
                        pf.Increment();

                        string[] sp = pair.Key.Split(':');
                        if (sp[0].Equals("-1"))
                        {
                            continue;
                        }
                        Element   el = doc.GetElement(new ElementId(Convert.ToInt32(sp[0])));
                        Parameter p  = el.LookupParameter(sp[1]);
                        if (p != null && !p.IsReadOnly)
                        {
                            p.Set(pair.Value);
                        }
                    }
                }
                t1.Commit();
            }
        }
Exemplo n.º 4
0
        internal void ParameterDispatcher()
        {
            CategorySet catSet = Utils.AssignableCategories(uiapp, doc);

            if (num > 0)
            {
                projectParameters = Parameters.ProjectData(num);
            }
            else
            {
                projectParameters = Parameters.ProjectData();
            }
            int catCounter = 0;

            // For each Category
            foreach (Category cat in catSet)
            {
                catCounter++;
                IList <Element> isntanceCollector = new FilteredElementCollector(doc).OfCategoryId(cat.Id).WhereElementIsNotElementType().ToElements();
                if (isntanceCollector.Count < 1)
                {
                    continue;
                }

                HashSet <string> unique = new HashSet <string>();

                string catName = cat.Name;

                int    n       = isntanceCollector.Count;
                string s       = "{0} of " + n.ToString() + String.Format(" elements of {0} category processed... .{1}/{2} cat.", catName, catCounter.ToString(), catSet.Size.ToString());
                string caption = "Exporting..";

                using (ProgressForm pf = new ProgressForm(caption, s, n))
                {
                    // For each element
                    foreach (Element el in isntanceCollector)
                    {
                        try
                        {
                            if (pf.getAbortFlag())
                            {
                                return;
                            }
                            pf.Increment();
                            List <string> elParameters = new List <string>();
                            Element       type         = doc.GetElement(el.GetTypeId());

                            if (num > 0)
                            {
                                elParameters.Add(el.UniqueId.ToString());
                            }

                            foreach (Tuple <string, string> tuple in projectParameters)
                            {
                                if (tuple.Item2.Equals("Instance"))
                                {
                                    Parameter p           = el.LookupParameter(tuple.Item1);
                                    string    emptyString = "  ";
                                    if (p != null && p.HasValue && !String.IsNullOrEmpty(p.AsString()))
                                    {
                                        emptyString = p.AsString();
                                    }
                                    elParameters.Add(emptyString);
                                }
                                else
                                {
                                    if (type == null)
                                    {
                                        elParameters.Add("No Type");
                                        continue;
                                    }
                                    Parameter p           = type.LookupParameter(tuple.Item1);
                                    string    emptyString = "  ";
                                    if (p != null && p.HasValue)
                                    {
                                        emptyString = p.AsString();
                                    }
                                    elParameters.Add(emptyString);
                                }
                            }
                            if (type == null)
                            {
                                elParameters.Add("No Type");
                            }
                            else
                            {
                                elParameters.Add(type.Name);
                            }
                            if (num > 0)
                            {
                                elParameters.Add(catName);
                                projectData.Add(elParameters);
                            }
                            if (num == 0)
                            {
                                if (unique.Add(elParameters.Aggregate((i, j) => i + "," + j)))
                                {
                                    projectData.Add(elParameters);
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        internal void BoQ()
        {
            CategorySet catSet = Utils.AssignableCategories(uiapp, doc);

            using (Transaction t = new Transaction(doc, "Modelling Tool Populate"))
            {
                int n = catSet.Size;

                string s       = "{0} of " + n.ToString() + " categories processed...";
                string caption = "BoQ";

                t.Start();
                int count = 0;
                using (ProgressForm pf = new ProgressForm(caption, s, n))
                {
                    foreach (Category cat in catSet)
                    {
                        if (pf.getAbortFlag())
                        {
                            break;
                        }
                        pf.Increment();
                        try
                        {
                            IList <Element> collector = new FilteredElementCollector(doc).OfCategoryId(cat.Id).WhereElementIsNotElementType().ToElements();
                            //IList<Element> collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements();
                            if (collector.Count < 1)
                            {
                                continue;
                            }
                            foreach (Element el in collector)
                            {
                                Parameter p      = el.LookupParameter("BoQ Codes, Units and Factors");
                                int       i      = 1;
                                string    name   = "";
                                string    second = "";
                                //Element type = doc.GetElement(el.GetTypeId());
                                while (el.LookupParameter(String.Format("Budget Code_{0}", i.ToString("00"))) != null)
                                {
                                    string a = el.LookupParameter(String.Format("Budget Code_{0}", i.ToString("00"))).AsString();
                                    string b = el.LookupParameter(String.Format("Unit_{0}", i.ToString("00"))).AsString();
                                    string c = el.LookupParameter(String.Format("Factor_{0}", i.ToString("00"))).AsString();
                                    if (!String.IsNullOrEmpty(c))
                                    {
                                        c = String.Format("({0})", c);
                                    }
                                    if (string.IsNullOrEmpty(a + b + c))
                                    {
                                        i++;
                                        continue;
                                    }
                                    name  += second;
                                    name  += String.Format("{0}_{1}{2}", a, b, c);
                                    second = "#";
                                    i++;
                                }

                                if (p != null && !p.IsReadOnly)
                                {
                                    p.Set(name);
                                }
                            }
                            count++;
                        }
                        catch (Exception)
                        {
                            //TaskDialog.Show("Failed", cat.Name + " : " + ex);
                        }
                    }
                }
                if (count == 0)
                {
                    TaskDialog.Show("Failed", "No elements with Modelling Tool parameter found in this document.");
                    t.RollBack();
                }
                t.Commit();
            }
        }
Exemplo n.º 6
0
        internal void WindowsAndDoorsHosts()
        {
            CategorySet catSet     = new CategorySet();
            Categories  categories = doc.Settings.Categories;

            Category doors   = categories.get_Item("Doors");
            Category windows = categories.get_Item("Windows");

            catSet.Insert(doors);
            catSet.Insert(windows);

            List <HostObject> hostObjects = new FilteredElementCollector(doc)
                                            .OfClass(typeof(Wall))
                                            .WhereElementIsNotElementType()
                                            .Cast <HostObject>()
                                            //.Where(x => x.FindInserts(false, false, false, false).Count > 0)
                                            .ToList();

            using (Transaction t = new Transaction(doc, "Window and Door Hosts Populate"))
            {
                t.Start();
                int count = 0;
                foreach (Category cat in catSet)
                {
                    try
                    {
                        IList <Element> collector = new FilteredElementCollector(doc).OfCategoryId(cat.Id).WhereElementIsNotElementType().ToElements();
                        if (collector.Count < 1)
                        {
                            continue;
                        }
                        int n = collector.Count;

                        string s       = "{0} of " + n.ToString() + " elements processed...";
                        string caption = cat.Name;

                        using (ProgressForm pf = new ProgressForm(caption, s, n))
                        {
                            foreach (Element el in collector)
                            {
                                if (pf.getAbortFlag())
                                {
                                    t.RollBack();
                                    return;
                                }
                                pf.Increment();
                                Parameter p = el.LookupParameter("Windows and Doors Host");

                                string hostName = "";

                                foreach (HostObject hostObject in hostObjects)
                                {
                                    IList <ElementId> ids = hostObject.FindInserts(false, false, false, false);
                                    if (ids.Contains(el.Id))
                                    {
                                        hostName = String.Format("{0}", (hostObject as Wall).WallType.Name);
                                        break;
                                    }
                                }
                                if (p != null && !p.IsReadOnly)
                                {
                                    p.Set(hostName);
                                }
                            }
                            count++;
                        }
                    }
                    catch (Exception)
                    {
                        //TaskDialog.Show("Failed", cat.Name + " : " + ex);
                    }
                }


                if (count == 0)
                {
                    TaskDialog.Show("Windows And Doors Hosts failed to execute.", "No Windows or Door elements with Modelling Tool parameter found in this document.");
                    t.RollBack();
                    return;
                }
                t.Commit();
            }
        }