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