Exemplo n.º 1
0
        private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                var currentCell = dataGridViewElement.CurrentCellAddress;
                var sendingCB   = sender as DataGridViewComboBoxEditingControl;
                DataGridViewTextBoxCell cell = (DataGridViewTextBoxCell)dataGridViewElement.Rows[currentCell.Y].Cells["MassId"];
                int selectedIndex            = ((System.Windows.Forms.ComboBox)sender).SelectedIndex;

                int selectedMassId = 0;
                if (null != dataGridViewElement.Rows[currentCell.Y].Tag && selectedIndex != -1)
                {
                    if (selectedIndex == 0) //mass name: <None>
                    {
                        cell.Value = selectedMassId;
                    }
                    else if (selectedIndex > 0)
                    {
                        ElementProperties ep = dataGridViewElement.Rows[currentCell.Y].Tag as ElementProperties;
                        selectedMassId = ep.MassContainers.Keys.ToList()[selectedIndex - 1];
                        cell.Value     = selectedMassId;

                        if (checkBoxHost.Checked)
                        {
                            if (hostMaps.ContainsKey(ep.ElementId))
                            {
                                foreach (int elementId in hostMaps[ep.ElementId].Keys)
                                {
                                    int rowIndex = hostMaps[ep.ElementId][elementId];
                                    DataGridViewCell textCell = dataGridViewElement.Rows[rowIndex].Cells["MassId"];
                                    textCell.Value = selectedMassId;
                                    DataGridViewComboBoxCell comboCell = dataGridViewElement.Rows[rowIndex].Cells["ColumnSelection"] as DataGridViewComboBoxCell;
                                    comboCell.Value = massDictionary[selectedMassId].MassName;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to tag massId on the cell.\n" + ex.Message, "Form_OverlapMass:ComboBox_SelectedIndexChanged", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("ComboBox_SelectedIndexChanged", ex.Message);
            }
        }
Exemplo n.º 2
0
 private void listViewCategories_ItemChecked(object sender, ItemCheckedEventArgs e)
 {
     try
     {
         categoriesToSplit = new List <string>();
         foreach (ListViewItem item in listViewCategories.Items)
         {
             if (null != item.Tag && item.Checked)
             {
                 categoriesToSplit.Add(item.Name);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to check list view items.\n" + ex.Message, "Form_OverlapMass:listViewCategories_ItemChecked", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         LogFileManager.AppendLog("listViewCategories_ItemChecked", ex.Message);
     }
 }
Exemplo n.º 3
0
 private void CollectWorksets()
 {
     try
     {
         FilteredWorksetCollector worksets = new FilteredWorksetCollector(m_doc).OfKind(WorksetKind.UserWorkset);
         foreach (Workset workset in worksets)
         {
             if (!worksetDictionary.ContainsKey(workset.Name))
             {
                 worksetDictionary.Add(workset.Name, workset.Id.IntegerValue);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to collect workset from the host project.\n" + ex.Message, "LinkedModelManager:CollectWorksets", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         LogFileManager.AppendLog("CollectWorksets", ex.Message);
     }
 }
Exemplo n.º 4
0
 private void dataGridViewElement_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
 {
     try
     {
         if (e.Button == MouseButtons.Right)
         {
             int rowSelected = e.RowIndex;
             if (e.RowIndex > -1 && e.RowIndex < dataGridViewElement.Rows.Count)
             {
                 contextMenuStripView.Enabled = true;
                 dataGridViewElement.Rows[rowSelected].Selected = true;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to control context menu strip.\n" + ex.Message, "Form_OverlapMass:dataGridViewElement_CellMouseDown", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         LogFileManager.AppendLog("dataGridViewElement_CellMouseDown", ex.Message);
     }
 }
Exemplo n.º 5
0
        private void DisplayCategory()
        {
            try
            {
                foreach (Category category in elementCategories.Keys)
                {
                    ListViewItem item = new ListViewItem(category.Name);
                    item.Name    = category.Name;
                    item.Tag     = category;
                    item.Checked = elementCategories[category];

                    listViewCategory.Items.Add(item);
                }
                listViewCategory.Sort();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display categories.\n" + ex.Message, "Form_ElementFilter:DisplayCategory", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("DisplayCategory", ex.Message);
            }
        }
Exemplo n.º 6
0
 private void DisplayCategories()
 {
     try
     {
         foreach (string category in intersectingCategories)
         {
             if (categoryNames.Contains(category))
             {
                 ListViewItem item = new ListViewItem(category);
                 item.Name    = category;
                 item.Tag     = category;
                 item.Checked = true;
                 listViewCategories.Items.Add(item);
                 categoriesToSplit.Add(category);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to display cateogires.\n" + ex.Message, "Form_OverlapMass:DisplayCategories", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         LogFileManager.AppendLog("DisplayCategories", ex.Message);
     }
 }
Exemplo n.º 7
0
        private void buttonDetermine_Click(object sender, EventArgs e)
        {
            try
            {
                string ratio       = textBoxRatio.Text;
                double doubleRatio = 0;

                if (double.TryParse(ratio, out doubleRatio))
                {
                    if (doubleRatio > 0 && doubleRatio < 1)
                    {
                        SetDeterminant(doubleRatio);
                    }
                    else if (doubleRatio == 0)
                    {
                        SetDeterminant(doubleRatio);
                    }
                    else if (doubleRatio == 1)
                    {
                        SetDeterminant(doubleRatio);
                    }
                    else
                    {
                        MessageBox.Show("Please enter a valid determinant value for ratio.\n The value should be between 0 and 1.", "Invalid Ratio Determinant", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid determinant value for ratio.\n The value should be between 0 and 1.", "Invalid Ratio Determinant", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to set the ratio determinant.\n" + ex.Message, "Form_OverlapMass:buttonDetermine_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("buttonDetermine_Click", ex.Message);
            }
        }
Exemplo n.º 8
0
        private void bttnApply_Click(object sender, EventArgs e)
        {
            try
            {
                FilteredElementCollector collector    = new FilteredElementCollector(m_doc);
                List <Element>           massElements = collector.OfCategory(BuiltInCategory.OST_Mass).WhereElementIsNotElementType().ToElements().ToList();

                switch (selectedSourceType)
                {
                case MassSource.SelectedMass:
                    CollectHostMass(selectedMass);
                    break;

                case MassSource.DisplayAll:
                    CollectHostMass(massElements);
                    CollectLinkedMass();
                    break;

                case MassSource.OnlyHost:
                    CollectHostMass(massElements);
                    break;

                case MassSource.OnlyLink:
                    CollectLinkedMass();
                    break;
                }

                FindOverlaps();

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect RevitLinkTypes.\n" + ex.Message, "Form_LinkedFiles:bttnApply_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("bttnApply_Click", ex.Message);
            }
        }
Exemplo n.º 9
0
        private bool FindINI()
        {
            try
            {
                string    masterFilePath = "";
                ModelPath modelPath      = m_doc.GetWorksharingCentralModelPath();
                if (m_doc.IsWorkshared && null != modelPath)
                {
                    if (modelPath.ServerPath)
                    {
                        masterFilePath = modelPath.CentralServerPath;
                    }
                    else
                    {
                        masterFilePath = m_doc.PathName;
                    }
                }
                else
                {
                    masterFilePath = m_doc.PathName;
                }
                iniPath = masterFilePath.Replace(".rvt", "_split.ini");
                if (!File.Exists(iniPath))
                {
                    try { FileStream fs = File.Create(iniPath); fs.Close(); }
                    catch { return(false); }
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find INI file. \n" + ex.Message, "SplitINIDataManager : FindINI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("FindINI", ex.Message);
                return(false);
            }
        }
Exemplo n.º 10
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckValidation())
                {
                    foreach (DataGridViewRow row in dataGridViewElement.Rows)
                    {
                        if (null != row.Tag)
                        {
                            ElementProperties ep = row.Tag as ElementProperties;
                            intersectingElements.Remove(ep.ElementId);

                            bool selected = Convert.ToBoolean(row.Cells[0].Value);
                            if (selected)
                            {
                                int massId = int.Parse(row.Cells["MassId"].Value.ToString());
                                ep.SelectedMassId = massId;
                                intersectingElements.Add(ep.ElementId, ep);

                                if (massId == 0)
                                {
                                    unassignedElements.Add(ep.ElementId, ep);
                                }
                            }
                        }
                    }
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to assign Mass elements to propagate.\n" + ex.Message, "Form_OverlapMass:buttonApply_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("buttonApply_Click", ex.Message);
            }
        }
Exemplo n.º 11
0
 private void bttnApply_Click(object sender, EventArgs e)
 {
     try
     {
         StringBuilder strBuilder = new StringBuilder();
         string        message    = "Please enter a name of the following element parameters:";
         selectedParam = new Dictionary <string, string>();
         foreach (DataGridViewRow row in dataGridViewParam.Rows)
         {
             if (Convert.ToBoolean(row.Cells[0].Value.ToString()))
             {
                 if (row.Cells[2].Value.ToString().Length > 0)
                 {
                     selectedParam.Add(row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString());
                 }
                 else
                 {
                     strBuilder.AppendLine(row.Cells[1].Value.ToString());
                 }
             }
         }
         if (strBuilder.Length > 0)
         {
             MessageBox.Show(message + "\n" + strBuilder.ToString(), "Missing Element Parameters", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             this.DialogResult = DialogResult.OK;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to collect selected parameters.\n" + ex.Message, "Form_Parameters:bttnApply_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         LogFileManager.AppendLog("bttnApply_Click", ex.Message);
     }
 }
Exemplo n.º 12
0
        public void SetDeterminant(double determinantVal)
        {
            try
            {
                determinant       = determinantVal;
                textBoxRatio.Text = determinant.ToString();
                foreach (DataGridViewRow row in dataGridViewElement.Rows)
                {
                    row.Visible = true;
                }

                foreach (DataGridViewRow row in dataGridViewElement.Rows)
                {
                    for (int i = 3; i < row.Cells.Count - 2; i++)
                    {
                        double ratio = 0;
                        if (null != row.Cells[i].Value)
                        {
                            if (double.TryParse(row.Cells[i].Value.ToString(), out ratio))
                            {
                                if (ratio > determinantVal)
                                {
                                    row.Visible = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to set ratio determinant.\n" + ex.Message, "Form_OverlapMass:SetDeterminant", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("SetDeterminant", ex.Message);
            }
        }
Exemplo n.º 13
0
        private bool CheckValidation()
        {
            bool result = true;

            try
            {
                if (double.TryParse(textBoxRatio.Text, out ratio))
                {
                    if (ratio > 0 && ratio < 1)
                    {
                        result = true;
                    }
                    else if (ratio == 1)
                    {
                        result = true;
                    }
                    else
                    {
                        MessageBox.Show("The ratio vlalue should between 0 and 1.", "Invalid Ratio Value", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        result = false;
                    }
                }
                else
                {
                    MessageBox.Show("The ratio vlalue should between 0 and 1.", "Invalid Ratio Value", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    result = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to check validation.\n" + ex.Message, "Form_Settings:CheckValidation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("CheckValidation", ex.Message);
                result = false;
            }
            return(result);
        }
Exemplo n.º 14
0
        private List <Element> FindElementsInMass(Document doc, Solid massSolid, int massId, bool linkedElement)
        {
            List <Element> elementList = new List <Element>();

            try
            {
                FilteredElementCollector elementCollector = new FilteredElementCollector(doc);
                ElementCategoryFilter    catFilter        = new ElementCategoryFilter(BuiltInCategory.OST_RvtLinks, true);
                elementCollector.WherePasses(catFilter).WherePasses(new ElementIntersectsSolidFilter(massSolid)).WhereElementIsNotElementType();
                elementList = elementCollector.ToElements().ToList();

                foreach (Element element in elementList)
                {
                    int elementId = element.Id.IntegerValue;
                    if (!elementDictionary.ContainsKey(elementId))
                    {
                        ElementProperties ep = new ElementProperties(element);
                        ep.LinkedElement = linkedElement;
                        CollectParameterValues(element);

                        FamilyInstance fi = element as FamilyInstance;
                        if (null != fi)
                        {
                            if (null != fi.Host)
                            {
                                ep.HostElementId = fi.Host.Id.IntegerValue;
                            }
                        }

                        Dictionary <int, Solid> massContainers = new Dictionary <int, Solid>();
                        massContainers.Add(massId, massSolid);
                        ep.MassContainers = massContainers;
                        elementDictionary.Add(ep.ElementId, ep);

                        if (!categoryIds.Contains(element.Category.Id.IntegerValue) && null != element.Category.Name)
                        {
                            elementCategories.Add(element.Category, false);
                            categoryIds.Add(element.Category.Id.IntegerValue);
                        }
                    }
                    else
                    {
                        ElementProperties ep = elementDictionary[elementId];
                        if (!ep.MassContainers.ContainsKey(massId))
                        {
                            ep.MassContainers.Add(massId, massSolid);
                            elementDictionary.Remove(elementId);
                            elementDictionary.Add(elementId, ep);
                        }
                    }
                }

                return(elementList);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find mass elements in mass.\n" + ex.Message, "LinkedModelManager:FindElementsInMass", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("FindElementsInMass", ex.Message);
                return(elementList);
            }
        }
Exemplo n.º 15
0
        private void CollectLinkedMass()
        {
            try
            {
                List <int> selectedMass = new List <int>();
                foreach (TreeNode typeNode in treeViewLinkedFile.Nodes)
                {
                    foreach (TreeNode instanceNode in typeNode.Nodes)
                    {
                        int  instanceId  = int.Parse(instanceNode.Name);
                        bool massChecked = false;
                        foreach (TreeNode massNode in instanceNode.Nodes)
                        {
                            if (massNode.Checked)
                            {
                                selectedMass.Add(int.Parse(massNode.Name));
                                massChecked = true;
                            }
                        }
                        if (!massChecked)
                        {
                            linkedMassDictionary.Remove(instanceId);
                        }
                    }
                }

                if (selectedMass.Count > 0)
                {
                    progressForm            = new Form_ProgressBar();
                    progressForm.Text       = "Finding Elements";
                    progressForm.LabelText  = "Finding elements intersecting with 3D mass in linked files . . .";
                    progressForm.LabelCount = selectedMass.Count.ToString() + " mass found";
                    progressForm.MaxValue   = selectedMass.Count;
                    progressForm.Show();
                    progressFormOpend = true;
                    progressForm.Refresh();

                    List <int> instanceIds = linkedMassDictionary.Keys.ToList();
                    foreach (int instanceId in instanceIds)
                    {
                        LinkedInstanceProperties         lip            = linkedMassDictionary[instanceId];
                        Dictionary <int, MassProperties> massDictionary = new Dictionary <int, MassProperties>();
                        foreach (Element massElement in lip.MassElements)
                        {
                            if (!selectedMass.Contains(massElement.Id.IntegerValue))
                            {
                                continue;
                            }

                            progressForm.PerformStep();
                            FamilyInstance fi = massElement as FamilyInstance;
                            if (null != fi)
                            {
                                MassProperties mp         = new MassProperties(fi);
                                Solid          unionSolid = null;
                                Options        opt        = m_app.Application.Create.NewGeometryOptions();
                                opt.ComputeReferences = true;
                                opt.DetailLevel       = Autodesk.Revit.DB.ViewDetailLevel.Fine;

                                GeometryElement geomElement = fi.get_Geometry(new Options(opt));

                                if (null != lip.TransformValue)
                                {
                                    geomElement = geomElement.GetTransformed(lip.TransformValue);
                                }
                                foreach (GeometryObject obj in geomElement)
                                {
                                    Solid solid = obj as Solid;
                                    if (null != solid)
                                    {
                                        if (solid.Volume > 0)
                                        {
                                            if (unionSolid == null)
                                            {
                                                unionSolid = solid;
                                            }
                                            else
                                            {
                                                unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(unionSolid, solid, BooleanOperationsType.Union);
                                            }
                                        }
                                    }
                                }
                                mp.MassSolid = unionSolid;

                                if (null != unionSolid)
                                {
                                    if (unionSolid.Volume > 0)
                                    {
                                        mp.ElementContainer = FindElementsInMass(m_doc, mp.MassSolid, mp.MassId, false);
                                        List <Element> linkedElements = FindElementsInLInkedFiles(fi, geomElement);
                                        mp.ElementContainer.AddRange(linkedElements);
                                        mp.ElementCount = mp.ElementContainer.Count;
                                    }
                                }

                                if (mp.MassParameters.Count > 0)
                                {
                                    foreach (Parameter param in mp.MassParameters)
                                    {
                                        if (!massParameters.Contains(param.Definition.Name))
                                        {
                                            massParameters.Add(param.Definition.Name);
                                        }
                                    }
                                }
                                mp.IsHost         = false;
                                mp.LInkedFileName = lip.FileName;

                                if (!massDictionary.ContainsKey(mp.MassId))
                                {
                                    massDictionary.Add(mp.MassId, mp);
                                }
                                integratedMassList.Add(mp);
                            }
                        }
                        lip.MassContainers = massDictionary;
                        linkedMassDictionary.Remove(instanceId);
                        linkedMassDictionary.Add(instanceId, lip);
                    }

                    progressForm.Close();
                    progressFormOpend = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect mass elements from the linked files.\n" + ex.Message, "LinkedModelManager:CollectLinkedMass", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("CollectLinkedMass", ex.Message);
            }
        }
Exemplo n.º 16
0
        private void CollectHostMass(List <Element> massElements)
        {
            try
            {
                progressForm = new Form_ProgressBar();
                if (massElements.Count > 0)
                {
                    progressForm.Text       = "Finding Elements";
                    progressForm.LabelText  = "Finding elements intersecting with 3D mass in the host project . . .";
                    progressForm.LabelCount = massElements.Count.ToString() + " mass found";
                    progressForm.MaxValue   = massElements.Count;
                    progressForm.Show();
                    progressFormOpend = true;
                    progressForm.Refresh();
                }

                foreach (Element element in massElements)
                {
                    progressForm.PerformStep();
                    FamilyInstance fi = element as FamilyInstance;
                    if (null != fi)
                    {
                        MassProperties mp = new MassProperties(fi);
                        mp.WorksetId = fi.WorksetId.IntegerValue; //from host project

                        Solid   unionSolid = null;
                        Options opt        = m_app.Application.Create.NewGeometryOptions();
                        opt.ComputeReferences = true;
                        opt.DetailLevel       = Autodesk.Revit.DB.ViewDetailLevel.Fine;
                        GeometryElement geomElement = fi.get_Geometry(new Options(opt));
                        foreach (GeometryObject obj in geomElement)
                        {
                            Solid solid = obj as Solid;
                            if (null != solid)
                            {
                                if (solid.Volume > 0)
                                {
                                    if (unionSolid == null)
                                    {
                                        unionSolid = solid;
                                    }
                                    else
                                    {
                                        unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(solid, unionSolid, BooleanOperationsType.Union);
                                    }
                                }
                            }
                        }
                        mp.MassSolid = unionSolid;

                        if (null != unionSolid)
                        {
                            if (unionSolid.Volume > 0)
                            {
                                mp.ElementContainer = FindElementsInMass(m_doc, mp.MassSolid, mp.MassId, false);
                                List <Element> linkedElements = FindElementsInLInkedFiles(fi, geomElement);
                                mp.ElementContainer.AddRange(linkedElements);
                                mp.ElementCount = mp.ElementContainer.Count;
                            }
                        }

                        if (mp.MassParameters.Count > 0)
                        {
                            foreach (Parameter param in mp.MassParameters)
                            {
                                if (!massParameters.Contains(param.Definition.Name))
                                {
                                    massParameters.Add(param.Definition.Name);
                                }
                            }
                        }

                        mp.IsHost = true;
                        integratedMassList.Add(mp);
                    }
                }

                if (progressFormOpend)
                {
                    progressForm.Close();
                    progressFormOpend = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect mass elements from the host project.\n" + ex.Message, "LinkedModelManager:CollectHostMass", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("CollectHostMass", ex.Message);
            }
        }
Exemplo n.º 17
0
        private void DisplayIntersectingMasses()
        {
            try
            {
                if (massIds.Count > 1)
                {
                    int colWidth = (massIds.Count - 1) * 120;
                    if (splitOption)
                    {
                        colWidth += 120;
                    }

                    this.Size = new Size(this.Size.Width + colWidth, this.Size.Height);
                }

                if (!splitOption)
                {
                    dataGridViewElement.Columns[0].Visible = false;
                    bttnCheckAll.Enabled  = false;
                    bttnCheckNone.Enabled = false;
                }

                foreach (int massId in massIds)
                {
                    if (massDictionary.ContainsKey(massId))
                    {
                        DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                        column.Name        = massId.ToString();
                        column.HeaderText  = massDictionary[massId].MassName;
                        column.ToolTipText = massId.ToString();
                        column.ReadOnly    = true;
                        column.Width       = 110;

                        dataGridViewElement.Columns.Add(column);
                    }
                }

                DataGridViewComboBoxColumn comboColumn = new DataGridViewComboBoxColumn();
                comboColumn.Name         = "ColumnSelection";
                comboColumn.HeaderText   = "Selection";
                comboColumn.Width        = 110;
                comboColumn.FlatStyle    = FlatStyle.Flat;
                comboColumn.AutoComplete = true;
                dataGridViewElement.Columns.Add(comboColumn);

                //hidden massId column to create elementId-massId map
                DataGridViewTextBoxColumn massIdColumn = new DataGridViewTextBoxColumn();
                massIdColumn.Name       = "MassId";
                massIdColumn.HeaderText = "MassId";
                massIdColumn.Visible    = false;
                dataGridViewElement.Columns.Add(massIdColumn);

                int index = 0;
                foreach (int elementId in intersectingElements.Keys)
                {
                    ElementProperties ep = intersectingElements[elementId];
                    index = dataGridViewElement.Rows.Add();
                    dataGridViewElement.Rows[index].Tag            = ep;
                    dataGridViewElement.Rows[index].Cells[0].Value = true;
                    dataGridViewElement.Rows[index].Cells[1].Value = ep.ElementId.ToString();
                    dataGridViewElement.Rows[index].Cells[2].Value = ep.ElementName;
                    dataGridViewElement.Rows[index].Cells[3].Value = ep.CategoryName;

                    List <string> massNames = new List <string>();
                    massNames.Add("<Unassigned>");
                    double maxVal       = 0;
                    string selectedName = "";
                    int    maxId        = 0;
                    foreach (int massId in ep.MassContainers.Keys)
                    {
                        if (massDictionary.ContainsKey(massId))
                        {
                            string massName = massDictionary[massId].MassName;
                            if (ep.OpverappingMaps.Count > 0)
                            {
                                if (ep.OpverappingMaps.ContainsKey(massId))
                                {
                                    double ratio = ep.OpverappingMaps[massId];

                                    dataGridViewElement.Rows[index].Cells[massId.ToString()].Value = Math.Round(ratio, 2);
                                    if (ratio > maxVal)
                                    {
                                        maxVal       = ratio;
                                        selectedName = massName;
                                        maxId        = massId;
                                    }
                                }
                            }
                            massNames.Add(massName);
                        }
                    }

                    DataGridViewComboBoxCell comboCell = dataGridViewElement.Rows[index].Cells["ColumnSelection"] as DataGridViewComboBoxCell;
                    comboCell.DataSource = massNames;
                    if (ep.OpverappingMaps.Count > 0)
                    {
                        comboCell.Value = selectedName;
                    }
                    else
                    {
                        comboCell.Value = massNames[0]; maxId = 0;
                    }

                    dataGridViewElement.Rows[index].Cells["MassId"].Value = maxId;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display elements and intersecting masses.\n" + ex.Message, "Form_OverlapMass:DisplayIntersectingMasses", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("DisplayIntersectingMasses", ex.Message);
            }
        }
Exemplo n.º 18
0
        //find elements which intersect more than two mass elements.
        private void FindOverlaps()
        {
            try
            {
                if (elementDictionary.Count > 0)
                {
                    progressForm            = new Form_ProgressBar();
                    progressForm.Text       = "Finding Overlapping Conditions";
                    progressForm.LabelText  = "Finding elements intersecting with more than two mass elements...";
                    progressForm.LabelCount = elementDictionary.Count.ToString() + " elements found";
                    progressForm.MaxValue   = elementDictionary.Count;
                    progressForm.Show();
                    progressFormOpend = true;
                    progressForm.Refresh();
                }

                List <int> elementIds = elementDictionary.Keys.ToList();
                foreach (int elementId in elementIds)
                {
                    progressForm.PerformStep();
                    ElementProperties ep = elementDictionary[elementId];
                    if (ep.MassContainers.Count > 0)
                    {
                        Solid   unionSolid = null;
                        Options opt        = m_app.Application.Create.NewGeometryOptions();
                        opt.ComputeReferences = true;
                        opt.DetailLevel       = Autodesk.Revit.DB.ViewDetailLevel.Fine;

                        GeometryElement geomElement = ep.ElementObj.get_Geometry(new Options(opt));
                        geomElement = geomElement.GetTransformed(ep.TransformValue);

                        foreach (GeometryObject obj in geomElement)
                        {
                            Solid solid = obj as Solid;
                            if (null != solid)
                            {
                                if (solid.Volume > 0)
                                {
                                    if (unionSolid == null)
                                    {
                                        unionSolid = solid;
                                    }
                                    else
                                    {
                                        try { unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(solid, unionSolid, BooleanOperationsType.Union); }
                                        catch { }
                                    }
                                }
                            }
                        }
                        ep.ElementSolid = unionSolid;

                        Dictionary <int, double> overlapMap = new Dictionary <int, double>();
                        if (unionSolid != null)
                        {
                            if (unionSolid.Volume > 0)
                            {
                                foreach (int massId in ep.MassContainers.Keys)
                                {
                                    Solid massSolid      = ep.MassContainers[massId];
                                    Solid intersectSolid = null;
                                    try { intersectSolid = BooleanOperationsUtils.ExecuteBooleanOperation(massSolid, unionSolid, BooleanOperationsType.Intersect); }
                                    catch { intersectSolid = null; }
                                    if (null != intersectSolid)
                                    {
                                        if (intersectSolid.Volume > 0)
                                        {
                                            double ratio = intersectSolid.Volume / unionSolid.Volume;
                                            if (!overlapMap.ContainsKey(massId))
                                            {
                                                overlapMap.Add(massId, ratio);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        ep.OpverappingMaps = overlapMap;
                        elementDictionary.Remove(ep.ElementId);
                        elementDictionary.Add(ep.ElementId, ep);
                    }
                }

                if (progressFormOpend)
                {
                    progressForm.Close();
                    progressFormOpend = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find overlapping conditions.\n" + ex.Message, "LinkedModelManager:FindOverlaps", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("FindOverlaps", ex.Message);
            }
        }
Exemplo n.º 19
0
        private void buttonFilter_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewCategory.CheckedItems.Count > 0)
                {
                    List <ElementFilter> elementCatFilters = new List <ElementFilter>();
                    elementCategories.Clear();
                    foreach (ListViewItem item in listViewCategory.Items)
                    {
                        if (null != item.Tag)
                        {
                            Category category = (Category)item.Tag;
                            if (item.Checked)
                            {
                                ElementCategoryFilter catFilter = new ElementCategoryFilter(category.Id);
                                elementCatFilters.Add(catFilter);
                                elementCategories.Add(category, true);
                            }
                            else
                            {
                                elementCategories.Add(category, false);
                            }
                        }
                    }

                    LogicalOrFilter orFilter = new LogicalOrFilter(elementCatFilters);

                    for (int i = integratedMassList.Count - 1; i > -1; i--)
                    {
                        MassProperties   mp         = integratedMassList[i];
                        List <ElementId> elementIds = new List <ElementId>();
                        foreach (Element elem in mp.ElementContainer)
                        {
                            elementIds.Add(elem.Id);
                        }

                        if (elementIds.Count > 0)
                        {
                            List <Element>           filteredElement = new List <Element>();
                            FilteredElementCollector collector       = new FilteredElementCollector(m_doc, elementIds);

                            if (paramFilterActivated)
                            {
                                if (ValidateParamFilter())
                                {
                                    string paramValue = "";
                                    if (textBoxValue1.Visible)
                                    {
                                        paramValue = textBoxValue1.Text;
                                    }
                                    else if (!checkBoxEmpty1.Checked)
                                    {
                                        paramValue = cmbValue1.SelectedItem.ToString();
                                    }
                                    ElementFilter paramFilter1 = CreateParamFilter((int)cmbParamName1.SelectedValue, cmbOperation1.SelectedItem.ToString(), paramValue, checkBoxEmpty1.Checked);

                                    List <ElementId> elementIdList = collector.WherePasses(orFilter).ToElementIds().ToList();
                                    collector = new FilteredElementCollector(m_doc, elementIdList);
                                    if (radioButtonAnd.Checked)
                                    {
                                        if (textBoxValue2.Visible)
                                        {
                                            paramValue = textBoxValue2.Text;
                                        }
                                        else if (!checkBoxEmpty2.Checked)
                                        {
                                            paramValue = cmbValue2.SelectedItem.ToString();
                                        }
                                        ElementFilter paramFilter2 = CreateParamFilter((int)cmbParamName2.SelectedValue, cmbOperation2.SelectedItem.ToString(), paramValue, checkBoxEmpty2.Checked);
                                        if (null != paramFilter1 && null != paramFilter2)
                                        {
                                            LogicalAndFilter andFilter = new LogicalAndFilter(paramFilter1, paramFilter2);
                                            filteredElement = collector.WherePasses(andFilter).ToElements().ToList();
                                        }
                                    }
                                    else if (radioButtonOr.Checked)
                                    {
                                        if (textBoxValue2.Visible)
                                        {
                                            paramValue = textBoxValue2.Text;
                                        }
                                        else if (!checkBoxEmpty2.Checked)
                                        {
                                            paramValue = cmbValue2.SelectedItem.ToString();
                                        }
                                        ElementFilter paramFilter2 = CreateParamFilter((int)cmbParamName2.SelectedValue, cmbOperation2.SelectedItem.ToString(), paramValue, checkBoxEmpty2.Checked);
                                        if (null != paramFilter1 && null != paramFilter2)
                                        {
                                            LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter1, paramFilter2);
                                            filteredElement = collector.WherePasses(logicalOrFilter).ToElements().ToList();
                                        }
                                    }
                                    else if (radioButtonNone.Checked)
                                    {
                                        if (null != paramFilter1)
                                        {
                                            filteredElement = collector.WhereElementIsNotElementType().WherePasses(paramFilter1).ToElements().ToList();
                                        }
                                    }
                                    mp.FilteredContainer = filteredElement;
                                    integratedMassList.RemoveAt(i);
                                    integratedMassList.Add(mp);
                                    this.DialogResult = DialogResult.OK;
                                }
                            }
                            else
                            {
                                filteredElement      = collector.WherePasses(orFilter).ToElements().ToList();
                                mp.FilteredContainer = filteredElement;
                                integratedMassList.RemoveAt(i);
                                integratedMassList.Add(mp);
                                this.DialogResult = DialogResult.OK;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a category filter.\n" + ex.Message, "Form_ElementFilter:buttonFilter_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("buttonFilter_Click", ex.Message);
            }
        }
Exemplo n.º 20
0
        private void DisplayRvtLinkTypes()
        {
            try
            {
                FilteredElementCollector collector = new FilteredElementCollector(m_doc);
                collector.OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType();
                List <RevitLinkInstance> revitLinkInstances = collector.ToElements().Cast <RevitLinkInstance>().ToList();

                Dictionary <int /*typeId*/, RevitLinkType> linkTypes = new Dictionary <int, RevitLinkType>();
                foreach (RevitLinkInstance instance in revitLinkInstances)
                {
                    LinkedInstanceProperties lip = new LinkedInstanceProperties(instance);
                    ElementId typeId             = instance.GetTypeId();

                    RevitLinkType linkType = m_doc.GetElement(typeId) as RevitLinkType;
                    lip.FileName = linkType.Name;
                    lip.TypeId   = linkType.Id.IntegerValue;

                    if (!linkTypes.ContainsKey(linkType.Id.IntegerValue))
                    {
                        linkTypes.Add(linkType.Id.IntegerValue, linkType);
                    }

                    Parameter nameParam = instance.get_Parameter(BuiltInParameter.RVT_LINK_INSTANCE_NAME);
                    if (null != nameParam)
                    {
                        lip.InstanceName = nameParam.AsString();
                    }

                    foreach (Document document in m_app.Application.Documents)
                    {
                        if (lip.FileName.Contains(document.Title))
                        {
                            lip.LinkedDocument = document;
                            FilteredElementCollector linkedCollector = new FilteredElementCollector(document);
                            List <Element>           massElements    = linkedCollector.OfCategory(BuiltInCategory.OST_Mass).WhereElementIsNotElementType().ToElements().ToList();
                            lip.MassElements = massElements;
                            linkedMassDictionary.Add(lip.InstanceId, lip);
                            break;
                        }
                    }
                }

                foreach (int typeId in linkTypes.Keys)
                {
                    RevitLinkType linkType = linkTypes[typeId];
                    TreeNode      typeNode = new TreeNode(linkType.Name);
                    typeNode.Name = typeId.ToString();
                    typeNode.Tag  = linkType.Id;

                    foreach (int instanceId in linkedMassDictionary.Keys)
                    {
                        LinkedInstanceProperties lip = linkedMassDictionary[instanceId];
                        if (lip.TypeId == typeId)
                        {
                            TreeNode instanceNode = new TreeNode(lip.FileName + " : " + lip.InstanceName);
                            instanceNode.Name = lip.InstanceId.ToString();
                            instanceNode.Tag  = lip.InstanceId;

                            foreach (Element massElement in lip.MassElements)
                            {
                                TreeNode massNode = new TreeNode(massElement.Name);
                                massNode.Name = massElement.Id.ToString();
                                massNode.Tag  = massElement.Id;

                                instanceNode.Nodes.Add(massNode);
                            }
                            typeNode.Nodes.Add(instanceNode);
                        }
                    }
                    treeViewLinkedFile.Nodes.Add(typeNode);
                }
                treeViewLinkedFile.Sort();

                if (treeViewLinkedFile.Nodes.Count > 0)
                {
                    radioButtonLink.Enabled = true;
                    radioButtonAll.Enabled  = true;
                    radioButtonAll.Checked  = true;

                    foreach (TreeNode typeNode in treeViewLinkedFile.Nodes)
                    {
                        typeNode.Checked = true;
                        foreach (TreeNode instanceNode in typeNode.Nodes)
                        {
                            instanceNode.Checked = true;
                            foreach (TreeNode massNode in instanceNode.Nodes)
                            {
                                massNode.Checked = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display RevitLinkTypes.\n" + ex.Message, "Form_LinkedFiles:DisplayRvtLinkTypes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("DisplayRvtLinkTypes", ex.Message);
            }
        }
Exemplo n.º 21
0
        public void WriteINI()
        {
            try
            {
                if (File.Exists(iniPath))
                {
                    //delete all
                    string tempFile = Path.GetTempFileName();
                    using (StreamReader sr = new StreamReader(iniPath))
                    {
                        using (StreamWriter sw = new StreamWriter(tempFile))
                        {
                            string line;

                            while ((line = sr.ReadLine()) != null)
                            {
                                sw.WriteLine("");
                            }
                        }
                    }
                    File.Delete(iniPath);
                    File.Move(tempFile, iniPath);

                    FileStream fs = File.Open(iniPath, FileMode.Create);
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        string sp = "##";
                        foreach (int elemnetId in splitDictionary.Keys)
                        {
                            SplitINIData splitData = splitDictionary[elemnetId];
                            string       line      = splitData.CategoryName + sp + splitData.ElementId + sp;

                            string primaryIds = "";
                            for (int i = 0; i < splitData.PrimaryElementIds.Count; i++)
                            {
                                if (i == 0)
                                {
                                    primaryIds += splitData.PrimaryElementIds[i];
                                }
                                else
                                {
                                    primaryIds += "," + splitData.PrimaryElementIds[i];
                                }
                            }
                            line += primaryIds + sp;

                            string secondaryIds = "";
                            for (int i = 0; i < splitData.SecondaryElementIds.Count; i++)
                            {
                                if (i == 0)
                                {
                                    secondaryIds += splitData.SecondaryElementIds[i];
                                }
                                else
                                {
                                    secondaryIds += "," + splitData.SecondaryElementIds[i];
                                }
                            }
                            line += secondaryIds;
                            sw.WriteLine(line);
                        }
                        sw.Close();
                    }
                    fs.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write the INI file.\n" + ex.Message, "SplitINIDataManager:WriteINI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogFileManager.AppendLog("WriteINI", ex.Message);
            }
        }