Пример #1
0
        private ElementArray GetSimilarForElement(ElementId elementId)
        {
            ElementArray ea = null;

            if (elementId != null)
            {
                ElementType et = _doc.GetElement(elementId) as ElementType;

                if (et != null)
                {
                    ea = new ElementArray();

                    foreach (ElementId eid in et.GetSimilarTypes())
                    {
                        ea.Append(_doc.GetElement(eid));
                    }
                }
            }

            return(ea);
        }
Пример #2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication           uiapp = commandData.Application;
            UIDocument              uidoc = uiapp.ActiveUIDocument;
            Application             app = uiapp.Application;
            Document                doc = uidoc.Document;
            Selection               SelectedObjs = uidoc.Selection;
            ICollection <ElementId> ids = uidoc.Selection.GetElementIds();
            Line           dimDirCross = null; Line dimDir = null;
            int            selectdim  = 0;
            bool           updateMode = false;
            ElementArray   dimensions = new ElementArray();
            ReferenceArray dimto = new ReferenceArray();

            GetMenuValues(uiapp);
            foreach (ElementId eid in ids)
            {
                if (doc.GetElement(eid).GetType() == typeof(Grid))
                {
                    Grid grid = doc.GetElement(eid) as Grid;
                    dimto.Append(new Reference(grid));
                }
                else if (doc.GetElement(eid).GetType() == typeof(Dimension))
                {
                    updateMode = true;
                    dimensions.Append(doc.GetElement(eid));
                }
                else
                {
                    GeometryElement geom    = doc.GetElement(eid).get_Geometry(Store.Dimop(doc.ActiveView));
                    Line            refLine = GetLineOfGeom(geom);
                    if (selectdim == 0)
                    {
                        dimDir      = Line.CreateBound(refLine.GetEndPoint(0), refLine.GetEndPoint(1));
                        dimDirCross = RackDim.GetPerpendicular(dimDir, Store.mod_place);
                        selectdim   = 1;
                    }
                    dimto.Append(refLine.Reference);
                }
            }
            if (updateMode)
            {
                foreach (Element elem in dimensions)
                {
                    selectdim = 0;
                    Dimension      dim        = elem as Dimension;
                    ReferenceArray updatedref = new ReferenceArray();
                    foreach (Reference refe in dim.References)
                    {
                        if (doc.GetElement(refe.ElementId).GetType() == typeof(Grid))
                        {
                            Grid grid = doc.GetElement(refe.ElementId) as Grid;
                            updatedref.Append(new Reference(grid));
                        }
                        else
                        {
                            GeometryElement geom    = doc.GetElement(refe.ElementId).get_Geometry(Store.Dimop(doc.ActiveView));
                            Line            refLine = GetLineOfGeom(geom);
                            if (selectdim == 0)
                            {
                                dimDir      = Line.CreateBound(refLine.GetEndPoint(0), refLine.GetEndPoint(1));
                                dimDirCross = RackDim.GetPerpendicular(dimDir, Store.mod_place);
                                selectdim   = 1;
                            }
                            updatedref.Append(refLine.Reference);
                        }
                    }
                    RackDim.CreateRackDim(doc, uiapp, dimDir, dimDirCross, updatedref);
                    using (Transaction deltrans = new Transaction(doc))
                    {
                        deltrans.Start("Update Dimension");
                        doc.Delete(elem.Id);
                        deltrans.Commit();
                    }
                }
            }
            else
            {
                RackDim.CreateRackDim(doc, uiapp, dimDir, dimDirCross, dimto);
            }
            return(Result.Succeeded);
        }