Exemplo n.º 1
0
        private void BtnConnect_Click(object sender, EventArgs e)
        {
            if (tbId1.Enabled || tbId2.Enabled)
            {
                Elms = new List <Element>();

                var b1  = int.TryParse(tbId1.Text.Trim(), out var id1);
                var b2  = int.TryParse(tbId2.Text.Trim(), out var id2);
                var ids = new FilteredElementCollector(Uidoc.Document)
                          .ToElementIds()
                          .Select(s => s.IntegerValue)
                          .ToList();

                if (b1 && b2 && ids.Contains(id1) && ids.Contains(id2))
                {
                    var elm1 = Uidoc.Document.GetElement(new ElementId(id1));
                    var elm2 = Uidoc.Document.GetElement(new ElementId(id2));

                    Elms.Add(elm1);
                    Elms.Add(elm2);
                }
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Exemplo n.º 2
0
 /// <summary>
 /// 生成单管选管标注
 /// </summary>
 /// <param name="datadoc"></param>
 private void GenerateSinglePipeTag(Document savedoc, Document datadoc)
 {
     DelegateHelper.DelegateTransaction(savedoc, "一键单管直径标注", () =>
     {
         var pipeIdInThisViews = new FilteredElementCollector(datadoc, View.Id).OfCategory(BuiltInCategory.OST_PipeTags)
                                 .WhereElementIsNotElementType()
                                 .Select(c => (c as IndependentTag).TaggedLocalElementId).ToList().Distinct();
         var pipes = new FilteredElementCollector(datadoc).OfCategory(BuiltInCategory.OST_PipeCurves).WhereElementIsNotElementType().ToList();
         foreach (var pipe in pipes)
         {
             //0728长度过滤
             if (!CheckFilter(pipe))
             {
                 continue;
             }
             if (!pipeIdInThisViews.Contains(pipe.Id))
             {
                 var setting     = PipeAnnotationCmd.PipeAnnotationUIData.SettingForSingle;
                 var headerPoint = setting.GetHeaderPoint(pipe as Pipe);
                 var tag         = savedoc.Create.NewTag(View, pipe, setting.NeedLeader, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, headerPoint);
             }
         }
         return(true);
     });
 }
Exemplo n.º 3
0
        private void BtnLocate_Click(object sender, EventArgs e)
        {
            var b1  = int.TryParse(tbId1.Text.Trim(), out var id1);
            var b2  = int.TryParse(tbId2.Text.Trim(), out var id2);
            var b3  = int.TryParse(tbId1.Text.Trim(), out var id3);
            var b4  = int.TryParse(tbId2.Text.Trim(), out var id4);
            var b5  = int.TryParse(tbId1.Text.Trim(), out var id5);
            var ids = new FilteredElementCollector(Uidoc.Document)
                      .ToElementIds()
                      .Select(s => s.IntegerValue)
                      .ToList();

            if (b1 && ids.Contains(id1))
            {
                Elms.Add(Uidoc.Document.GetElement(new ElementId(id1)));
            }

            if (b2 && ids.Contains(id2))
            {
                Elms.Add(Uidoc.Document.GetElement(new ElementId(id2)));
            }

            if (b3 && ids.Contains(id3))
            {
                Elms.Add(Uidoc.Document.GetElement(new ElementId(id3)));
            }

            if (b4 && ids.Contains(id4))
            {
                Elms.Add(Uidoc.Document.GetElement(new ElementId(id4)));
            }

            if (b5 && ids.Contains(id5))
            {
                Elms.Add(Uidoc.Document.GetElement(new ElementId(id5)));
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Exemplo n.º 4
0
        public View ReferenceViews()
        {
            View viewrf = null;
            View view   = doc.ActiveView;
            FilteredElementCollector viewersCollector = new FilteredElementCollector(doc);

            viewersCollector.OfCategory(BuiltInCategory.OST_Viewers);
            Element elem = null;

            foreach (Element e in viewersCollector)
            {
                if (e.Name == view.Name)
                {
                    elem = e;
                }
            }

            if (elem != null)
            {
                DateTime start = DateTime.Now;
                FilterableValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEWPORT_SHEET_NUMBER));
                FilterRule               rule    = new FilterStringRule(provider, new FilterStringGreater(), string.Empty, false);
                ElementParameterFilter   epf     = new ElementParameterFilter(rule, false);
                FilteredElementCollector viewCol = new FilteredElementCollector(doc).WherePasses(epf);
                viewCol.OfClass(typeof(View));

                StringBuilder sb = new StringBuilder();
                foreach (View v in viewCol)
                {
                    if (v.Id.IntegerValue == view.Id.IntegerValue || v.IsTemplate || v.ViewType == ViewType.DrawingSheet || v.ViewType == ViewType.ColumnSchedule)
                    {
                        continue;
                    }
                    try
                    {
                        ICollection <ElementId> col = new FilteredElementCollector(doc, v.Id).ToElementIds();
                        if (col.Contains(elem.Id))
                        {
                            sb.AppendLine("View: " + v.Name);
                        }
                        viewrf = v;
                    }
                    catch { }
                }
            }
            return(viewrf);
        }
Exemplo n.º 5
0
        //----------------------------------------------------------
        public void Data_Pick_Element(UIDocument uidoc, Document doc,
                                      RadioButton center_mid_point, RadioButton line, RadioButton arc, RadioButton ellipse, RadioButton pick)
        {
            mySource = new ListSource();

            Selection selection = uidoc.Selection;

            if (center_mid_point.IsChecked == true && center_mid_point.IsEnabled == true)
            {
                List <XYZ> support = new List <XYZ>();
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select center point"));
                data_point = new geometry_data()
                {
                    name       = mySource.list_option_selection_name[0],
                    list_point = support
                };
            }
            if (line.IsChecked == true)
            {
                List <XYZ> support = new List <XYZ>();
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select start point"));
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select end point"));
                data_point = new geometry_data()
                {
                    name       = mySource.list_option_selection_name[1],
                    list_point = support
                };
            }
            if (arc.IsChecked == true && arc.IsEnabled == true)
            {
                List <XYZ> support = new List <XYZ>();
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select center point"));
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select start point"));
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select end point, not same start point"));
                data_point = new geometry_data()
                {
                    name       = mySource.list_option_selection_name[2],
                    list_point = support
                };
            }
            if (ellipse.IsChecked == true && ellipse.IsEnabled == true)
            {
                List <XYZ> support = new List <XYZ>();
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select start point define radius x"));
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select end point define radius x"));
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select start point define radius y"));
                support.Add(selection.PickPoint(ObjectSnapTypes.Endpoints | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Centers | ObjectSnapTypes.Intersections | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Nearest | ObjectSnapTypes.Quadrants, "Select end point define radius y"));
                data_point = new geometry_data()
                {
                    name       = mySource.list_option_selection_name[3],
                    list_point = support
                };
            }
            if (pick.IsChecked == true)
            {
                var            refe     = selection.PickObject(ObjectType.PointOnElement, "Select reference of element");
                Element        element  = doc.GetElement(refe);
                GeometryObject geometry = element.GetGeometryObjectFromReference(refe);

                List <string> my_cad_link = new FilteredElementCollector(doc).OfClass(typeof(CADLinkType)).Cast <CADLinkType>().Select(x => x.Name).ToList();
                if (my_cad_link.Count() > 0 && my_cad_link.Contains(doc.GetElement(element.UniqueId).Category.Name))
                {
                    GeometryElement elem = element.get_Geometry(new Options());
                    if (elem != null)
                    {
                        foreach (GeometryObject geometryObject in elem)
                        {
                            GeometryInstance gInstance = geometryObject as GeometryInstance;
                            if (null != gInstance)
                            {
                                origin = gInstance.Transform.Origin;
                            }
                        }
                    }
                }

                if (geometry is Line)
                {
                    Line polyLine = geometry as Line;

                    data_point = new geometry_data()
                    {
                        name = mySource.list_option_selection_name[4],
                        line = polyLine
                    };
                }
                else if (geometry is PolyLine)
                {
                    PolyLine polyLine = geometry as PolyLine;
                    data_point = new geometry_data()
                    {
                        name     = mySource.list_option_selection_name[5],
                        polyLine = polyLine
                    };
                }
                else if (geometry is Arc)
                {
                    Arc polyLine = geometry as Arc;

                    data_point = new geometry_data()
                    {
                        name = mySource.list_option_selection_name[6],
                        arc  = polyLine
                    };
                }
                else if (geometry is Ellipse)
                {
                    Ellipse polyLine = geometry as Ellipse;

                    data_point = new geometry_data()
                    {
                        name    = mySource.list_option_selection_name[6],
                        ellipse = polyLine
                    };
                }
            }
        }
        /// <summary>
        /// Выполнить процедуру слияния выбранных размеров
        /// </summary>
        public void MergeExecute()
        {
            var          selection   = _application.ActiveUIDocument.Selection;
            var          doc         = _application.ActiveUIDocument.Document;
            var          prompt      = Language.GetItem(new ModPlusConnector().Name, "h1");
            const double tol         = 0.0001;
            var          elementsIds = new FilteredElementCollector(doc, doc.ActiveView.Id)
                                       .WhereElementIsNotElementType()
                                       .Select(e => e.Id.IntegerValue)
                                       .ToList();

            while (true)
            {
                try
                {
                    var dimensions = selection
                                     .PickElementsByRectangle(new DimensionsFilter(), prompt)
                                     .OfType <Dimension>().ToList();

                    var byDimLineDictionary = new Dictionary <Line, List <Dimension> >();
                    foreach (var dimension in dimensions)
                    {
                        if (!(dimension.Curve is Line line))
                        {
                            continue;
                        }

                        var isMatch = false;
                        foreach (var pair in byDimLineDictionary)
                        {
                            if ((Math.Abs(pair.Key.Origin.DistanceTo(line.Origin)) < tol &&
                                 Math.Abs(Math.Abs(pair.Key.Direction.DotProduct(line.Direction)) - 1) < tol) ||
                                Math.Abs(Math.Abs(pair.Key.Direction.DotProduct(Line.CreateBound(pair.Key.Origin, line.Origin).Direction)) - 1) < tol)
                            {
                                isMatch = true;
                                pair.Value.Add(dimension);
                                break;
                            }
                        }

                        if (!isMatch)
                        {
                            byDimLineDictionary.Add(line, new List <Dimension> {
                                dimension
                            });
                        }
                    }

                    var transactionName = Language.GetFunctionLocalName(new ModPlusConnector());
                    if (string.IsNullOrEmpty(transactionName))
                    {
                        transactionName = "Merge dimensions";
                    }

                    using (var t = new TransactionGroup(doc, transactionName))
                    {
                        t.Start();
                        foreach (var pair in byDimLineDictionary)
                        {
                            if (pair.Value.Count < 1)
                            {
                                continue;
                            }
                            try
                            {
                                using (var tr = new Transaction(doc, "Merge dims"))
                                {
                                    tr.Start();

                                    var referenceArray = new ReferenceArray();
                                    var view           = pair.Value.First().View;
                                    var type           = pair.Value.First().DimensionType;
                                    var dimsData       = new List <DimData>();
                                    foreach (var d in pair.Value)
                                    {
                                        if (d.NumberOfSegments > 0)
                                        {
                                            dimsData.AddRange(from DimensionSegment segment in d.Segments select new DimData(segment));
                                        }
                                        else
                                        {
                                            dimsData.Add(new DimData(d));
                                        }

                                        foreach (Reference reference in d.References)
                                        {
                                            if (reference.ElementId != ElementId.InvalidElementId &&
                                                !elementsIds.Contains(reference.ElementId.IntegerValue))
                                            {
                                                continue;
                                            }

                                            if (reference.ElementId != ElementId.InvalidElementId &&
                                                doc.GetElement(reference.ElementId) is Grid grid)
                                            {
                                                referenceArray.Append(new Reference(grid));
                                            }
                                            else if (reference.ElementId != ElementId.InvalidElementId &&
                                                     doc.GetElement(reference.ElementId) is Level level)
                                            {
                                                referenceArray.Append(new Reference(level));
                                            }
                                            else
                                            {
                                                referenceArray.Append(reference);
                                            }
                                        }
                                    }

                                    if (doc.Create.NewDimension(view, pair.Key, referenceArray, type) is Dimension createdDimension)
                                    {
                                        if (ModPlus_Revit.Utils.Dimensions.TryRemoveZeroes(createdDimension, out referenceArray))
                                        {
                                            if (doc.Create.NewDimension(view, pair.Key, referenceArray, type) is Dimension reCreatedDimension)
                                            {
                                                doc.Delete(createdDimension.Id);
                                                RestoreTextFields(reCreatedDimension, dimsData);
                                            }
                                        }
                                        else
                                        {
                                            RestoreTextFields(createdDimension, dimsData);
                                        }

                                        doc.Delete(pair.Value.Select(d => d.Id).ToList());
                                    }

                                    tr.Commit();
                                }
                            }
                            catch (Exception exception)
                            {
                                ExceptionBox.Show(exception);
                            }
                        }

                        t.Assimilate();
                    }
                }
                catch (Autodesk.Revit.Exceptions.OperationCanceledException)
                {
                    break;
                }
            }
        }