Exemplo n.º 1
0
 private static IEnumerable <BrowserItem> GetElementTypes(RevitDocument revitDocument)
 {
     return(new FilteredElementCollector(revitDocument.Document)
            .WhereElementIsElementType()
            .Where(e => e.Category != null && e.GetType() != typeof(ViewSheet))
            .Select(e =>
     {
         try
         {
             return new BrowserItem(
                 e.Id.IntegerValue,
                 e.Category.Name + ModPlusAPI.Language.GetItem(LangItem, "m11"),
                 ((ElementType)e).FamilyName,
                 e.Name);
         }
         catch (Exception ex)
         {
             Logger.Instance.Add(
                 string.Format(
                     ModPlusAPI.Language.GetItem(LangItem, "m1"),
                     DateTime.Now.ToLocalTime(),
                     e.Id.IntegerValue,
                     ex.Message));
             return null;
         }
     })
            .Where(e => e != null));
 }
Exemplo n.º 2
0
        private static IEnumerable <BrowserItem> GetCategories(RevitDocument revitDocument)
        {
            var categories     = new List <BrowserItem>();
            var categoriesList = revitDocument.Document.Settings.Categories;

            foreach (Category category in categoriesList)
            {
                if (category.Id.IntegerValue > 0)
                {
                    continue;
                }

                var subCategories = category.SubCategories;
                if (subCategories == null || subCategories.Size == 0)
                {
                    continue;
                }

                foreach (Category subCategory in subCategories)
                {
                    var element = revitDocument.Document.GetElement(subCategory.Id);
                    if (element != null)
                    {
                        categories.Add(new BrowserItem(
                                           element.Id.IntegerValue,
                                           ModPlusAPI.Language.GetItem(LangItem, "m26"),
                                           string.Empty,
                                           element.Name));
                    }
                }
            }

            return(categories);
        }
Exemplo n.º 3
0
 private static IEnumerable <BrowserItem> GetViewTemplates(RevitDocument revitDocument)
 {
     return(new FilteredElementCollector(revitDocument.Document)
            .OfClass(typeof(View))
            .Where(e => ((View)e).IsTemplate)
            .Select(e =>
     {
         try
         {
             var elementType = (ElementType)revitDocument.Document.GetElement(e.GetTypeId());
             return new BrowserItem(
                 e.Id.IntegerValue,
                 ModPlusAPI.Language.GetItem(LangItem, "m29"),
                 elementType != null ? elementType.FamilyName : string.Empty,
                 e.Name);
         }
         catch (Exception ex)
         {
             Logger.Instance.Add(
                 string.Format(
                     ModPlusAPI.Language.GetItem(LangItem, "m1"),
                     DateTime.Now.ToLocalTime(),
                     e.Id.IntegerValue,
                     ex.Message));
             return null;
         }
     })
            .Where(e => e != null));
 }
Exemplo n.º 4
0
 private static IEnumerable <BrowserItem> GetWorksets(RevitDocument revitDocument)
 {
     return(new FilteredWorksetCollector(revitDocument.Document)
            .OfKind(WorksetKind.UserWorkset)
            .Select(e =>
     {
         try
         {
             return new BrowserItem(
                 e.Id.IntegerValue,
                 ModPlusAPI.Language.GetItem(LangItem, "m10"),
                 "-",
                 e.Name);
         }
         catch (Exception ex)
         {
             Logger.Instance.Add(
                 string.Format(
                     ModPlusAPI.Language.GetItem(LangItem, "m1"),
                     DateTime.Now.ToLocalTime(),
                     e.Id.IntegerValue,
                     ex.Message));
             return null;
         }
     })
            .Where(e => e != null));
 }
Exemplo n.º 5
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            m_app = commandData.Application;
            m_doc = m_app.ActiveUIDocument.Document;
            Log.AppendLog(LogMessageType.INFO, "Started");

            // (Konrad) We are gathering information about the addin use. This allows us to
            // better maintain the most used plug-ins or discontiue the unused ones.
            AddinUtilities.PublishAddinLog(new AddinLog("ViewAnalysis-LPD Analysis", commandData.Application.Application.VersionNumber));

            var docPath = RevitDocument.GetCentralPath(m_doc);

            if (!string.IsNullOrEmpty(docPath))
            {
                var commandForm = new CommandForm(m_app);
                commandForm.ShowDialog();
            }
            else
            {
                Log.AppendLog(LogMessageType.WARNING, "File not saved");
                MessageBox.Show(Properties.Resources.Command_FileNotSaved, Properties.Resources.Command_FileNotSavedHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Log.AppendLog(LogMessageType.INFO, "Ended");
            return(Result.Succeeded);
        }
Exemplo n.º 6
0
 private static IEnumerable <BrowserItem> GetSpecialCategoryElements(RevitDocument revitDocument)
 {
     return(new FilteredElementCollector(revitDocument.Document)
            .WherePasses(new LogicalOrFilter(new List <ElementFilter>
     {
         new ElementCategoryFilter(BuiltInCategory.OST_ColorFillSchema),
         new ElementCategoryFilter(BuiltInCategory.OST_AreaSchemes),
         new ElementCategoryFilter(BuiltInCategory.OST_Phases),
         new ElementCategoryFilter(BuiltInCategory.OST_VolumeOfInterest)
     }))
            .Select(e =>
     {
         try
         {
             var elementType = (ElementType)revitDocument.Document.GetElement(e.GetTypeId());
             return new BrowserItem(
                 e.Id.IntegerValue,
                 e.Category.Name,
                 elementType != null ? elementType.FamilyName : string.Empty,
                 e.Name);
         }
         catch (Exception ex)
         {
             Logger.Instance.Add(
                 string.Format(
                     ModPlusAPI.Language.GetItem(LangItem, "m1"),
                     DateTime.Now.ToLocalTime(),
                     e.Id.IntegerValue,
                     ex.Message));
             return null;
         }
     })
            .Where(e => e != null));
 }
Exemplo n.º 7
0
 private IEnumerable <BrowserItem> GetElements(RevitDocument revitDocument)
 {
     return(new FilteredElementCollector(revitDocument.Document)
            .WherePasses(new ElementMulticlassFilter(_elementTypes))
            .Select(e =>
     {
         try
         {
             var elementType = (ElementType)revitDocument.Document.GetElement(e.GetTypeId());
             return new BrowserItem(
                 e.Id.IntegerValue,
                 e.Category?.Name ?? _specialTypeCategoryNames[e.GetType().Name],
                 elementType != null ? elementType.FamilyName : string.Empty,
                 e.Name);
         }
         catch (Exception ex)
         {
             Logger.Instance.Add(
                 string.Format(
                     ModPlusAPI.Language.GetItem(LangItem, "m1"),
                     DateTime.Now.ToLocalTime(),
                     e.Id.IntegerValue,
                     ex.Message));
             return null;
         }
     })
            .Where(e => e != null));
 }
Exemplo n.º 8
0
 private static IEnumerable <BrowserItem> GetGridsAndLevels(RevitDocument revitDocument)
 {
     return(new FilteredElementCollector(revitDocument.Document)
            .WherePasses(new ElementMulticlassFilter(new List <Type>
     {
         typeof(Grid), typeof(Level)
     }))
            .WhereElementIsNotElementType()
            .Select(e =>
     {
         try
         {
             var elementType = (ElementType)revitDocument.Document.GetElement(e.GetTypeId());
             return new BrowserItem(
                 e.Id.IntegerValue,
                 e.Category.Name,
                 elementType != null ? elementType.FamilyName : string.Empty,
                 e.Name);
         }
         catch (Exception ex)
         {
             Logger.Instance.Add(
                 string.Format(
                     ModPlusAPI.Language.GetItem(LangItem, "m1"),
                     DateTime.Now.ToLocalTime(),
                     e.Id.IntegerValue,
                     ex.Message));
             return null;
         }
     })
            .Where(e => e != null));
 }
Exemplo n.º 9
0
 // Token: 0x0600003B RID: 59 RVA: 0x0000627C File Offset: 0x0000447C
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     try
     {
         if (!commandData.Application.ActiveUIDocument.Document.IsFamilyDocument)
         {
             if (HeXML_Import.frm_HeXML_Import == null || !HeXML_Import.frm_HeXML_Import.Visible)
             {
                 this._commandData = commandData;
                 RevitDocument revitDocument = new RevitDocument();
                 string        familyPath    = Path.GetDirectoryName(Assembly.GetAssembly(typeof(HeXML_Import)).Location) + "\\" + revitDocument.MeasurementFamilyPointPath;
                 revitDocument.Load_Family(familyPath, commandData.Application.ActiveUIDocument.Document);
                 Transaction transaction = new Transaction(this._commandData.Application.ActiveUIDocument.Document);
                 transaction.Start("Leica_Transaction_HeXMLPoints");
                 HeXML_Import.frm_HeXML_Import = new frm_HeXML_Import(commandData);
                 HeXML_Import.frm_HeXML_Import.HeXML_Import = this;
                 HeXML_Import.frm_HeXML_Import.ShowDialog(new RevitWindowHandle());
                 transaction.Commit();
             }
         }
         else
         {
             MessageBox.Show("The \"Leica HeXML Import\" can only be used with project documents.", "Leica", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     return(0);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Returns unique ids for the elements involved in the event.
        /// </summary>
        /// <returns>List of unique id strings</returns>
        public IEnumerable <string> GetUniqueIds()
        {
            if (Elements == null || RevitDocument == null)
            {
                yield break;
            }

            foreach (var id in Elements)
            {
                var e = RevitDocument.GetElement(id);
                if (e != null)
                {
                    yield return(e.UniqueId);
                }
            }
        }
Exemplo n.º 11
0
        // Token: 0x06000032 RID: 50 RVA: 0x000057D0 File Offset: 0x000039D0
        private void TSB_Select_Click(object sender, EventArgs e)
        {
            RevitDocument revitDocument = new RevitDocument();

            base.Visible = false;
            List <HeXML_Point> list = revitDocument.Select_HeXMLPoints(this._commandData.Application, this._commandData.Application.ActiveUIDocument.Document);

            base.Visible      = true;
            this._List_Object = new List <object>();
            if (list.Count != 0)
            {
                foreach (HeXML_Point item in list)
                {
                    this._List_Object.Add(item);
                }
                this.uc_HeXML_DetailTreeview.Load(this._List_Object);
            }
            this.Check_Controls();
        }
Exemplo n.º 12
0
 // Token: 0x06000040 RID: 64 RVA: 0x00006400 File Offset: 0x00004600
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     try
     {
         if (Control.ModifierKeys != Keys.Control)
         {
             string text = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Help)).Location) + "\\LeicaBimLink.chm";
             if (File.Exists(text))
             {
                 Process.Start(text);
             }
         }
         else
         {
             List <HeXML_Point> list = new RevitDocument().Select_HeXMLPoints(commandData.Application, commandData.Application.ActiveUIDocument.Document);
             if (list.Count != 0)
             {
                 string text2 = "";
                 foreach (HeXML_Point heXML_Point in list)
                 {
                     text2 = string.Concat(new object[]
                     {
                         text2,
                         "n: ",
                         heXML_Point.Coordinate_Local_Grid.n,
                         "; e: ",
                         heXML_Point.Coordinate_Local_Grid.e,
                         "; hghthO: ",
                         heXML_Point.Coordinate_Local_Grid.hghthO,
                         "\n"
                     });
                 }
                 MessageBox.Show(text2);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     return(0);
 }
        // Token: 0x06000029 RID: 41 RVA: 0x00004DC0 File Offset: 0x00002FC0
        private void TSB_OpenHeXML_Click(object sender, EventArgs e)
        {
            this.toolStrip.Enabled = false;
            this.uc_HeXML_DetailTreeview.Enabled = false;
            this.uc_HeXML_DetailTreeview.Clear();
            this._LandXML_Header = null;
            this._UnitConverter  = RevitDocument.UnitConverter.None;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "XML Files (*.XML)|*.XML|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                HeXML heXML = new HeXML();
                this._List_Object = heXML.Read(openFileDialog.FileName, out this._LandXML_Header);
                RevitDocument revitDocument = new RevitDocument();
                this._UnitConverter = revitDocument.Test_LinearUnitType_Agreement(this._commandData.Application.ActiveUIDocument.Document, this._LandXML_Header.Units_linearUnit);
                if (this._List_Object != null && this._List_Object.Count != 0)
                {
                    this.toolStripStatus.Text = "Status: Update display";
                    Application.DoEvents();
                    this.uc_HeXML_DetailTreeview.Load(this._List_Object);
                    if (this._UnitConverter == RevitDocument.UnitConverter.None)
                    {
                        this.toolStripStatus.Text = "Status: Ready";
                    }
                    else
                    {
                        this.toolStripStatus.Text = "Information: Different unit types";
                    }
                }
                else
                {
                    MessageBox.Show("No usable objects exist.", "Leica", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                this._UnitConverterIntern = revitDocument.Test_LinearUnitType_AgreementIntern(this._LandXML_Header.Units_linearUnit);
            }
            this.Check_Controls();
            this.toolStrip.Enabled = true;
            this.uc_HeXML_DetailTreeview.Enabled = true;
        }
Exemplo n.º 14
0
        private IEnumerable <BrowserItem> GetParameters(RevitDocument revitDocument)
        {
            var parameters = new List <BrowserItem>();

            if (revitDocument.Document.IsFamilyDocument)
            {
                return(parameters);
            }

            var definitionBindingMapIterator = revitDocument.Document.ParameterBindings.ForwardIterator();

            definitionBindingMapIterator.Reset();
            while (definitionBindingMapIterator.MoveNext())
            {
                Element element = null;
                try
                {
                    var key = (InternalDefinition)definitionBindingMapIterator.Key;
                    element = revitDocument.Document.GetElement(key.Id);
                    var elementType = (ElementType)revitDocument.Document.GetElement(element.GetTypeId());
                    parameters.Add(new BrowserItem(
                                       element.Id.IntegerValue,
                                       element.Category?.Name ?? _specialTypeCategoryNames[element.GetType().Name],
                                       elementType != null ? elementType.FamilyName : string.Empty,
                                       element.Name));
                }
                catch (Exception ex)
                {
                    Logger.Instance.Add(string.Format(
                                            ModPlusAPI.Language.GetItem(LangItem, "m1"),
                                            DateTime.Now.ToLocalTime(),
                                            element != null ? element.Id.IntegerValue.ToString() : "null",
                                            ex.Message));
                }
            }

            return(parameters);
        }
Exemplo n.º 15
0
 // Token: 0x06000033 RID: 51 RVA: 0x00005888 File Offset: 0x00003A88
 private void TSB_ExportHeXML_Click(object sender, EventArgs e)
 {
     if (this._List_Object.Count != 0)
     {
         this.toolStrip.Enabled = false;
         this.uc_HeXML_DetailTreeview.Enabled = false;
         SaveFileDialog saveFileDialog = new SaveFileDialog();
         saveFileDialog.Filter   = "XML Files (*.XML)|*.XML|All files (*.*)|*.*";
         saveFileDialog.FileName = "HeXML.xml";
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             this.toolStripStatus.Text = "Status: Saving ...";
             Application.DoEvents();
             LandXML_Header landXML_Header = new LandXML_Header();
             RevitDocument  revitDocument  = new RevitDocument();
             landXML_Header.Application_version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
             string str = string.Concat(new string[]
             {
                 string.Format("{0:D2}", DateTime.Now.Year),
                 "-",
                 string.Format("{0:D2}", DateTime.Now.Month),
                 "-",
                 string.Format("{0:D2}", DateTime.Now.Day)
             });
             string str2 = string.Concat(new string[]
             {
                 string.Format("{0:D2}", DateTime.Now.Hour),
                 ":",
                 string.Format("{0:D2}", DateTime.Now.Minute),
                 ":",
                 string.Format("{0:D2}", DateTime.Now.Second)
             });
             landXML_Header.Author_timeStamp = str + "T" + str2;
             bool            flag             = true;
             DisplayUnitType displayUnitType  = revitDocument.Detect_UnitType(this._commandData.Application.ActiveUIDocument.Document, 0);
             DisplayUnitType displayUnitType2 = revitDocument.Detect_UnitType(this._commandData.Application.ActiveUIDocument.Document, 1);
             DisplayUnitType displayUnitType3 = revitDocument.Detect_UnitType(this._commandData.Application.ActiveUIDocument.Document, 2);
             revitDocument.Detect_UnitType(this._commandData.Application.ActiveUIDocument.Document, 3);
             string text = displayUnitType.ToString().ToLower();
             if (text.Contains("feet") || text.Contains("foot") || text.Contains("inches"))
             {
                 landXML_Header.Units_linearUnit = "foot";
                 flag = false;
             }
             else
             {
                 landXML_Header.Units_linearUnit = "meter";
             }
             string text2 = displayUnitType2.ToString().ToLower();
             if (text2.Contains("feet") || text2.Contains("acres") || text2.Contains("inches"))
             {
                 landXML_Header.Units_areaUnit = "squareFoot";
             }
             else
             {
                 landXML_Header.Units_areaUnit = "squareMeter";
             }
             string text3 = displayUnitType3.ToString().ToLower();
             if (text3.Contains("gallon") || text3.Contains("inch") || text3.Contains("feet") || text3.Contains("yard"))
             {
                 landXML_Header.Units_volumeUnit = "cubicFeet";
             }
             else
             {
                 landXML_Header.Units_volumeUnit = "cubicMeter";
             }
             landXML_Header.Units_angularUnit = "decimal degrees";
             if (!flag)
             {
                 landXML_Header.Units_pressureUnit = "inchHG";
             }
             else
             {
                 landXML_Header.Units_pressureUnit = "milliBars";
             }
             if (!flag)
             {
                 landXML_Header.Units_temperatureUnit = "fahrenheit";
             }
             else
             {
                 landXML_Header.Units_temperatureUnit = "celsius";
             }
             new HeXML().Write(saveFileDialog.FileName, this._List_Object, landXML_Header);
             this.toolStripStatus.Text = "Status: The file has been written";
             frm_Report frm_Report = new frm_Report();
             frm_Report.FillTextBox(this._List_Object, "Protocol Export HeXML");
             frm_Report.ShowDialog();
             this.toolStripStatus.Text = "Status: Ready";
             this.uc_HeXML_DetailTreeview.Clear();
         }
         this.toolStrip.Enabled = true;
         this.uc_HeXML_DetailTreeview.Enabled = true;
     }
     this.Check_Controls();
 }
 // Token: 0x0600002A RID: 42 RVA: 0x00004F1C File Offset: 0x0000311C
 private void TSB_ImportHeXML_Click(object sender, EventArgs e)
 {
     this.toolStrip.Enabled = false;
     this.uc_HeXML_DetailTreeview.Enabled = false;
     if (this._List_Object.Count != 0)
     {
         RevitDocument revitDocument          = new RevitDocument();
         List <string> listExisting_UniqueIDs = revitDocument.Get_FamilyParameterValue(revitDocument.MeasurementFamilyPointTypName, HeXML_Point_Strings.FamilyParameterName_UniqueID, this._commandData.Application.ActiveUIDocument.Document);
         HeXML_Details heXML_Details;
         if (this._UnitConverter == RevitDocument.UnitConverter.FeetToMeter)
         {
             heXML_Details = new HeXML_Details(HeXML_Details.UnitConverter.FeetToMeter);
         }
         else if (this._UnitConverter == RevitDocument.UnitConverter.MeterToFeet)
         {
             heXML_Details = new HeXML_Details(HeXML_Details.UnitConverter.MeterToFeet);
         }
         else
         {
             heXML_Details = new HeXML_Details(HeXML_Details.UnitConverter.None);
         }
         heXML_Details.Detect_Details(this._List_Object, listExisting_UniqueIDs);
         heXML_Details.Get_HeXMLPoints();
         listExisting_UniqueIDs = revitDocument.Get_FamilyParameterValue(revitDocument.MeasurementFamilyPointTypName, HeXML_Point_Strings.FamilyParameterName_UniqueID, this._commandData.Application.ActiveUIDocument.Document);
         HeXML_Details heXML_Details2 = null;
         if (this._UnitConverterIntern == RevitDocument.UnitConverter.FeetToMeter)
         {
             heXML_Details2 = new HeXML_Details(HeXML_Details.UnitConverter.FeetToMeter);
         }
         if (this._UnitConverterIntern == RevitDocument.UnitConverter.MeterToFeet)
         {
             heXML_Details2 = new HeXML_Details(HeXML_Details.UnitConverter.MeterToFeet);
         }
         if (this._UnitConverterIntern == RevitDocument.UnitConverter.None)
         {
             heXML_Details2 = new HeXML_Details(HeXML_Details.UnitConverter.None);
         }
         heXML_Details2.Detect_Details(this._List_Object, listExisting_UniqueIDs);
         List <HeXML_Point> heXMLPoints = heXML_Details2.Get_HeXMLPoints();
         if (heXMLPoints.Count != 0 || heXML_Details.List_HeXML_Point_Index_Fail.Count != 0)
         {
             revitDocument.ToolStripProgressBar = this.toolStripProgressBar;
             revitDocument.ToolStripStatusLabel = this.toolStripStatus;
             Path.GetDirectoryName(Assembly.GetAssembly(typeof(frm_HeXML_Import)).Location) + "\\" + revitDocument.MeasurementFamilyPointPath;
             this.toolStripStatus.Text = "Status: Loads the family";
             Application.DoEvents();
             Family family = null;
             if (family == null)
             {
                 family = revitDocument.Get_Family(revitDocument.MeasurementFamilyPointName, this._commandData.Application.ActiveUIDocument.Document);
             }
             this.toolStripProgressBar.Visible = true;
             revitDocument.Set_HeXMLPoints(family, heXMLPoints, this._commandData.Application.ActiveUIDocument.Document, this.HeXML_Import);
             this.toolStripProgressBar.Visible = false;
             this.toolStripStatus.Text         = "Status: The points were imported";
             frm_Report frm_Report = new frm_Report();
             frm_Report.FillTextBox(heXML_Details, "Protocol Import HeXML");
             frm_Report.ShowDialog();
             this.uc_HeXML_DetailTreeview.Clear();
             base.Close();
         }
     }
     this.Check_Controls();
     this.toolStrip.Enabled = true;
     this.uc_HeXML_DetailTreeview.Enabled = true;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Получает все элементы выбранного документа Revit
        /// </summary>
        /// <param name="revitDocument">Документ Revit для извлечения данных</param>
        /// <returns>Общая группа элементов в браузере</returns>
        public GeneralItemsGroup GetAllRevitElements(RevitDocument revitDocument)
        {
            Logger.Instance.Add(
                string.Format(
                    ModPlusAPI.Language.GetItem(LangItem, "m2"),
                    DateTime.Now.ToLocalTime(),
                    revitDocument.Title));

            try
            {
                var allElements = new List <BrowserItem>();
                allElements.AddRange(GetElementTypes(revitDocument));
                allElements.AddRange(GetElements(revitDocument));
                allElements.AddRange(GetSpecialCategoryElements(revitDocument));
                allElements.AddRange(GetViewTemplates(revitDocument));
                allElements.AddRange(GetViews(revitDocument));
                allElements.AddRange(GetElevationMarkers(revitDocument));
                allElements.AddRange(GetViewports(revitDocument));
                allElements.AddRange(revitDocument.Document.IsWorkshared ? GetWorksets(revitDocument) : new List <BrowserItem>());
                allElements.AddRange(GetGridsAndLevels(revitDocument));
                allElements.AddRange(GetParameters(revitDocument));
                allElements.AddRange(GetCategories(revitDocument));

                var elementsGroupedByCategory = allElements
                                                .GroupBy(e => e.CategoryName)
                                                .ToList();
                var categoryGroups = new List <BrowserItem>();
                foreach (var categoryGroup in elementsGroupedByCategory)
                {
                    var elementsGroupedByType = categoryGroup
                                                .GroupBy(e => e.FamilyName)
                                                .ToList();
                    var typeGroups = new List <BrowserItem>();
                    foreach (var typeGroup in elementsGroupedByType)
                    {
                        var instances = typeGroup.ToList();
                        instances = instances.OrderBy(instance => instance.Name).ToList();

                        if (string.IsNullOrEmpty(typeGroup.Key))
                        {
                            instances.ForEach(instance => typeGroups.Add(instance));
                            continue;
                        }

                        typeGroups.Add(new BrowserItem(typeGroup.Key, instances));
                    }

                    typeGroups = typeGroups.OrderBy(type => type.Name).ToList();
                    categoryGroups.Add(new BrowserItem(categoryGroup.Key, typeGroups));
                }

                categoryGroups = categoryGroups.OrderBy(category => category.Name).ToList();

                Logger.Instance.Add(
                    string.Format(
                        ModPlusAPI.Language.GetItem(LangItem, "m3"),
                        DateTime.Now.ToLocalTime(),
                        revitDocument.Title));
                Logger.Instance.Add("---------");

                return(new GeneralItemsGroup(
                           ModPlusAPI.Language.GetItem(LangItem, "m28"),
                           categoryGroups));
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);

                return(new GeneralItemsGroup(
                           ModPlusAPI.Language.GetItem(LangItem, "m28"),
                           new List <BrowserItem>()));
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Копирует все выбранные элементы в выбранные документы
        /// </summary>
        /// <param name="documentFrom">Документ из которого производится копирование</param>
        /// <param name="documentsTo">Список документов в которые осуществляется копирование</param>
        /// <param name="elements">Список элементов Revit</param>
        /// <param name="copyingOptions">Настройки копирования элементов</param>
        public async void CopyElements(
            RevitDocument documentFrom,
            IEnumerable <RevitDocument> documentsTo,
            List <BrowserItem> elements,
            CopyingOptions copyingOptions)
        {
            _uiApplication.Application.FailuresProcessing += Application_FailuresProcessing;

            var revitDocuments = documentsTo.ToList();

            Logger.Instance.Add(string.Format(
                                    ModPlusAPI.Language.GetItem(LangItem, "m5"),
                                    DateTime.Now.ToLocalTime(),
                                    documentFrom.Title,
                                    string.Join(", ", revitDocuments.Select(doc => doc.Title))));
            Logger.Instance.Add(string.Format(
                                    ModPlusAPI.Language.GetItem(LangItem, "m8"),
                                    GetCopyingOptionsName(copyingOptions)));

            var copyPasteOption = new CopyPasteOptions();

            switch (copyingOptions)
            {
            case CopyingOptions.AllowDuplicates:
                copyPasteOption.SetDuplicateTypeNamesHandler(new CustomCopyHandlerAllow());
                break;

            case CopyingOptions.RefuseDuplicate:
                copyPasteOption.SetDuplicateTypeNamesHandler(new CustomCopyHandlerAbort());
                break;
            }

            foreach (var documentTo in revitDocuments)
            {
                foreach (var element in elements)
                {
                    var succeed = true;
                    try
                    {
                        await Task.Delay(100).ConfigureAwait(true);

                        var elementId    = new ElementId(element.Id);
                        var revitElement = documentFrom.Document.GetElement(elementId);
                        ICollection <ElementId> elementIds = new List <ElementId> {
                            elementId
                        };

                        using (var transaction = new Transaction(
                                   documentTo.Document,
                                   ModPlusAPI.Language.GetItem(LangItem, "m27")))
                        {
                            transaction.Start();

                            try
                            {
                                if (revitElement.GetType() == typeof(Workset))
                                {
                                    if (documentTo.Document.IsWorkshared)
                                    {
                                        Workset.Create(documentTo.Document, revitElement.Name);
                                    }
                                    else
                                    {
                                        Logger.Instance.Add(string.Format(
                                                                ModPlusAPI.Language.GetItem(LangItem, "m9"),
                                                                DateTime.Now.ToLocalTime(),
                                                                documentTo.Title));
                                    }
                                }

                                if (_stopCopyingOperation)
                                {
                                    _stopCopyingOperation = false;
                                    OnPassedElementsCountChanged(true);
                                    return;
                                }

                                ElementTransformUtils.CopyElements(
                                    documentFrom.Document,
                                    elementIds,
                                    documentTo.Document,
                                    null,
                                    copyPasteOption);
                            }
                            catch (Exception e)
                            {
                                Logger.Instance.Add(string.Format(
                                                        ModPlusAPI.Language.GetItem(LangItem, "m7"),
                                                        DateTime.Now.ToLocalTime(),
                                                        element.Name,
                                                        element.Id,
                                                        element.CategoryName,
                                                        e.Message));

                                succeed = false;
                            }

                            transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Instance.Add(string.Format(
                                                ModPlusAPI.Language.GetItem(LangItem, "m7"),
                                                DateTime.Now.ToLocalTime(),
                                                element.Name,
                                                element.Id,
                                                element.CategoryName,
                                                e.Message));

                        succeed = false;
                    }

                    if (!succeed)
                    {
                        OnBrokenElementsCountChanged();
                    }

                    _passedElements++;
                    if (_passedElements == elements.Count * revitDocuments.Count)
                    {
                        OnPassedElementsCountChanged(true);
                        _passedElements = 0;
                        _uiApplication.Application.FailuresProcessing -= Application_FailuresProcessing;
                    }
                    else
                    {
                        OnPassedElementsCountChanged(false);
                    }
                }
            }

            Logger.Instance.Add(string.Format(
                                    ModPlusAPI.Language.GetItem(LangItem, "m6"),
                                    DateTime.Now.ToLocalTime(),
                                    documentFrom.Title,
                                    string.Join(", ", revitDocuments.Select(doc => doc.Title))));
            Logger.Instance.Add("---------");
        }