Ejemplo n.º 1
0
        private void BtnCreate_Click(object sender, EventArgs e)
        {
            // check if at least one item is selected
            if (LsvWorksets.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Selection";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more worksets from the list.";
                using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }
            else
            {
                // collect selected worksets
                List <string> selectedWorksets = new List <string>();
                foreach (ListViewItem item in LsvWorksets.CheckedItems)
                {
                    selectedWorksets.Add(item.Text);
                }

                // check if workset name is in use
                usedNames = GetUsedNames(m_doc, selectedWorksets);
                if (usedNames.Any())
                {
                    using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning())
                    {
                        thisForm.ShowDialog();
                    }
                }
                // proceed if workset names are unique
                else
                {
                    using (TransactionGroup tg = new TransactionGroup(m_doc, "Transfer Worksets"))
                    {
                        tg.Start();
                        createdWorksets.Clear(); // clear results list for when running the command more than once.
                        foreach (string WorksetName in selectedWorksets)
                        {
                            using (Transaction t = new Transaction(m_doc, "Single Transaction"))
                            {
                                t.Start();
                                Workset newWorkset = null;
                                newWorkset = Workset.Create(m_doc, WorksetName);
                                createdWorksets.Add(WorksetName);
                                t.Commit();
                            }
                        }
                        tg.Assimilate();
                    }
                    // show Results Form
                    using (UI.Info.Form_Results thisForm = new Info.Form_Results())
                    {
                        thisForm.ShowDialog();
                    }
                    DialogResult = DialogResult.OK;
                }
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        private void BtnTransfer_Click(object sender, EventArgs e)
        {
            List <string> infoFiltersTransferred      = new List <string>();
            List <string> infoFiltersGraphicOverriden = new List <string>();

            #region items selected?
            if (LsvFilters.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more View Filters from the list to continue.";
                using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); }
                return;
            }
            if (LsvTemplates.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more View Templates from the list to continue.";
                using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); }
                return;
            }
            #endregion

            #region CHECK IF FILTER IS ALREADY APPLIED
            List <string> infoIsFilterApplied    = new List <string>();
            bool          triggerIsFilterApplied = false;
            foreach (ListViewItem tItem in LsvTemplates.CheckedItems)    // LOOP THROUGH TEMPLATES
            {
                ElementId templateId            = new ElementId(tItem.ImageIndex);
                Autodesk.Revit.DB.View template = m_doc.GetElement(templateId) as Autodesk.Revit.DB.View;

                foreach (ListViewItem vItem in LsvFilters.CheckedItems)  // LOOP THROUGH FILTERS
                {
                    ElementId filterId = new ElementId(vItem.ImageIndex);
                    if (template.IsFilterApplied(filterId))
                    {
                        infoIsFilterApplied.Add(string.Format("{0} -> {1}", vItem.Text, template.Name));
                        triggerIsFilterApplied = true;
                    }
                }
            }
            if (triggerIsFilterApplied)
            {
                // show warning form
                UI.Info.Form_Warning.warningHead = "You should know...";
                UI.Info.Form_Warning.warningMain = "The following Filters are already applied to one or more selected View Templates:";
                UI.Info.Form_Warning.warningFoot = "Graphic settings will be overriden.";
                UI.Info.Form_Warning.warningList = infoIsFilterApplied;
                using (UI.Info.Form_Warning thisForm = new Info.Form_Warning())
                {
                    thisForm.ShowDialog();
                }
            }
            #endregion

            #region PROCEED WITH TRANSACTION
            executionTime.Start();
            using (Transaction t = new Transaction(m_doc, "Transfer View Filters"))
            {
                Ana_NoOfTemplates = LsvTemplates.CheckedItems.Count;     // collect data for analytics

                t.Start();
                // FOR EACH FILTER SELECTED FROM THE LIST, GET HOST VIEW TEMPLATE AND GRAPHIC OVERRIDES
                foreach (ListViewItem filterItem in LsvFilters.CheckedItems)
                {
                    ElementId filterId = new ElementId(filterItem.ImageIndex);
                    // GET SOURCE VIEW TEMPLATE TO GET GRAPHIC OVERRIDES
                    Autodesk.Revit.DB.View  sourceTemplate = Data.Helpers.GetTemplateByName(m_doc, filterItem.Group.ToString());
                    OverrideGraphicSettings graphSetting   = sourceTemplate.GetFilterOverrides(filterId);

                    //FOR EACH TARGET TEMPLATE SELECTED, APPLY FILTERS
                    foreach (ListViewItem templateItem in LsvTemplates.CheckedItems)
                    {
                        ElementId templateId = new ElementId(templateItem.ImageIndex);
                        Autodesk.Revit.DB.View targetTemplate = m_doc.GetElement(templateId) as Autodesk.Revit.DB.View;

                        if (!targetTemplate.IsFilterApplied(filterId))   // IF FILTER IS NOT APPLIED, ADD FILTER AND OVERRIDE GRAPHICS
                        {
                            targetTemplate.AddFilter(filterId);
                            targetTemplate.SetFilterOverrides(filterId, graphSetting);

                            infoFiltersTransferred.Add(m_doc.GetElement(filterId).Name + " -> " + targetTemplate.Name);

                            Ana_NoOfFilters_Applied += 1;       // collect data for analytics
                        }

                        else // IF FILTER ALREADY APPLIED, JUST OVERRIDE GRAPHICS
                        {
                            targetTemplate.SetFilterOverrides(filterId, graphSetting);

                            infoFiltersGraphicOverriden.Add(m_doc.GetElement(filterId).Name + " -> " + targetTemplate.Name);

                            Ana_NoOfFilters_Overriden += 1;     // collect data for analytics
                        }

                        Ana_NoOfFilters_Total += 1;     // collect data for analytics
                    }
                }
                t.Commit();
            }
            executionTime.Stop();
            ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString();     // collect data for analytics
            #endregion

            #region show Results Form
            UI.Info.Form_Results.resultHead  = "Results";
            UI.Info.Form_Results.resultMain1 = "Filters Transferred:";
            UI.Info.Form_Results.resultMain2 = "Filters with Graphic Settings Overriden";
            UI.Info.Form_Results.resultList1 = infoFiltersTransferred;
            UI.Info.Form_Results.resultList2 = infoFiltersGraphicOverriden;

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

            DialogResult = DialogResult.OK;
            useTime.Stop();
            UseTimeElapseS = useTime.Elapsed.Seconds.ToString();    // collect data for analytics
            Utilities.GetAnalyticsCSV(m_doc, m_app);
            Helpers.TransferViewFiltersAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFilters_Total, Ana_NoOfFilters_Applied, Ana_NoOfFilters_Overriden, Ana_NoOfTemplates);
        }