public Form_AreaMass(UIApplication uiapp, List <Element> areas)
        {
            try
            {
                m_app          = uiapp;
                doc            = m_app.ActiveUIDocument.Document;
                collectedAreas = areas;
                InitializeComponent();
                this.Text = "Create Extruded Mass - v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

                //to restore user setting for shared parameter file
                originalDefFile = m_app.Application.SharedParametersFilename;

                iniDataManager  = new INIDataManager(m_app, MassCategory.Areas);
                placedAreas     = iniDataManager.PlacedAreas;
                areaDiscrepancy = iniDataManager.AreaDiscrepancy;
                defDictionary   = iniDataManager.DefDictionary;

                CollectAreas();
                DisplayAreaData();

                massCreator = new MassCreator(m_app);
                massCreator.AreaDictionary = areaDictionary;
                massCreator.MassFolder     = iniDataManager.MassFolder;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to start running the Mass Tool.\n" + ex.Message, "Mass From Area", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void button2DCreate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List <FloorProperties> floorList = (List <FloorProperties>)dataGridFloor.ItemsSource;
                var selectedFloors = from floor in floorList where floor.IsSelected select floor;

                if (selectedFloors.Count() > 0)
                {
                    statusLable.Text       = "Creating 2D Masses ..";
                    progressBar.Visibility = System.Windows.Visibility.Visible;
                    progressBar.Value      = 0;
                    progressBar.Maximum    = selectedFloors.Count();

                    bool createdParamMaps = (massConfig.UpdateType != ParameterUpdateType.None && massConfig.MassParameters.Count > 0) ? true : false;

                    UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
                    using (TransactionGroup tg = new TransactionGroup(m_doc))
                    {
                        tg.Start("Create 2D Masses");
                        try
                        {
                            double count = 0;
                            foreach (FloorProperties fp in selectedFloors)
                            {
                                using (Transaction trans = new Transaction(m_doc))
                                {
                                    trans.Start("Create 2D Mass");
                                    var options = trans.GetFailureHandlingOptions();
                                    options.SetFailuresPreprocessor(new DuplicateWarningSwallower());
                                    trans.SetFailureHandlingOptions(options);

                                    try
                                    {
                                        MassProperties createdMass = null;
                                        if (MassCreator.CreateFloorFace(m_doc, fp, out createdMass))
                                        {
                                            if (floorDictionary.ContainsKey(fp.FloorUniqueId))
                                            {
                                                FloorProperties updatedFloor = new FloorProperties(fp);
                                                updatedFloor.IsSelected   = false;
                                                updatedFloor.Linked2d     = true;
                                                updatedFloor.Linked2dMass = createdMass;
                                                updatedFloor.ModifiedHost = false;
                                                if (updatedFloor.Linked3d && null != updatedFloor.Linked3dMass)
                                                {
                                                    updatedFloor.ToolTip  = "Mass 3D Id: " + updatedFloor.Linked3dMass.MassId;
                                                    updatedFloor.ToolTip += "\nMass 2D Id: " + updatedFloor.Linked2dMass.MassId;
                                                }
                                                else
                                                {
                                                    updatedFloor.ToolTip = "Mass 2D Id: " + updatedFloor.Linked2dMass.MassId;
                                                }

                                                if (createdParamMaps)
                                                {
                                                    bool parameterUpdated = UpdateParameter(fp.FloorElement, createdMass.MassElement);
                                                }
                                                floorDictionary.Remove(fp.FloorUniqueId);
                                                floorDictionary.Add(fp.FloorUniqueId, updatedFloor);
                                            }
                                        }
                                        trans.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        trans.RollBack();
                                        string message = ex.Message;
                                    }
                                }

                                count++;
                                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, count });
                            }

                            DisplayFloorInfo();
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            tg.RollBack();
                            MessageBox.Show("Failed to create masses from the selected floors\n" + ex.Message, "Create 3D Masses from Floors", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    progressBar.Visibility = System.Windows.Visibility.Hidden;
                    statusLable.Text       = "Ready";
                }
                else
                {
                    MessageBox.Show("Please select floors to update masses.", "Select Floors", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create masses from the selected floors.\n" + ex.Message, "Create 3D Masses from Floors", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void button2DCreate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var areaList      = (List <AreaProperties>)dataGridArea.ItemsSource;
                var selectedAreas = areaList.Where(x => x.IsSelected).ToList();

                if (selectedAreas.Any())
                {
                    statusLable.Text       = "Creating 2D Masses ..";
                    progressBar.Visibility = System.Windows.Visibility.Visible;
                    progressBar.Value      = 0;
                    progressBar.Maximum    = selectedAreas.Count();

                    var createdParamMaps = massConfig.UpdateType != ParameterUpdateType.None && massConfig.MassParameters.Count > 0;

                    var updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
                    using (var tg = new TransactionGroup(doc))
                    {
                        tg.Start("Create 2D Masses");
                        try
                        {
                            double count = 0;
                            foreach (var ap in selectedAreas)
                            {
                                using (var trans = new Transaction(doc))
                                {
                                    trans.Start("Create 2D Mass");
                                    var options = trans.GetFailureHandlingOptions();
                                    options.SetFailuresPreprocessor(new DuplicateWarningSwallower());
                                    trans.SetFailureHandlingOptions(options);

                                    try
                                    {
                                        if (MassCreator.CreateAreaFace(doc, ap, out var createdMass))
                                        {
                                            if (AreaDictionary.ContainsKey(ap.AreaUniqueId))
                                            {
                                                var updatedArea = new AreaProperties(ap)
                                                {
                                                    IsSelected   = false,
                                                    Linked2d     = true,
                                                    Linked2dMass = createdMass,
                                                    ModifiedHost = false
                                                };

                                                if (updatedArea.Linked3d && null != updatedArea.Linked3dMass)
                                                {
                                                    updatedArea.ToolTip  = "Mass 3D Id: " + updatedArea.Linked3dMass.MassId;
                                                    updatedArea.ToolTip += "\nMass 2D Id: " + updatedArea.Linked2dMass.MassId;
                                                }
                                                else
                                                {
                                                    updatedArea.ToolTip = "Mass 2D Id: " + updatedArea.Linked2dMass.MassId;
                                                }

                                                if (createdParamMaps)
                                                {
                                                    var unused = UpdateParameter(ap.AreaElement, createdMass.MassElement);
                                                }
                                                AreaDictionary.Remove(ap.AreaUniqueId);
                                                AreaDictionary.Add(ap.AreaUniqueId, updatedArea);
                                            }
                                        }
                                        trans.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
                                        trans.RollBack();
                                    }
                                }

                                count++;
                                Dispatcher.Invoke(updatePbDelegate,
                                                  System.Windows.Threading.DispatcherPriority.Background, ProgressBar.ValueProperty,
                                                  count);
                            }

                            DisplayAreaInfo();
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
                            tg.RollBack();
                            MessageBox.Show("Failed to create 2d masses from the selected areas\n" + ex.Message,
                                            "Create 2D Masses from Areas", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    progressBar.Visibility = System.Windows.Visibility.Hidden;
                    statusLable.Text       = "Ready";
                }
                else
                {
                    MessageBox.Show("Please select areas to update masses.", "Select Areas", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
                MessageBox.Show("Failed to create 2d masses from the selected areas.\n" + ex.Message,
                                "Create 2D Masses from Areas", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void buttonCreate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool   useDefaultHeight = (bool)checkBoxDefaultHeight.IsChecked;
                double defaultHeight    = 0;
                if (useDefaultHeight)
                {
                    if (!ValidateInput(out defaultHeight))
                    {
                        return;
                    }
                }

                List <RoomProperties> roomList = (List <RoomProperties>)dataGridRoom.ItemsSource;
                var roomsFound = from room in roomList where room.IsSelected select room;
                List <RoomProperties> selectedRooms = roomsFound.ToList();
                if (selectedRooms.Count > 0)
                {
                    statusLable.Text       = "Creating 3D Masses ..";
                    progressBar.Visibility = System.Windows.Visibility.Visible;
                    progressBar.Value      = 0;
                    progressBar.Maximum    = selectedRooms.Count;

                    bool createdParamMaps = (massConfig.UpdateType != ParameterUpdateType.None && massConfig.MassParameters.Count > 0) ? true : false;

                    UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
                    using (TransactionGroup tg = new TransactionGroup(m_doc))
                    {
                        tg.Start("Create 3D Masses");
                        try
                        {
                            double count = 0;
                            for (int i = 0; i < selectedRooms.Count; i++)
                            {
                                RoomProperties rp = selectedRooms[i];
                                if (useDefaultHeight)
                                {
                                    rp.UserHeight = defaultHeight;
                                }
                                using (Transaction trans = new Transaction(m_doc))
                                {
                                    trans.Start("Create 3D Mass");
                                    var options = trans.GetFailureHandlingOptions();
                                    options.SetFailuresPreprocessor(new DuplicateWarningSwallower());
                                    trans.SetFailureHandlingOptions(options);

                                    try
                                    {
                                        MassProperties createdMass = null;
                                        if (MassCreator.CreateRoomSolid(m_doc, rp, out createdMass))
                                        {
                                            if (roomDictionary.ContainsKey(rp.RoomUniqueId))
                                            {
                                                RoomProperties updatedRoom = new RoomProperties(rp);
                                                updatedRoom.IsSelected   = false;
                                                updatedRoom.Linked3d     = true;
                                                updatedRoom.Linked3dMass = createdMass;
                                                updatedRoom.ModifiedHost = false;
                                                updatedRoom.ToolTip      = "Mass 3D Id: " + createdMass.MassId;
                                                if (updatedRoom.Linked2d && null != updatedRoom.Linked2dMass)
                                                {
                                                    updatedRoom.ToolTip += "\nMass 2D Id: " + updatedRoom.Linked2dMass.MassId;
                                                }

                                                if (createdParamMaps)
                                                {
                                                    bool parameterUpdated = UpdateParameter(rp.RoomElement, createdMass.MassElement);
                                                }
                                                roomDictionary.Remove(rp.RoomUniqueId);
                                                roomDictionary.Add(rp.RoomUniqueId, updatedRoom);
                                            }
                                        }
                                        trans.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        trans.RollBack();
                                        string message = ex.Message;
                                    }
                                }

                                count++;
                                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, count });
                            }

                            DisplayRoomInfo();
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            tg.RollBack();
                            MessageBox.Show("Failed to create masses from the selected rooms\n" + ex.Message, "Create 3D Masses from Rooms", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    progressBar.Visibility = System.Windows.Visibility.Hidden;
                    statusLable.Text       = "Ready";
                }
                else
                {
                    MessageBox.Show("Please select rooms to update masses.", "Select Rooms", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create 3d masses from the selected rooms.\n" + ex.Message, "Create 3D Masses from Rooms", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }