Esempio n. 1
0
        Move()
        {
            XYZ vec = new XYZ(10.0, 10.0, 0.0);

            ElementTransformUtils.MoveElements(
                m_revitApp.ActiveUIDocument.Document,
                m_revitApp.ActiveUIDocument.Selection.GetElementIds(),
                vec
                );
        }
        /// <summary>
        /// Edit filled region by moving it back and forth
        /// to make its boundary lines reappear after
        /// deleting the line style. From:
        /// http://forums.autodesk.com/t5/revit-api/filled-region/td-p/5796463
        /// </summary>
        public void EditFilledRegion(Document doc)
        {
            ICollection <ElementId> fillRegionIds
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(FilledRegion))
                  .ToElementIds();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Move all Filled Regions");

                XYZ v = XYZ.BasisX;
                ElementTransformUtils.MoveElements(doc, fillRegionIds, v);
                ElementTransformUtils.MoveElements(doc, fillRegionIds, -v);

                tx.Commit();
            }
        }
Esempio n. 3
0
        public static Result Move(UIApplication uiApp)
        {
            Document   doc   = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;

            try
            {
                using (TransactionGroup txGp = new TransactionGroup(doc))
                {
                    txGp.Start("Move elements to distance!");

                    Selection selection = uidoc.Selection;
                    var       selIds    = selection.GetElementIds();
                    if (selIds.Count == 0)
                    {
                        throw new Exception("Empty selection: must select element(s) to move first!");
                    }

                    HashSet <Element> elsToMove = selIds.Select(x => doc.GetElement(x)).ToHashSet();

                    var     elId     = uidoc.Selection.PickObject(ObjectType.Element, "Select element to move to!");
                    Element MoveToEl = doc.GetElement(elId);
                    double  distanceToKeep;

                    //Ask for a length input
                    InputBoxBasic ds = new InputBoxBasic();
                    ds.ShowDialog();
                    distanceToKeep = double.Parse(ds.DistanceToKeep).MmToFt();

                    //Business logic to move but keep desired distance
                    HashSet <Connector> toMoveCons = SpecialGetAllConnectors(elsToMove);

                    HashSet <Connector> moveToCons = SpecialGetAllConnectors(new HashSet <Element> {
                        MoveToEl
                    });

                    var listToCompare = new List <(Connector toMoveCon, Connector MoveToCon, double Distance)>();

                    foreach (Connector c1 in toMoveCons)
                    {
                        foreach (Connector c2 in moveToCons)
                        {
                            listToCompare.Add((c1, c2, c1.Origin.DistanceTo(c2.Origin)));
                        }
                    }

                    var(toMoveCon, MoveToCon, Distance) = listToCompare.MinBy(x => x.Distance).FirstOrDefault();

                    XYZ moveVector = (MoveToCon.Origin - toMoveCon.Origin) * (1 - distanceToKeep / Distance);

                    using (Transaction trans3 = new Transaction(doc))
                    {
                        trans3.Start("Move Element!");
                        {
                            if (elsToMove.Count > 1)
                            {
                                ElementTransformUtils.MoveElements(doc, selIds, moveVector);
                            }
                            else
                            {
                                foreach (Element elToMove in elsToMove)
                                {
                                    ElementTransformUtils.MoveElement(doc, elToMove.Id, moveVector);
                                }
                            }
                        }
                        trans3.Commit();
                    }

                    txGp.Assimilate();
                }

                return(Result.Succeeded);
            }

            catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 4
0
        public void Getlinedimention(IList <Reference> references, double x)
        {
            View             view       = doc.ActiveView;
            XYZ              directview = view.ViewDirection;
            XYZ              up         = view.UpDirection;
            XYZ              right      = view.RightDirection;
            List <Dimension> listdim    = new List <Dimension>();

            foreach (var i in references)
            {
                Dimension dim = doc.GetElement(i) as Dimension;
                listdim.Add(dim);
            }
            var line       = listdim.First().Curve as Line;
            XYZ directline = line.Direction;

            Sortdimensionlistrightdirect(listdim);
            for (int i = 1; i < listdim.Count; i++)
            {
                var    dim1  = listdim[i];
                var    dim2  = listdim[i - 1];
                var    line1 = dim1.Curve as Line;
                var    line2 = dim2.Curve as Line;
                var    org1  = line1.Origin;
                var    org2  = line2.Origin;
                double kc    = line1.Distance(org2);
                var    bm    = Math.Round(right.DotProduct(directline), 3);
                using (Transaction t = new Transaction(doc, "move"))
                {
                    t.Start();
                    if (bm != 0)
                    {
                        if (up.X > 0 || up.Y > 0 || up.Z > 0)
                        {
                            ICollection <ElementId> twodim = new List <ElementId>();
                            for (int j = i + 1; j < listdim.Count; j++)
                            {
                                var dim3 = listdim[j];
                                twodim.Add(dim3.Id);
                            }
                            ElementTransformUtils.MoveElement(doc, dim1.Id, -up * kc);
                            ElementTransformUtils.MoveElement(doc, dim1.Id, up * x);
                            if (twodim.Count != 0)
                            {
                                ElementTransformUtils.MoveElements(doc, twodim, up * x);
                            }
                        }
                        if (up.X < 0 || up.Y < 0 || up.Z < 0)
                        {
                            ICollection <ElementId> twodim = new List <ElementId>();
                            for (int j = i + 1; j < listdim.Count; j++)
                            {
                                var dim3 = listdim[j];
                                twodim.Add(dim3.Id);
                            }
                            ElementTransformUtils.MoveElement(doc, dim1.Id, up * kc);
                            ElementTransformUtils.MoveElement(doc, dim1.Id, -up * x);
                            if (twodim.Count != 0)
                            {
                                ElementTransformUtils.MoveElements(doc, twodim, -up * x);
                            }
                        }
                    }
                    else
                    {
                        if (right.X > 0 || right.Y > 0 || right.Z > 0)
                        {
                            ICollection <ElementId> twodim = new List <ElementId>();
                            for (int j = i + 1; j < listdim.Count; j++)
                            {
                                var dim3 = listdim[j];
                                twodim.Add(dim3.Id);
                            }
                            ElementTransformUtils.MoveElement(doc, dim1.Id, -right * kc);
                            ElementTransformUtils.MoveElement(doc, dim1.Id, right * x);
                            if (twodim.Count != 0)
                            {
                                ElementTransformUtils.MoveElements(doc, twodim, right * x);
                            }
                        }
                        if (right.X < 0 || right.Y < 0 || right.Z < 0)
                        {
                            ICollection <ElementId> twodim = new List <ElementId>();
                            for (int j = i + 1; j < listdim.Count; j++)
                            {
                                var dim3 = listdim[j];
                                twodim.Add(dim3.Id);
                            }
                            ElementTransformUtils.MoveElement(doc, dim1.Id, right * kc);
                            ElementTransformUtils.MoveElement(doc, dim1.Id, -right * x);
                            if (twodim.Count != 0)
                            {
                                ElementTransformUtils.MoveElements(doc, twodim, -right * x);
                            }
                        }
                    }
                    t.Commit();
                }
            }
        }