Пример #1
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();

                    MassProperties mp = new MassProperties(element);
                    mp.WorksetId = element.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 = element.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(element, 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)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
Пример #2
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();
                            MassProperties mp         = new MassProperties(massElement);
                            Solid          unionSolid = null;
                            Options        opt        = m_app.Application.Create.NewGeometryOptions();
                            opt.ComputeReferences = true;
                            opt.DetailLevel       = Autodesk.Revit.DB.ViewDetailLevel.Fine;

                            GeometryElement geomElement = massElement.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(massElement, 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)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
Пример #3
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)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }