Esempio n. 1
0
        //----------------------------------------------------------
        void ResetView(UIApplication uiapp, Document doc)
        {
            try
            {
                View viewCurrent = doc.ActiveView;
                if (viewCurrent.IsTemporaryHideIsolateActive())
                {
                    TemporaryViewMode tempView = TemporaryViewMode.TemporaryHideIsolate;
                    viewCurrent.DisableTemporaryViewMode(tempView);
                }

                //var UIView = uiapp.ActiveUIDocument.GetOpenUIViews();
                //foreach (var view in UIView)
                //{
                //    if (view.ViewId == viewCurrent.Id)
                //    {
                //        view.ZoomToFit();
                //    }
                //}
                View3D view1 = viewCurrent as View3D;
                view1.IsSectionBoxActive = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR in Reset View" + "\n" + ex.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //
            DllActivator_eZRvt dat = new DllActivator_eZRvt();

            dat.ActivateReferences();
            //
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;

            //
            ConduitLevelFilter clf = ConduitLevelFilter.GetUniqueConduitLevelFilter(uiDoc);
            DialogResult       res = clf.ShowDialog();

            if (res != DialogResult.OK)
            {
                return(Result.Cancelled);
            }

            //
            FilterOption filterOptions = clf.FilterOptions;


            // 过滤出来的线管与弯头对象
            var elems = uiDoc.Selection.GetElementIds();
            List <ConduitLine> lines = FilterConduits(doc, elems);

            //   uiDoc.Selection.SetElementIds(lines.Select(r => r.Line.Id).ToList());

            //
            using (Transaction transa = new Transaction(doc, "线管布线"))
            {
                try
                {
                    transa.Start();

                    bool             inRange;
                    List <ElementId> elemsInRange  = new List <ElementId>();
                    List <ElementId> elemsOutRange = new List <ElementId>();
                    foreach (ConduitLine line in lines)
                    {
                        // 检查此线管是否要被隐藏
                        if (filterOptions.CheckAllConnector) // 此线管中只要有一个 Connector 不在视图范围内,则将其隐藏
                        {
                            inRange = true;
                            foreach (Connector connector in line.ConnectorManager.Connectors)
                            {
                                if (!IsWithinElevationRange(connector.Origin.Z, filterOptions))
                                {
                                    inRange = false;
                                    continue;
                                }
                            }
                        }
                        else // 此线管中只要有一个 Connector 在视图范围内,则不将其隐藏
                        {
                            inRange = false;
                            foreach (Connector connector in line.ConnectorManager.Connectors)
                            {
                                if (IsWithinElevationRange(connector.Origin.Z, filterOptions))
                                {
                                    inRange = true;
                                    continue;
                                }
                            }
                        }

                        if (inRange)
                        {
                            elemsInRange.Add(line.Line.Id);
                        }
                        else
                        {
                            elemsOutRange.Add(line.Line.Id);
                        }
                    }

                    View v = uiDoc.ActiveView;
                    // 先解除临时隐藏模式
                    v.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);

                    // 隐藏线管
                    if (filterOptions.ShowElementsInRange)
                    {
                        // if (elemsInRange.Count > 0) v.UnhideElements(elemsInRange);
                        //
                        if (elemsOutRange.Count > 0)
                        {
                            v.HideElementsTemporary(elemsOutRange);
                        }
                    }
                    else
                    {
                        if (elemsInRange.Count > 0)
                        {
                            v.HideElementsTemporary(elemsInRange);
                        }
                        // if (elemsOutRange.Count > 0) v.UnhideElements(elemsOutRange);
                    }

                    transa.Commit();
                    return(Result.Succeeded);

                    ;
                }
                catch (Exception ex)
                {
                    transa.RollBack();

                    message = ex.Message + "\r\n" + ex.StackTrace;
                    return(Result.Failed);

                    ;
                }
            }
        }