Beispiel #1
0
        private bool DetailWithView(Document doc, string transactionName, string cpSettingsString, View3D view, ShowDialogType dialogType, Func <List <ElementId> > GetElementIds)
        {
            bool isSuccess;

            ListForm.ShowDialogType = dialogType;
            string viewName = dialogType.GetViewName();

            isSuccess = DealWithTransaction(viewName, doc, transactionName, () =>
            {
                view = Revit_Document_Helper.GetElementByNameAs <View3D>(UI_Doc.Document, viewName);
                if (view == null)
                {
                    view = Revit_Document_Helper.Create3DView(doc, viewName);
                }
                ////渲染_所有 隐藏
                //IList<Element> allElements = GetAllElements(doc);
                //List<ElementId> elementIdsToHid = new List<ElementId>();
                //foreach (var element in allElements)
                //    if (element.CanBeHidden(view) && element.Id != view.Id)
                //        elementIdsToHid.Add(element.Id);
                //if (elementIdsToHid.Count > 0)
                //    view.HideElements(elementIdsToHid);
                ////渲染_测点 淡显,显示
                //var allNodesElementIds = Model.GetAllNodesElementIds(doc);
                //var defaultOverrideGraphicSettings = CPSettings.GetTingledOverrideGraphicSettings(doc);
                //if (allNodesElementIds.Count > 0)
                //    view.UnhideElements(allNodesElementIds);
                //foreach (var elementId in allNodesElementIds)
                //    view.SetElementOverrides(elementId, defaultOverrideGraphicSettings);
                //渲染_选中 选中颜色显示
                var cpSettings = new CPSettings(cpSettingsString);
                var overrideGraphicSettings = Revit_Helper.GetOverrideGraphicSettings(new Color(cpSettings.Color.R, cpSettings.Color.G, cpSettings.Color.B), new ElementId(cpSettings.FillerId), cpSettings.SurfaceTransparency);
                var selectedElementIds      = GetElementIds();
                foreach (var elementId in selectedElementIds)
                {
                    view.SetElementOverrides(elementId, overrideGraphicSettings);
                }
            });
            if (view != null)
            {
                UI_Doc.ActiveView = view;
            }
            return(isSuccess);
        }
        private void SetElementTransparency(View3D view3d, Dictionary <int, Element> elementDictionary)
        {
            try
            {
                this.toolStripProgressBar1.Visible = true;
                this.toolStripStatusLabel1.Text    = "Setting Transparency of Elements...";
                Application.DoEvents();
                System.Threading.Thread.Sleep(1000);

                OverrideGraphicSettings settings = new OverrideGraphicSettings();
                settings.SetSurfaceTransparency(70);
                settings.SetHalftone(true);

                BoundingBoxXYZ boundingBox                      = view3d.GetSectionBox();
                Outline        outline                          = new Outline(boundingBox.Min, boundingBox.Max);
                BoundingBoxIntersectsFilter filter              = new BoundingBoxIntersectsFilter(outline);
                FilteredElementCollector    collector           = new FilteredElementCollector(m_doc);
                IList <Element>             boundingBoxElements = collector.WherePasses(filter).ToElements();

                this.toolStripProgressBar1.Maximum = boundingBoxElements.Count;
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.ProgressBar.Refresh();

                foreach (Element element in boundingBoxElements)
                {
                    if (elementDictionary.ContainsKey(element.Id.IntegerValue))
                    {
                        continue;
                    }
                    view3d.SetElementOverrides(element.Id, settings);
                    this.toolStripProgressBar1.PerformStep();
                }
                this.toolStripProgressBar1.Visible = false;
                this.toolStripStatusLabel1.Text    = "Ready";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a 3DView named " + selectedView + "\n" + ex.Message, "CommandForm:Create3DView", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 视图逻辑处理
        /// 支持(隐藏,淡显,红显)和(反隐藏,淡显,红显)
        /// </summary>
        /// <param name="showDialogType"></param>
        /// <param name="needHide"></param>
        /// <param name="getElementIds"></param>
        /// <returns></returns>
        private bool DetailWithView(ShowDialogType showDialogType, bool needHide, Func <Document, List <ElementId> > getElementIds)
        {
            ListForm.ShowDialogType = showDialogType;
            string viewName        = ListForm.ShowDialogType.GetViewName();
            var    doc             = UI_Doc.Document;
            View3D view            = null;
            var    transactionName = nameof(SubsidenceMonitor) + nameof(btn_ViewSelection_Click);
            bool   isSuccess       = DealWithTransaction(viewName, doc, transactionName, () =>
            {
                view = Revit_Document_Helper.GetElementByNameAs <View3D>(UI_Doc.Document, viewName);
                if (view == null)
                {
                    view = Revit_Document_Helper.Create3DView(doc, viewName);
                }
                if (needHide)
                {
                    //渲染_所有 隐藏
                    IList <Element> allElements      = GetAllElements(doc);
                    List <ElementId> elementIdsToHid = new List <ElementId>();
                    foreach (var element in allElements)
                    {
                        if (element.CanBeHidden(view) && element.Id != view.Id)
                        {
                            elementIdsToHid.Add(element.Id);
                        }
                    }
                    if (elementIdsToHid.Count > 0)
                    {
                        view.HideElements(elementIdsToHid);
                    }
                    //渲染_测点 淡显
                    var nodesElementIds = Model.GetAllNodesElementIdsByTNode(doc);
                    if (nodesElementIds.Count > 0)
                    {
                        view.UnhideElements(nodesElementIds);
                    }
                    var defaultOverrideGraphicSettings = CPSettings.GetTingledOverrideGraphicSettings(doc);
                    foreach (var elementId in nodesElementIds)
                    {
                        view.SetElementOverrides(elementId, defaultOverrideGraphicSettings);
                    }
                }
                else
                {
                    ////渲染_所有 反隐藏
                    //IList<Element> allElements = GetAllElements(doc);
                    //List<ElementId> elementIdsToHid = new List<ElementId>();
                    //foreach (var element in allElements)
                    //    if (element.CanBeHidden(view) && element.Id != view.Id)
                    //        elementIdsToHid.Add(element.Id);
                    //view.UnhideElements(elementIdsToHid);
                    //渲染_所有 淡显
                    var allElementIds = GetAllElements(doc);
                    var defaultOverrideGraphicSettings = CPSettings.GetTingledOverrideGraphicSettings(doc);
                    foreach (var elementId in allElementIds)
                    {
                        view.SetElementOverrides(elementId.Id, defaultOverrideGraphicSettings);
                    }
                }
                //渲染_选中 红显
                var overrideGraphicSettings = Revit_Helper.GetOverrideGraphicSettings(ColorForSelectedElements, CPSettings.GetDefaultFillPatternId(doc), 0);
                var selectedElementIds      = getElementIds(doc);
                foreach (var elementId in selectedElementIds)
                {
                    view.SetElementOverrides(elementId, overrideGraphicSettings);
                }
            });

            if (view != null)
            {
                UI_Doc.ActiveView = view;
            }
            return(isSuccess);
        }
        void AdjustColumnHeightsUsingReferenceIntersector(
            Document doc,
            IList <ElementId> ids)
        {
            View3D view = doc.ActiveView as View3D;

            if (null == view)
            {
                throw new Exception(
                          "Please run this command in a 3D view.");
            }

            int allColumns     = 0;
            int successColumns = 0;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Attach Columns Tops");

                foreach (ElementId elemId in ids)
                {
                    Element elem = doc.GetElement(elemId);

                    if ((BuiltInCategory)elem.Category.Id.IntegerValue
                        == BuiltInCategory.OST_StructuralColumns)
                    {
                        allColumns++;

                        FamilyInstance column = elem as FamilyInstance;

                        // Collect beams and slabs

                        List <BuiltInCategory> builtInCats = new List <BuiltInCategory>();
                        builtInCats.Add(BuiltInCategory.OST_Floors);
                        builtInCats.Add(BuiltInCategory.OST_StructuralFraming);
                        ElementMulticategoryFilter filter
                            = new ElementMulticategoryFilter(builtInCats);

                        // Remove old column attachement

                        if (ColumnAttachment.GetColumnAttachment(column, 1) != null)
                        {
                            ColumnAttachment.RemoveColumnAttachment(column, 1);
                        }

                        BoundingBoxXYZ elemBB = elem.get_BoundingBox(view);

                        XYZ elemLoc    = (elem.Location as LocationPoint).Point;
                        XYZ elemCenter = new XYZ(elemLoc.X, elemLoc.Y, elemLoc.Z + 0.1);
                        XYZ b1         = new XYZ(elemBB.Min.X, elemBB.Min.Y, elemBB.Min.Z + 0.1);
                        XYZ b2         = new XYZ(elemBB.Max.X, elemBB.Max.Y, elemBB.Min.Z + 0.1);
                        XYZ b3         = new XYZ(elemBB.Min.X, elemBB.Max.Y, elemBB.Min.Z + 0.1);
                        XYZ b4         = new XYZ(elemBB.Max.X, elemBB.Min.Y, elemBB.Min.Z + 0.1);

                        List <XYZ> points = new List <XYZ>(5);
                        points.Add(b1);
                        points.Add(b2);
                        points.Add(b3);
                        points.Add(b4);
                        points.Add(elemCenter);

                        ReferenceIntersector refI = new ReferenceIntersector(
                            filter, FindReferenceTarget.All, view);

                        XYZ rayd = XYZ.BasisZ;
                        ReferenceWithContext refC = null;
                        foreach (XYZ pt in points)
                        {
                            refC = refI.FindNearest(pt, rayd);
                            if (refC != null)
                            {
                                break;
                            }
                        }

                        if (refC != null)
                        {
                            Reference reference = refC.GetReference();
                            ElementId id        = reference.ElementId;
                            Element   e         = doc.GetElement(id);

                            ColumnAttachment.AddColumnAttachment(
                                doc, column, e, 1,
                                ColumnAttachmentCutStyle.None,
                                ColumnAttachmentJustification.Minimum,
                                0);

                            successColumns++;
                        }
                        else
                        {
                            // Change color of columns to red

                            Color color = new Color((byte)255, (byte)0, (byte)0);
                            OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                            ogs.SetProjectionLineColor(color);
                            view.SetElementOverrides(elem.Id, ogs);
                        }
                    }
                }
                tx.Commit();
            }
        }