Beispiel #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            #region Is family document?
            if (doc.IsFamilyDocument)
            {
                UI.Info.Form_Info1.infoMsgMain = "Wrong document";
                UI.Info.Form_Info1.infoMsgBody = "This is a family document.\nRun this tool in a project document.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }
            #endregion

            using (UI.Form_Main thisForm = new UI.Form_Main(doc, app))
            {
                thisForm.ShowDialog();
                if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }
            }

            return(Result.Succeeded);
        }
Beispiel #2
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = commandData.Application.ActiveUIDocument.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            // check if there are unused text note types and show a message if there aren´t
            if (!Helpers.GetUnusedTextNoteTypes(doc).Any())
            {
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return(Result.Succeeded);
            }

            // else, open up windows form
            else
            {
                using (TextNotesForm thisForm = new TextNotesForm(doc, app))
                {
                    thisForm.ShowDialog();
                    if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return(Result.Cancelled);
                    }
                }

                return(Result.Succeeded);
            }
        }
Beispiel #3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = commandData.Application.ActiveUIDocument.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            // is family document
            if (doc.IsFamilyDocument)
            {
                UI.Info.Form_Info1.infoMsgMain = "Wrong document";
                UI.Info.Form_Info1.infoMsgBody = "This is a family document.\nRun this tool in a project document.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }

            // are there other projects open?
            if (Data.Helpers.GetOpenDocuments(doc, app).Count() == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Project not found";
                UI.Info.Form_Info1.infoMsgBody = "There are not other project documents open in this session.\nThis application will close.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }

            // open main form
            using (Form.Form_Main thisForm = new Form.Form_Main(doc, app))
            {
                thisForm.ShowDialog();
                if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }
            }
            //try
            //{
            //    Utilities.GetAnalyticsCSV(doc, app);
            //}
            //catch (Exception)
            //{
            //}
            return(Result.Succeeded);
        }
Beispiel #4
0
        private void LsvFilters_ItemCheck(Object sender, ItemCheckEventArgs e)
        {
            ListViewItem selectedItem = LsvFilters.Items[e.Index];

            foreach (ListViewItem item in LsvFilters.CheckedItems)
            {
                if (item != selectedItem && item.Text == selectedItem.Text)
                {
                    UI.Info.Form_Info1.infoMsgMain = "Duplicated Selection";
                    UI.Info.Form_Info1.infoMsgBody = "This filter is already selected in another template." +
                                                     "\nYou can only select a filter once." +
                                                     "\nThis filter will be unchecked.";
                    using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                    {
                        thisForm.ShowDialog();
                    }
                    e.NewValue = CheckState.Unchecked;
                }
            }
        }
Beispiel #5
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = commandData.Application.ActiveUIDocument.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            //first check if there are any filters in the document
            //if there are not, show a message and close the command
            if (!Helpers.GetUnusedFilterElem(doc).Any())
            {
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return(Result.Cancelled);
                    }
                }
                return(Result.Succeeded);
            }
            //if there are, open the form
            else
            {
                //using windows form
                using (ViewFiltersForm thisForm = new ViewFiltersForm(doc, app))
                {
                    thisForm.ShowDialog();
                    if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return(Result.Cancelled);
                    }
                }

                return(Result.Succeeded);
            }
        }
Beispiel #6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            if (!GetSelectedDoors(uidoc).Any() && !GetSelectedWalls(uidoc).Any())
            {
                infoMsgMain = "Select";
                infoMsgBody = "You need to select walls or doors before executing the application";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }

                return(Result.Cancelled);
            }

            using (Form.Main_Form thisForm = new Form.Main_Form(doc, uidoc, app))
            {
                thisForm.ShowDialog();
                if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }
            }
            //try
            //{
            //    Utilities.GetAnalyticsCSV(doc, app);
            //}
            //catch (Exception)
            //{
            //}

            return(Result.Succeeded);
        }
Beispiel #7
0
        } = 0;                                                      // number of schedules exported
        #endregion

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            #region variables
            UIApplication uiapp = commandData.Application;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            // element selection
            ICollection <ElementId> selIds = uidoc.Selection.GetElementIds();

            // excel export settings
            ViewScheduleExportOptions export_options = new ViewScheduleExportOptions();

            // paths to check Excel install
            string excelPaths_FileName = "OpenInExcel_UserPaths.txt";
            string assemblyPath        = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string excelPaths_FilePath = Path.Combine(assemblyPath, excelPaths_FileName);

            // paths to export schedule
            string temp_folder = Path.GetTempPath();
            #endregion

            // check if file exists
            if (!Data.Helpers.CheckFileExists(excelPaths_FilePath))
            {
                warningMsgMain = "File missing";
                warningMsgBody = string.Format("Could not find the File: {0}{0}{1} in {2}{0}{0}Contact [email protected] for help.",
                                               Environment.NewLine,
                                               excelPaths_FileName,
                                               assemblyPath);
                using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning())
                {
                    thisForm.ShowDialog();
                }
                return(Result.Cancelled);
            }

            // check if excel is installed in usual paths
            if (!Data.Helpers.CheckExcelInstall(excelPaths_FilePath))
            {
                warningMsgMain = "Excel not found";
                warningMsgBody = string.Format("Could not find Excel installed in the usual paths.{0}{0}" +
                                               "Please install Excel or add your Excel path to the OpenInExcel_UserPaths.txt " +
                                               "(located in {1}) and try again.{0}{0}" +
                                               "Contact [email protected] for help.", Environment.NewLine, assemblyPath);

                using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning())
                {
                    thisForm.ShowDialog();
                }
                return(Result.Cancelled);
            }

            // if there are not schedules selected or open throw a message
            if (!Data.Helpers.GetSelectedSchedules(doc, selIds).Any())
            {
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return(Result.Cancelled);
            }

            // go ahead and export the selected schedules
            if (Data.Helpers.GetSelectedSchedules(doc, selIds).Any())
            {
                // start counters. For this application Use Time and Execution time will be the same.
                useTime.Start();

                Random randomNumber = new Random();

                // create excel name with schedule name + random number
                foreach (View v in Data.Helpers.GetSelectedSchedules(doc, selIds))
                {
                    Ana_NoOfExports += 1;   // count number of schedules exported

                    string scheduleName       = Data.Helpers.ReplaceIllegalCharaters(v.Name);
                    string txtFileName        = scheduleName + "_" + randomNumber.Next(1000) + ".txt";
                    string scheduleExportPath = Path.Combine(temp_folder, txtFileName);

                    // export schedule to .txt
                    ViewSchedule viewSchedule = v as ViewSchedule;
                    viewSchedule.Export(temp_folder, txtFileName, export_options);

                    // open .txt schedule with excel
                    Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
                    excelApp.Visible = true; // make the running excel instance visible
                    Workbook wb = excelApp.Workbooks.Open(scheduleExportPath);
                }
                useTime.Stop();
                UseTimeElapseS  = useTime.Elapsed.Seconds.ToString();
                ExecTimeElapseS = UseTimeElapseS;
            }
            //try
            //{
            //    Utilities.GetAnalyticsCSV(doc, app);
            //    Data.Helpers.ScheduleToExcelAnalytics(doc, app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfExports);
            //}
            //catch (Exception)
            //{
            //}
            return(Result.Succeeded);
        }
Beispiel #8
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            if (RbtFlipHand.Checked == false && RbtFlipFacing.Checked == false && RbtFlipWalls.Checked == false)
            {
                infoMsgMain = "Choose option";
                infoMsgBody = "You need to choose an option in order to flip.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
            }

            if (RbtFlipHand.Checked == true)
            {
                if (!GetSelectedDoors(m_uidoc).Any())
                {
                    infoMsgMain = "Select";
                    infoMsgBody = "You need to select a door.";
                    using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                }
                else
                {
                    executionTime.Start();      // collect data for analytics

                    IList <FamilyInstance> doorInstances = GetSelectedDoors(m_uidoc).Cast <FamilyInstance>().ToList();
                    elemTry     = doorInstances.Count();
                    elemSuccess = 0;
                    elemFail    = 0;
                    using (Transaction t = new Transaction(m_doc, "Flip Door Hand"))
                    {
                        t.Start();
                        try
                        {
                            foreach (FamilyInstance fi in doorInstances)
                            {
                                fi.flipHand();
                                elemSuccess += 1;
                            }
                        }
                        catch (Exception)
                        {
                            elemFail += 1;
                        }
                        t.Commit();
                    }
                    executionTime.Stop();                                       // collect data for analytics
                    ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); // collect data for analytics

                    // show Results Form
                    using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()){ thisForm.ShowDialog(); }

                    DialogResult = DialogResult.OK;

                    useTime.Stop();
                    UseTimeElapseS       = useTime.Elapsed.Seconds.ToString();                                                // collect data for analytics
                    Ana_NoOfFlippedDoors = elemSuccess;                                                                       // collect data for analytics
                    Utilities.GetAnalyticsCSV(m_doc, m_app);                                                                  // collect data for analytics
                    FlipAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFlippedWalls, Ana_NoOfFlippedDoors); // collect data for analytics
                }
            }

            if (RbtFlipFacing.Checked == true)
            {
                if (!GetSelectedDoors(m_uidoc).Any())
                {
                    infoMsgMain = "Select";
                    infoMsgBody = "You need to select one or more doors.";
                    using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                }
                else
                {
                    executionTime.Start();      // collect data for analytics

                    IList <FamilyInstance> doorInstances = GetSelectedDoors(m_uidoc).Cast <FamilyInstance>().ToList();
                    elemTry     = doorInstances.Count();
                    elemSuccess = 0;
                    elemFail    = 0;
                    using (Transaction t = new Transaction(m_doc, "Flip Door Facing"))
                    {
                        t.Start();
                        try
                        {
                            foreach (FamilyInstance fi in doorInstances)
                            {
                                fi.flipFacing();
                                elemSuccess += 1;
                            }
                        }
                        catch (Exception)
                        {
                            elemFail += 1;
                        }
                        t.Commit();
                    }
                    executionTime.Stop();                                       // collect data for analytics
                    ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); // collect data for analytics

                    // show Results Form
                    using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); }

                    DialogResult = DialogResult.OK;

                    useTime.Stop();
                    UseTimeElapseS       = useTime.Elapsed.Seconds.ToString();                                                // collect data for analytics
                    Ana_NoOfFlippedDoors = elemSuccess;                                                                       // collect data for analytics
                    Utilities.GetAnalyticsCSV(m_doc, m_app);                                                                  // collect data for analytics
                    FlipAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFlippedWalls, Ana_NoOfFlippedDoors); // collect data for analytics
                }
            }

            if (RbtFlipWalls.Checked == true)
            {
                if (!GetSelectedWalls(m_uidoc).Any())
                {
                    infoMsgMain = "Select";
                    infoMsgBody = "You need to select one or more walls.";
                    using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                }
                else
                {
                    executionTime.Start();      // collect data for analytics

                    IList <Wall> wallInstances = GetSelectedWalls(m_uidoc).Cast <Wall>().ToList();
                    elemTry     = wallInstances.Count();
                    elemSuccess = 0;
                    elemFail    = 0;

                    using (TransactionGroup tg = new TransactionGroup(m_doc, "Flip Walls"))
                    {
                        tg.Start();
                        foreach (Wall w in wallInstances)
                        {
                            try
                            {
                                Parameter loc_line     = w.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM);
                                int       currentValue = loc_line.AsInteger();
                                using (Transaction t = new Transaction(m_doc, "Change Location Line"))
                                {
                                    t.Start();
                                    loc_line.Set(0);
                                    t.Commit();
                                }
                                using (Transaction t = new Transaction(m_doc, "Flip the wall"))
                                {
                                    t.Start();
                                    w.Flip();
                                    elemSuccess += 1;
                                    loc_line.Set(currentValue);
                                    t.Commit();
                                }
                            }
                            catch (Exception)
                            {
                                elemFail += 1;
                            }
                        }
                        tg.Assimilate();
                    }
                    executionTime.Stop();                                       // collect data for analytics
                    ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); // collect data for analytics

                    // show Results Form
                    using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); }

                    DialogResult = DialogResult.OK;

                    useTime.Stop();
                    UseTimeElapseS       = useTime.Elapsed.Seconds.ToString();                                                // collect data for analytics
                    Ana_NoOfFlippedWalls = elemSuccess;
                    Utilities.GetAnalyticsCSV(m_doc, m_app);                                                                  // collect data for analytics
                    FlipAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFlippedWalls, Ana_NoOfFlippedDoors); // collect data for analytics
                }
            }
        }
Beispiel #9
0
        private void BtnAddParameters_Click(object sender, EventArgs e)
        {
            #region get all checked parameters
            List <Definition> defList = new List <Definition>();
            foreach (TreeNode n1 in TreeViewParameters.Nodes)
            {
                foreach (TreeNode n2 in n1.Nodes)
                {
                    if (n2.Checked == true)
                    {
                        defList.Add(n2.Tag as Definition);
                    }
                }
            }
            #endregion

            #region get all checked categories
            List <Category> catList = new List <Category>();
            if (m_doc.IsFamilyDocument == true)
            {
                catList.Add(m_doc.OwnerFamily.FamilyCategory);
            }
            else
            {
                foreach (TreeNode c in TreeViewCategories.Nodes)
                {
                    if (c.Checked == true)
                    {
                        catList.Add(c.Tag as Category);
                    }
                }
            }
            #endregion

            // Check if selected: Shared Parameter FILE, Parameters and Categories
            if (m_app.OpenSharedParameterFile() == null
                | defList.Count == 0
                | catList.Count == 0)
            {
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }

            // Load parameters
            else
            {
                // get parameter group
                KeyValuePair <BuiltInParameterGroup, string> groupKeyValuePair = (KeyValuePair <BuiltInParameterGroup, string>)CbxGroup.SelectedItem;
                BuiltInParameterGroup group = groupKeyValuePair.Key;

                // Bind the Definitions
                Data.Helpers.BindDefinitionsToCategories(m_doc,
                                                         m_app,
                                                         defList,
                                                         catList,
                                                         group,
                                                         RbtInstance.Checked);
                // show Results Form
                using (UI.Info.Form_Results thisForm = new Info.Form_Results())
                {
                    thisForm.ShowDialog();
                }

                // show form Do you want to load more parameters?
                using (UI.Info.Form_Info2 thisForm = new UI.Info.Form_Info2())
                {
                    thisForm.ShowDialog();
                    if (thisForm.DialogResult == DialogResult.No)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }

                // uncheck parameters
                foreach (TreeNode n in TreeViewParameters.Nodes) // parents
                {
                    n.Checked = false;

                    foreach (TreeNode c in n.Nodes) // children
                    {
                        c.Checked = false;
                    }
                }
                // uncheck categories
                foreach (TreeNode n in TreeViewCategories.Nodes)
                {
                    n.Checked = false;
                }
            }
        }
Beispiel #10
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            // handle error if no data is selected
            if (CbxCategories.SelectedItem == null)
            {
                // show Wrong Selection form
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }
            else
            {
                Category cat = CbxCategories.SelectedItem as Category;
                elemTry = GetInstances(m_doc, cat).Count();

                KeyValuePair <Parameter, string> targetKeyValuePair = (KeyValuePair <Parameter, string>)CbxTargetParameters.SelectedItem;

                Parameter targetParam = targetKeyValuePair.Key;

                using (TransactionGroup tg = new TransactionGroup(m_doc, "Parameter Mapper"))
                {
                    tg.Start();
                    // for each element of the selected category
                    foreach (Element elem in GetInstances(m_doc, cat))
                    {
                        using (Transaction t = new Transaction(m_doc, "Parameter Mapper Single Transaction"))
                        {
                            t.Start();
                            try
                            {
                                Parameter elemTargetParam = elem.get_Parameter(targetParam.Definition);

                                if (RbtElementId.Checked == true) // when Element Id is selected
                                {
                                    string eId = elem.Id.ToString();
                                    elemTargetParam.Set(eId);
                                    t.Commit();
                                }
                                else if (RbtSourceParam.Checked == true && RbtAsText.Checked == true) // when "Number As Text" is selected
                                {
                                    KeyValuePair <Parameter, string> sourceKeyValuePair = (KeyValuePair <Parameter, string>)CbxSourceParameters.SelectedItem;
                                    Parameter sourceParam     = sourceKeyValuePair.Key;
                                    Parameter elemSourceParam = elem.get_Parameter(sourceParam.Definition);

                                    string sourceValueString = GetParamValueAsString(elemSourceParam);
                                    elemTargetParam.Set(sourceValueString);
                                    t.Commit();
                                }
                                else // when "Number As Number" is selected
                                {
                                    KeyValuePair <Parameter, string> sourceKeyValuePair = (KeyValuePair <Parameter, string>)CbxSourceParameters.SelectedItem;
                                    Parameter sourceParam     = sourceKeyValuePair.Key;
                                    Parameter elemSourceParam = elem.get_Parameter(sourceParam.Definition);

                                    if (elemSourceParam.StorageType != StorageType.Double)
                                    {
                                        string sourceValueString = GetParamValueAsString(elemSourceParam);
                                        elemTargetParam.Set(sourceValueString);
                                        t.Commit();
                                    }
                                    else
                                    {
                                        if (RbtAsNumber.Checked == true)
                                        {
                                            double sourceValueDouble = elemSourceParam.AsDouble();
                                            elemTargetParam.Set(sourceValueDouble);
                                            t.Commit();
                                        }
                                        else
                                        {
                                            string sourceValueString = GetParamValueAsString(elemSourceParam);
                                            elemTargetParam.Set(sourceValueString);
                                            t.Commit();
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                elemFail += 1;
                            }
                        }
                    }
                    tg.Assimilate();
                }

                using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results())
                {
                    thisForm.ShowDialog();
                }
                DialogResult = DialogResult.OK;
            }
        }
Beispiel #11
0
        private void BtnDuplicate_Click(object sender, EventArgs e)
        {
            // reset viewport counter
            Ana_NoOfViewports = 0;

            // get number of copies
            int copies = Convert.ToInt32(NumOfCopies.Value);

            // set Dependent views Duplicate Option
            ViewDuplicateOption dependentOption = ViewDuplicateOption.AsDependent;

            if (CbxDependent.Checked != true)
            {
                dependentOption = ViewDuplicateOption.WithDetailing;
            }

            // is there at least one item selected?
            if (LsvSheets.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Select one sheet to continue.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }

            // proceed with duplication
            else
            {
                executionTime.Start(); // start execution time counter

                // collect selected sheets, for multiple selection
                List <string>    selSheetsTxt  = new List <string>();
                List <ViewSheet> allViewSheets = Data.Helpers.GetViewSheets(m_doc);
                foreach (ListViewItem lv in LsvSheets.CheckedItems)
                {
                    selSheetsTxt.Add(lv.SubItems[0].Text);
                }
                List <ViewSheet> selViewSheets = Data.Helpers.GetSelectedSheets(allViewSheets, selSheetsTxt);
                // currently multiple selection is not allowed, so take just one item
                ViewSheet sourceSheet = selViewSheets.First();
                Ana_SheetNumber = sourceSheet.SheetNumber;
                Ana_SheetName   = sourceSheet.Name;
                Ana_NoOfCopies  = copies;

                DuplicateSheets(m_doc, sourceSheet, copies, dependentOption);

                transactionMade = true; // to trigger stopwatch stop in other methods
                executionTime.Stop();   // stop execution time counter
                ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString();

                #region show Results Form
                resultHead = "Results";
                resultMain = string.Format("You have made {0} copies of:{1}{1}'{2}'", copies, Environment.NewLine, sourceSheet.Name);
                resultBody = string.Format("NOTE: A suffix 'DupX' has been added to the view names.{0}" +
                                           "Please, rename the views appropriately.", Environment.NewLine);
                ;                using (UI.Info.Form_Results thisForm = new Info.Form_Results())
                {
                    thisForm.ShowDialog();
                    if (thisForm.DialogResult == DialogResult.No)
                    {
                        useTime.Stop();
                        UseTimeElapseS = useTime.Elapsed.Seconds.ToString();
                        Utilities.GetAnalyticsCSV(m_doc, m_app);
                        Data.Helpers.DuplicateSheetsAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfCopies, Ana_NoOfViewports, Ana_SheetNumber, Ana_SheetName);

                        DialogResult = DialogResult.OK;
                    }
                    if (thisForm.DialogResult == DialogResult.Yes)
                    {
                        LoadSheets();
                        // get analytics data
                        useTime.Stop();
                        UseTimeElapseS = useTime.Elapsed.Seconds.ToString();
                        Utilities.GetAnalyticsCSV(m_doc, m_app);
                        Data.Helpers.DuplicateSheetsAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfCopies, Ana_NoOfViewports, Ana_SheetNumber, Ana_SheetName);
                        useTime.Restart();    // reset use time and start time counter again
                    }
                }
                #endregion
            }
        }
Beispiel #12
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            CopyPasteOptions copyOpt          = new CopyPasteOptions();
            Document         sourceDoc        = CbxOpenDocs.SelectedItem as Document;
            List <ElementId> templatesToCopy  = new List <ElementId>();
            List <string>    duplicatedNames  = new List <string>();
            List <string>    transferredViews = new List <string>();

            // is there at least one item selected?
            if (ClbTemplates.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more View Templates to continue.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
            }

            // proceed to transfer
            try
            {
                foreach (Autodesk.Revit.DB.View v in ClbTemplates.CheckedItems)
                {
                    templatesToCopy.Add(v.Id);
                    transferredViews.Add(v.Name);

                    // get duplicated names
                    if (GetViewTemplateNames(m_doc).Contains(v.Name))
                    {
                        duplicatedNames.Add(v.Name);
                    }
                }
                // show message if there are duplicated names
                if (duplicatedNames.Any())
                {
                    resultHead = "Information";
                    resultMain = "The following templates already exist or have the same name:";
                    resultBody = duplicatedNames;
                    // show message if there are duplicates
                    using (UI.Info.Form_DupResults thisForm = new UI.Info.Form_DupResults())
                    {
                        thisForm.ShowDialog();

                        // transfer view templates y pressed 'Yes'
                        if (thisForm.DialogResult == DialogResult.Yes)
                        {
                            using (Transaction t = new Transaction(m_doc, "Transfer View Templates"))
                            {
                                t.Start();
                                ElementTransformUtils.CopyElements(sourceDoc, templatesToCopy, m_doc, Transform.Identity, copyOpt);
                                t.Commit();
                            }
                            // show Results Form
                            resultHead = "Result";
                            resultMain = "The following View Templates have been transferred:";
                            resultBody = transferredViews;
                            using (UI.Info.Form_Results ResultForm = new UI.Info.Form_Results())
                            {
                                ResultForm.ShowDialog();
                            }
                            DialogResult = DialogResult.OK;
                        }
                    }
                }
                // go ahead if no duplicates
                else
                {
                    using (Transaction t = new Transaction(m_doc, "Transfer View Templates"))
                    {
                        t.Start();
                        ElementTransformUtils.CopyElements(sourceDoc, templatesToCopy, m_doc, Transform.Identity, copyOpt);
                        t.Commit();
                    }
                    // show Results Form
                    resultHead = "Result";
                    resultMain = "The following View Templates have been transferred:";
                    resultBody = transferredViews;
                    using (UI.Info.Form_Results ResultForm = new UI.Info.Form_Results())
                    {
                        ResultForm.ShowDialog();
                    }
                    DialogResult = DialogResult.OK;
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #13
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            // show message if both boxes are unchecked
            if (!CbxRoomCentroid.Checked && !CbxRoomTag.Checked)
            {
                infoMsgMain = "Hey!";
                infoMsgBody = "Choose an action from the menu.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }

            // show message if there are neither tags not rooms
            if ((CbxRoomCentroid.Checked || CbxRoomTag.Checked) &&
                !Data.Helpers.GetModelRooms(m_doc).Any() &&
                !Data.Helpers.GetModelRoomTags(m_doc).Any() &&
                !Data.Helpers.GetLinkRoomTags(m_doc).Any())
            {
                // show dialog
                infoMsgMain = "Missing elements";
                infoMsgBody = "There are not placed rooms or room tags in this project.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                Close();
            }

            else // if there are tags or rooms
            {
                if (CbxRoomCentroid.Checked)
                {
                    if (RbtProject.Checked)                           // if "Entire Project" is checked
                    {
                        if (!Data.Helpers.GetModelRooms(m_doc).Any()) // show message if there are no rooms
                        {
                            // show dialog
                            infoMsgMain = "Missing elements";
                            infoMsgBody = "There are not placed rooms in this project.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            Close();
                        }
                        else // move room insertion point to centroid
                        {
                            using (Transaction t = new Transaction(m_doc, "Room Insertion Point to Centroid"))
                            {
                                t.Start();
                                Data.Helpers.MoveRoomToCentroid(m_doc, Data.Helpers.GetModelRooms(m_doc));
                                t.Commit();
                            }
                            // show dialog
                            infoMsgMain = "Result";
                            infoMsgBody = "Room location points have been moved to centroid.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            DialogResult = DialogResult.OK;
                        }
                    }

                    if (RbtActiveView.Checked)                               // if "Active View" is checked
                    {
                        if (!Data.Helpers.GetModelRoomsActView(m_doc).Any()) // show message if there are no rooms in active view
                        {
                            // show dialog
                            infoMsgMain = "Missing elements";
                            infoMsgBody = "There are not placed rooms in this view.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            Close();
                        }
                        else // move room insertion point to centroid
                        {
                            using (Transaction t = new Transaction(m_doc, "Room Insertion Point to Centroid"))
                            {
                                t.Start();
                                Data.Helpers.MoveRoomToCentroid(m_doc, Data.Helpers.GetModelRoomsActView(m_doc));
                                t.Commit();
                            }
                            // show dialog
                            infoMsgMain = "Result";
                            infoMsgBody = "Room location points have been moved to centroid.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            DialogResult = DialogResult.OK;
                        }
                    }
                }

                if (CbxRoomTag.Checked)
                {
                    if (RbtActiveView.Checked)                                  // if "Active View" is checked
                    {
                        if (!Data.Helpers.GetModelRoomTagsActView(m_doc).Any()) // show message if there are no tags
                        {
                            // show dialog
                            infoMsgMain = "Missing elements";
                            infoMsgBody = "There are not room tags in this active view, or they are tagging rooms from a linked model.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            Close();
                        }
                        else // move tag to room insertion point
                        {
                            using (Transaction t = new Transaction(m_doc, "Tags to Room Insertion Point"))
                            {
                                t.Start();
                                Data.Helpers.MoveModelTags(m_doc, Data.Helpers.GetModelRoomTagsActView(m_doc));
                                t.Commit();
                            }
                            // show dialog
                            infoMsgMain = "Result";
                            infoMsgBody = "Room tags have been moved to room location point.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            DialogResult = DialogResult.OK;
                        }
                    }

                    if (RbtProject.Checked)                                 // if "Entire Project" is checked
                    {
                        if (CbxLinkedRoomTag.Checked && CbxRoomTag.Checked) // if "Include tags of linked rooms" is checked
                        {
                            if (!Data.Helpers.GetLinkRoomTags(m_doc).Any())
                            {
                                // show dialog
                                infoMsgMain = "Missing elements";
                                infoMsgBody = "There are not room tags tagging linked rooms in the model.";
                                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                            }
                            else // move all tags
                            {
                                using (Transaction t = new Transaction(m_doc, "Tags to Room Insertion Point"))
                                {
                                    t.Start();
                                    Data.Helpers.MoveModelTags(m_doc, Data.Helpers.GetModelRoomTags(m_doc)); // move model tags
                                    // show dialog
                                    infoMsgMain = "Result";
                                    infoMsgBody = "Room tags have been moved to room location point.";
                                    using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                                    try
                                    {
                                        foreach (RoomTag rt in Data.Helpers.GetLinkRoomTags(m_doc)) // move linked tags
                                        {
                                            Data.Helpers.MoveLinkTags(m_doc, rt);
                                        }
                                        // show dialog
                                        infoMsgMain = "Result";
                                        infoMsgBody = "Tags of linked rooms have been moved to room insertion point.";
                                        using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                                    }
                                    catch (Exception)
                                    {
                                        // show dialog
                                        warningMsgMain = "For your information";
                                        warningMsgBody = string.Format("Some tags of linked rooms were not moved " +
                                                                       "because one or more links containing tagged rooms are unloaded.{0}{0}" +
                                                                       "Please, reload links and try again.", Environment.NewLine);
                                        using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); }
                                        DialogResult = DialogResult.Cancel;
                                    }
                                    t.Commit();
                                }
                                DialogResult = DialogResult.OK;
                            }
                        }

                        if (!CbxLinkedRoomTag.Checked) // if "Include tags of linked rooms" is unchecked
                        {
                            if (!Data.Helpers.GetModelRoomTags(m_doc).Any())
                            {
                                // show dialog
                                infoMsgMain = "Missing elements";
                                infoMsgBody = "There are not room tags in the model, or they are tagging rooms from a linked model.";
                                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }

                                Close();
                            }
                            else // move model tags
                            {
                                using (Transaction t = new Transaction(m_doc, "Tags to Room Insertion Point"))
                                {
                                    t.Start();
                                    Data.Helpers.MoveModelTags(m_doc, Data.Helpers.GetModelRoomTags(m_doc));
                                    t.Commit();
                                }
                                // show dialog
                                infoMsgMain = "ResultAA";
                                infoMsgBody = "Room tags have been moved to room insertion point.";
                                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }

                                DialogResult = DialogResult.OK;
                            }
                        }
                    }
                }
            }
        }
Beispiel #14
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = commandData.Application.ActiveUIDocument.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            #region Is family document?
            if (doc.IsFamilyDocument)
            {
                UI.Info.Form_Info1.infoMsgMain = "Wrong document";
                UI.Info.Form_Info1.infoMsgBody = "This is a family document.\nRun this tool in a project document.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }
            #endregion

            // check if document is workshared
            if (!doc.IsWorkshared)
            {
                UI.Info.Form_Info1.infoMsgMain = "Worksharing?";
                UI.Info.Form_Info1.infoMsgBody = "This document is not workshared." + Environment.NewLine
                                                 + "Activate 'Collaborate' to enable collaboration and workset creation.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }

            //check if open document are workshared
            if (!GetOpenDocuments(doc, app).Any())
            {
                UI.Info.Form_Info1.infoMsgMain = "Worksharing?";
                UI.Info.Form_Info1.infoMsgBody = "None of the other open documents in this session are Workshared." + Environment.NewLine
                                                 + "This application will close.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }

            using (UI.Form_Main thisForm = new UI.Form_Main(doc, app))
            {
                thisForm.ShowDialog();
                if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }
            }
            //try
            //{
            //    Utilities.GetAnalyticsCSV(doc, app);
            //}
            //catch (Exception)
            //{
            //}
            return(Result.Succeeded);
        }
Beispiel #15
0
        private void BtnCreate_Click(object sender, EventArgs e)
        {
            #region check Sheet Set Name entered?
            if (TxbSetName.Text == "")
            {
                UI.Info.Form_Info1.infoMsgMain = "Value missing";
                UI.Info.Form_Info1.infoMsgBody = "Please, enter Sheet Set Name to continue.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return;
            }
            #endregion// check if the user entered a Set Name

            #region check if new print set name exists
            // get new sheet set name
            string sheetSetName = TxbSetName.Text;

            // collect existing view sheet sets
            List <Element> existingViewSheetSet = new FilteredElementCollector(m_doc)
                                                  .OfClass(typeof(ViewSheetSet))
                                                  .WhereElementIsNotElementType()
                                                  .ToElements()
                                                  .ToList();
            Dictionary <Element, string> existingVSSDict = new Dictionary <Element, string>();
            foreach (Element el in existingViewSheetSet)
            {
                existingVSSDict.Add(el, el.Name);
            }
            if (existingVSSDict.ContainsValue(sheetSetName))
            {
                UI.Info.Form_Info1.infoMsgMain = "Duplicated name";
                UI.Info.Form_Info1.infoMsgBody = "You have chosen a Sheet Set Name that already exists.\nPlease enter a different name.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return;
            }
            #endregion

            #region check sheets selected?
            if (LsvSheets.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Please, select one or more sheets to continue.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return;
            }
            #endregion

            #region create Sheet Set
            // collect selected sheets
            List <string>    selSheetsTxt  = new List <string>();
            List <ViewSheet> allViewSheets = Data.Helpers.GetViewSheets(m_doc);
            foreach (ListViewItem lv in LsvSheets.CheckedItems)
            {
                selSheetsTxt.Add(lv.SubItems[0].Text);
            }
            List <ViewSheet> selViewSheets = Data.Helpers.GetSelectedSheets(allViewSheets, selSheetsTxt);
            using (Transaction t = new Transaction(m_doc, "Create New Sheet Set"))
            {
                t.Start();
                PrintManager printManager = m_doc.PrintManager;
                printManager.PrintRange = PrintRange.Select;
                ViewSheetSetting existingPrintSets = printManager.ViewSheetSetting;

                // create ViewSet
                ViewSet myViewSet = new ViewSet();
                foreach (ViewSheet vs in selViewSheets)
                {
                    myViewSet.Insert(vs);
                }

                existingPrintSets.CurrentViewSheetSet.Views = myViewSet;
                existingPrintSets.SaveAs(sheetSetName);
                t.Commit();
            }
            #endregion

            #region show Results Form
            UI.Info.Form_Info1.infoMsgMain = "Results";
            UI.Info.Form_Info1.infoMsgBody = $"A new Sheet Set '{sheetSetName}' has been added to the project.";
            using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); }
            #endregion

            DialogResult = DialogResult.OK;
        }
Beispiel #16
0
        private void RbtSourceParam_CheckedChanged(object sender, EventArgs e)
        {
            if (CbxCategories.SelectedItem == null)
            {
                // show Wrong Selection form
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }
            else
            {
                ClearComboBox(CbxTargetParameters);
                ClearComboBox(CbxSourceParameters);

                Category cat = CbxCategories.SelectedItem as Category;

                if (RbtElementId.Checked)
                {
                    LblParamTypeSource.Text     = "Element Id will always be transferred as Text";
                    CbxSourceParameters.Enabled = false; // disable source parameter combo box

                    try
                    {
                        PopulateTargetComboBoxTextParams(CbxTargetParameters, m_doc, cat);
                        SetTypeParameterLabel(LblParamTypeTarget, CbxTargetParameters);
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (RbtAsText.Checked)
                {
                    LblParamTypeSource.Text     = "";
                    CbxSourceParameters.Enabled = true;

                    PopulateSourceComboBox(CbxSourceParameters, m_doc, cat);
                    SetTypeParameterLabel(LblParamTypeSource, CbxSourceParameters);

                    try
                    {
                        PopulateTargetComboBoxTextParams(CbxTargetParameters, m_doc, cat);
                        SetTypeParameterLabel(LblParamTypeTarget, CbxTargetParameters);
                    }
                    catch (Exception)
                    {
                    }
                }
                else // reload source parameters
                {
                    LblParamTypeSource.Text     = "";
                    CbxSourceParameters.Enabled = true;

                    PopulateSourceComboBox(CbxSourceParameters, m_doc, cat);
                    SetTypeParameterLabel(LblParamTypeSource, CbxSourceParameters);

                    try // reload target parameters
                    {
                        PopulateTargetComboBox(CbxSourceParameters, CbxTargetParameters, m_doc, cat);
                        SetTypeParameterLabel(LblParamTypeTarget, CbxTargetParameters);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Beispiel #17
0
        public static int countFail = 0;                            // number of elements failed

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = commandData.Application.ActiveUIDocument.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            #region check if it is family document
            if (doc.IsFamilyDocument)
            {
                using (UI.Form_Info3 thisForm = new UI.Form_Info3())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }
            #endregion

            #region warn the user if he wants to proceed
            using (UI.Warning.Form_Warning thisForm = new UI.Warning.Form_Warning())
            {
                thisForm.ShowDialog();
                if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }
            }
            #endregion

            #region remove elevation tags
            using (TransactionGroup tg = new TransactionGroup(doc, "Remove Elevation Tags"))
            {
                tg.Start();
                count = 0; // reset the counter for when the app is run more than once
                foreach (Element e in new FilteredElementCollector(doc)
                         .OfClass(typeof(ElevationMarker))
                         .WhereElementIsNotElementType()
                         .ToElements())
                {
                    ElevationMarker em = e as ElevationMarker;

                    // only proceed with empty elevation marks
                    if (em.HasElevations() == false)
                    {
                        string elevType = doc.GetElement(e.GetTypeId()).Name;
                        //string itemInfo = "ID: " + "\t" + e.Id + "     Elevation Type: " + elevType;
                        //string itemFail = "ID: " + "\t" + e.Id + "     Elevation Type: " + elevType;
                        string itemInfo = string.Format("Elevation Type: {0} (ID: {1})", elevType, e.Id);
                        string itemFail = string.Format("Elevation Type: {0} (ID: {1})", elevType, e.Id);
                        try
                        {
                            // delete item
                            using (Transaction t = new Transaction(doc, "Remove Single Elevation Tag"))
                            {
                                t.Start();
                                doc.Delete(e.Id);
                                t.Commit();
                            }
                            // collect info
                            info.Add(itemInfo);
                            count += 1;
                        }
                        catch (Exception)
                        {
                            infoFail.Add(itemFail);
                            countFail += 1;
                        }
                    }
                }
                tg.Assimilate();
            }
            #endregion

            // if count = 0 show Not Found form
            if (count == 0)
            {
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }

            // show Results Form
            if (count != 0)
            {
                using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results())
                {
                    thisForm.ShowDialog();
                }
            }

            #region get analytics
            //try
            //{
            //    Utilities.GetAnalyticsCSV(doc, app);
            //}
            //catch (Exception)
            //{
            //}
            #endregion

            return(Result.Succeeded);
        }
Beispiel #18
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Document      doc   = commandData.Application.ActiveUIDocument.Document;

            // add event handler for when the app does not find the ArpUtilies.dll assembly
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            #region is family document?
            if (doc.IsFamilyDocument)
            {
                UI.Info.Form_Info1.infoMsgMain = "Wrong document";
                UI.Info.Form_Info1.infoMsgBody = "This is a family document.\nRun this tool in a project document.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }
            #endregion

            #region verify active view is sheet
            View activeView = doc.ActiveView;
            if (!(activeView is Autodesk.Revit.DB.ViewSheet))
            {
                UI.Info.Form_Info1.infoMsgMain = "Wrong Active View";
                UI.Info.Form_Info1.infoMsgBody = "Please, open a Sheet to run this tool.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }
            #endregion

            #region sheet has viewports?
            List <Element> viewportList = GetAllViewport(doc, activeView as ViewSheet);
            if (!viewportList.Any())
            {
                UI.Info.Form_Info1.infoMsgMain = "Viewports?";
                UI.Info.Form_Info1.infoMsgBody = "This sheet does not contain any Viewport to renumber.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                    return(Result.Cancelled);
                }
            }
            #endregion

            // get maximum value of detail number parameter
            int maxNum = MaxDetailNumber(viewportList);

            // renumber viewports
            using (Transaction t = new Transaction(doc, "Reassign Detail Number"))
            {
                t.Start();
                // allows selection of as many viewports as there are in the sheet
                List <Element> selection = new List <Element>();
                while (selection.Count() < viewportList.Count())
                {
                    try
                    {
                        Element e = doc.GetElement(uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element,
                                                                              new ViewportSelectionFilter(),
                                                                              "Select Viewports sequentially to re-number."));
                        selection.Add(doc.GetElement(e.Id));
                    }
                    catch (Exception)
                    {
                        if (selection.Count != 0)
                        {
                            UI.Info.Form_Info1.infoMsgMain = "Incomplete Selection";
                            UI.Info.Form_Info1.infoMsgBody = "You have not selected all the viewports in this sheet.\n" +
                                                             "Only selected ones will be renumbered sequentially.\n" +
                                                             "Please, review the other detail numbers because they might have changed.";
                            using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); }
                        }
                        else // cancel command if no views selected
                        {
                            return(Result.Cancelled);
                        }
                        break;
                    }
                }

                // detect viewports with det num value equals to one of the tarjet values
                // and set it to a higher number so they don´t get duplicated
                for (int i = 1; i < selection.Count() + 1; i++)
                {
                    try
                    {
                        GetAllViewports_DICT(viewportList)[i.ToString()].           // get element with key value = i
                        get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).     // get Detail Number parameter
                        Set((maxNum + i).ToString());                               // set parameter to greater value than the maximum of values
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }

                // set new value for each item selected
                int newDetNumber = 0;
                infoResult.Clear(); // clear the results list for when the app is run multiple times
                foreach (Element e in selection)
                {
                    newDetNumber += 1;
                    e.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(newDetNumber.ToString());
                    Viewport vp = e as Viewport;
                    infoResult.Add(newDetNumber + "  ->  " + doc.GetElement(vp.ViewId).Name);
                }
                t.Commit();

                // show Results Form
                resultMsgMain = "The following viewports have been renumbered:";
                using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); }
            }
            //try
            //{
            //    Utilities.GetAnalyticsCSV(doc, app);
            //}
            //catch (Exception)
            //{
            //}
            return(Result.Succeeded);
        }