/// <summary>
        /// Set the positions of the InternalFamilyInstace from an array of uvs
        /// </summary>
        /// <param name="uvs"></param>
        /// <param name="faceReference"></param>
        private void InternalSetUvsAndFace(Autodesk.Revit.DB.UV[] uvs, Autodesk.Revit.DB.Reference faceReference)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(InternalFamilyInstance);

            if (placePointIds.Count() != uvs.Length)
            {
                throw new Exception(Properties.Resources.InputUVParamsMismatch);
            }

            // Set the position of each placement point
            int i = 0;

            foreach (var id in placePointIds)
            {
                var uv    = uvs[i];
                var point = Document.GetElement(id) as Autodesk.Revit.DB.ReferencePoint;
                var peref = Document.Application.Create.NewPointOnFace(faceReference, uv);
                point.SetPointElementReference(peref);
                i++;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
示例#2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            FSharpList <Value> pts = ((Value.List)args[0]).Item;
            FamilySymbol       fs  = (FamilySymbol)((Value.Container)args[1]).Item;

            FamilyInstance ac = null;

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //mutate
                Element e;
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e))
                {
                    ac        = e as FamilyInstance;
                    ac.Symbol = fs;
                }
                else
                {
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                }
            }
            else
            {
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = new List <ElementId>();

            placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != pts.Count())
            {
                throw new Exception("The input list of points does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                ReferencePoint point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                XYZ            pt    = (XYZ)((Value.Container)pts.ElementAt(i)).Item;
                point.Position = pt;
                i++;
            }

            return(Value.NewContainer(ac));
        }
示例#3
0
        public List <XYZ> GetInternalPoints(FamilyInstance adaptiveComponent)
        {
            var pts = new List <XYZ>();
            var ids = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(adaptiveComponent);

            foreach (var id in ids)
            {
                var p = DocumentManager.Instance.CurrentDBDocument.GetElement(id) as Autodesk.Revit.DB.ReferencePoint;
                pts.Add(p.Position);
            }
            return(pts);
        }
示例#4
0
        private List <Point> GetAdaptivePoints(DB.FamilyInstance revitAc)
        {
            var pointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(revitAc).ToList();
            var points   = new List <Point>();

            for (int i = 0; i < pointIds.Count; i++)
            {
                var point = Doc.GetElement(pointIds[i]) as ReferencePoint;
                points.Add(PointToSpeckle(point.Position));
            }
            return(points);
        }
示例#5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var doc = commandData.Application.ActiveUIDocument.Document;


            //select adaptive family instance
            var elementid      = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, new AdaptiveComponentSelectionFilter(), "Select adaptive component to project:").ElementId;
            var familyInstance = doc.GetElement(elementid) as FamilyInstance;


            //select target
            ElementId targetElementId = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Select targert element:").ElementId;


            //the reference intersector requires a 3d view. Find first 3d view.
            //Note: If the 3d view found has elements hidden the projection many not work as expected.
            View3D view3d = Utils.GetFirstView3d(doc);


            //start a transaction and do projection
            using (Transaction transaction = new Transaction(doc))
            {
                transaction.Start("Project adaptive component");

                //get placement points
                var placementPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance);


                foreach (ElementId id in placementPoints)
                {
                    //get current location
                    var placementPoint  = doc.GetElement(id) as ReferencePoint;
                    var currentLocation = placementPoint.Position;


                    //do projection
                    IEnumerable <XYZ> points = Utils.GetPointProjectedVertically(view3d, targetElementId, currentLocation);


                    //Find lowest point
                    var lowestPoint = Utils.GetLowestXYZ(points);


                    //move point
                    placementPoint.Position = lowestPoint;
                }

                transaction.Commit();
            }

            return(Result.Succeeded);
        }
示例#6
0
        public XYZ GetAdaptivePointLocation(Document document, Reference elementReference)
        {
            // Get the family instance of the selected element
            Autodesk.Revit.DB.FamilyInstance instance = document.GetElement(elementReference.ElementId) as Autodesk.Revit.DB.FamilyInstance;

            // Get the placement points of this instance

            ElementId placePointIds = (AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance)).First();

            ReferencePoint point = document.GetElement(placePointIds) as ReferencePoint;

            return(point.Position);
        }
示例#7
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var instance = (FamilyInstance)((Value.Container)args[0]).Item;

            // ADAPTIVE COMPONENT
            if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance))
            {
                var refPtIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance);
                FSharpList <Value> refPts = FSharpList <Value> .Empty;
                foreach (var id in refPtIds)
                {
                    var pt = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                    refPts = FSharpList <Value> .Cons(Value.NewContainer(pt.Position), refPts);
                }
                return(Value.NewList(Utils.SequenceToFSharpList(refPts.Reverse())));
            }

            // INSTANCE WITH PLACEMENT POINT
            var ptRefs = instance.GetFamilyPointPlacementReferences();

            if (ptRefs.Any())
            {
                var pts        = ptRefs.Select(x => x.Location.Origin);
                var containers = pts.Select(Value.NewContainer);
                return(Value.NewList(Utils.SequenceToFSharpList(containers)));
            }

            LocationPoint point = null;
            LocationCurve c     = null;

            // INSTANCE WITH LOCATION POINT
            point = instance.Location as LocationPoint;
            if (point != null)
            {
                return(Value.NewContainer(point.Point));
            }


            //INSTANCE WITH LOCATION CURVE
            c = instance.Location as LocationCurve;
            if (c != null)
            {
                return(Value.NewContainer(c.Curve));
            }

            throw new Exception("A location could not be found for the selected family instance(s).");
        }
示例#8
0
        /// <summary>
        /// Update the placement points of the adaptive component instance to the given points
        /// </summary>
        /// <param name="fi"></param>
        /// <param name="pnt"></param>
        private static void UpdatePlacementPoints(Autodesk.Revit.DB.FamilyInstance fi, XYZ[] pnts)
        {
            IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(fi);

            if (placePointIds.Count() != pnts.Count())
            {
                throw new Exception(Properties.Resources.InputPointParamsMismatch);
            }

            int count = placePointIds.Count;

            for (int i = 0; i < count; i++)
            {
                var point = (Autodesk.Revit.DB.ReferencePoint)Document.GetElement(placePointIds[i]);
                point.Position = pnts[i];
            }
        }
示例#9
0
        private void SetAdaptivePoints(DB.FamilyInstance revitAc, List <Point> points)
        {
            var pointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(revitAc).ToList();

            if (pointIds.Count != points.Count)
            {
                ConversionErrors.Add(new Exception("Adaptive family error\nWrong number of points supplied to adaptive family"));
                return;
            }

            //set adaptive points
            for (int i = 0; i < pointIds.Count; i++)
            {
                var point = Doc.GetElement(pointIds[i]) as ReferencePoint;
                point.Position = PointToNative(points[i]);
            }
        }
示例#10
0
        /// <summary>
        /// Creates a new instance of an adaptive component family.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="symbol"></param>
        /// <param name="pts"></param>
        /// <returns></returns>
        public static FamilyInstance CreateFamilyInstance(this Document doc, FamilySymbol symbol, List <XYZ> pts)
        {
            // Creates a new instance of an adaptive component family.
            var result = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, symbol);

            // Gets the placement points of this instance.
            var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(result);

            for (var i = 0; i < placePointIds.Count; i++)
            {
                if (doc.GetElement(placePointIds[i]) is ReferencePoint point)
                {
                    point.Position = pts[i];
                }
            }

            return(result);
        }
        private static void SetAdaptiveComponentPoints(FamilyInstance component, List <SpecklePoint> points)
        {
            var pointIds = new List <ElementId>();

            pointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(component).ToList();

            if (pointIds.Count != points.Count)
            {
                ConversionErrors.Add(new SpeckleConversionError {
                    Message = $"Wrong number of points supplied to adapive family"
                });
                return;
            }

            //set base points
            for (int i = 0; i < pointIds.Count; i++)
            {
                var point = Doc.GetElement(pointIds[i]) as ReferencePoint;
                point.Position = (XYZ)SpeckleCore.Converter.Deserialise(obj: points[i], excludeAssebmlies: new string[] { "SpeckleCoreGeometryDynamo" });
            }
        }
示例#12
0
        //创建族实例
        private void CreateFamilyInstance(List <XYZ> points1, List <XYZ> points2, FamilySymbol FamilySymbol, ExternalCommandData commandData, bool v)
        {
            //最后这个bool设定是为了设定两个list是否错开,是一一对应,还是错开一个相加


            UIDocument uiDoc = commandData.Application.ActiveUIDocument;           //取得当前活动文档

            if (v)
            {
                //如果不错开
                for (int i = 0; i < points1.Count; i += 1)
                {
                    FamilyInstance    familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(uiDoc.Document, FamilySymbol);
                    IList <ElementId> adaptivePoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance);
                    //取得的参照点
                    ReferencePoint referencePoint1 = uiDoc.Document.GetElement(adaptivePoints[0]) as ReferencePoint;
                    ReferencePoint referencePoint2 = uiDoc.Document.GetElement(adaptivePoints[1]) as ReferencePoint;
                    //设置参照点坐标
                    referencePoint1.Position = points1[i];
                    referencePoint2.Position = points2[i];
                }
            }
            else
            {
                //错开一个相加
                for (int i = 0; i < points1.Count - 1; i += 1)
                {
                    FamilyInstance    familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(uiDoc.Document, FamilySymbol);
                    IList <ElementId> adaptivePoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance);
                    //取得的参照点
                    ReferencePoint referencePoint1 = uiDoc.Document.GetElement(adaptivePoints[0]) as ReferencePoint;
                    ReferencePoint referencePoint2 = uiDoc.Document.GetElement(adaptivePoints[1]) as ReferencePoint;
                    //设置参照点坐标
                    referencePoint1.Position = points1[i];
                    referencePoint2.Position = points2[i + 1];
                }
            }
        }
        /// <summary>
        /// Set the positions of the internal family instance from a list of XYZ points
        /// </summary>
        /// <param name="points"></param>
        private void InternalSetPositions(XYZ[] points)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(InternalFamilyInstance);

            if (placePointIds.Count() != points.Count())
            {
                throw new Exception(Properties.Resources.InputPointParamsMismatch);
            }

            // Set the position of each placement point
            int i = 0;

            foreach (var id in placePointIds)
            {
                var point = (Autodesk.Revit.DB.ReferencePoint)Document.GetElement(id);
                point.Position = points[i];
                i++;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
        /// <summary>
        /// Set the positions of the internal family instance from a list of XYZ points
        /// </summary>
        /// <param name="points"></param>
        private void InternalSetPositions(XYZ[] points)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(InternalFamilyInstance);

            if (placePointIds.Count() != points.Count())
            {
                throw new Exception("The input list of points does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (var id in placePointIds)
            {
                var point = (Autodesk.Revit.DB.ReferencePoint)Document.GetElement(id);
                point.Position = points[i];
                i++;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
示例#15
0
        private static void UpdatePlacementPoints(FamilyInstance ac, FSharpList <Value> xyzs, int j)
        {
            IList <ElementId> placePointIds =
                AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            var pts = ((Value.List)xyzs[j]).Item;

            if (placePointIds.Count() != pts.Count())
            {
                return;
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var pt    = (XYZ)((Value.Container)pts.ElementAt(i)).Item;
                point.Position = pt;
                i++;
            }
        }
示例#16
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;

            if (doc.IsFamilyDocument)
            {
                TaskDialog.Show("ОТМЕНЕНО", "Данная команда предназначена для запуска в документе проекта");
                return(Result.Cancelled);
            }

            try
            {
                //Выбрать несколько файлов CSV с координатами
                Transform projectTransform = Utils.GetProjectCoordinatesTransform(doc);

                string[] filenames = null;
                WinForms.OpenFileDialog openFileDialog1 = new WinForms.OpenFileDialog();


                string curDocPath = doc.PathName;
                if (!String.IsNullOrEmpty(curDocPath))
                {
                    openFileDialog1.InitialDirectory = Path.GetDirectoryName(curDocPath);
                }
                openFileDialog1.Filter           = "csv files (*.csv)|*.csv";
                openFileDialog1.FilterIndex      = 1;
                openFileDialog1.RestoreDirectory = true;
                openFileDialog1.Multiselect      = true;
                openFileDialog1.Title            = "Выберите таблицы CSV с координатами 3d-полилиний";

                if (openFileDialog1.ShowDialog() == WinForms.DialogResult.OK)
                {
                    filenames = openFileDialog1.FileNames;

                    List <List <XYZ> > lines3d = new List <List <XYZ> >();

                    if (Utils.ReadCoordinatesFromCSV(filenames, projectTransform, lines3d))
                    {
                        //Загрузить семейство 3d линии если нет
                        Family       line3dFamily = Utils.GetFamily(doc, "3d line");
                        ElementId    symId        = line3dFamily.GetFamilySymbolIds().First();
                        FamilySymbol familySymbol = (FamilySymbol)doc.GetElement(symId);

                        //Вывести форму для выбора семейств
                        Categories       categories       = doc.Settings.Categories;
                        ElementId        IdGeneric        = categories.get_Item(BuiltInCategory.OST_GenericModel).Id;
                        SelectTypeWindow selectTypeWindow = new SelectTypeWindow(doc, IdGeneric);
                        bool?            result           = selectTypeWindow.ShowDialog();
                        if (result != null && result.Value &&
                            selectTypeWindow.SelectedFamilySymbols.Count > 0)
                        {
                            familySymbol = selectTypeWindow.SelectedFamilySymbols.First();
                        }

                        //Расставить линии по координатам
                        using (Transaction tr = new Transaction(doc))
                        {
                            tr.Start("Draw 3D line");
                            //активировать типоразмер
                            if (!familySymbol.IsActive)
                            {
                                familySymbol.Activate();
                                doc.Regenerate();
                            }


                            foreach (List <XYZ> ptList in lines3d)
                            {
                                for (int i = 0; i < ptList.Count - 1; i++)
                                {
                                    FamilyInstance    instance      = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, familySymbol);
                                    IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance);
                                    ReferencePoint    point1        = (ReferencePoint)doc.GetElement(placePointIds[0]);
                                    point1.Position = ptList[i];
                                    ReferencePoint point2 = (ReferencePoint)doc.GetElement(placePointIds[1]);
                                    point2.Position = ptList[i + 1];
                                }
                            }

                            tr.Commit();
                        }
                    }
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }
            catch (Exception ex)
            {
                CommonException(ex, "Ошибка при вычерчивании 3d линии в Revit");
            }



            return(Result.Succeeded);
        }
示例#17
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var doc = commandData.Application.ActiveUIDocument.Document;



            //Collect all adaptive component family symbols with more than 1 placement point
            var collector = new FilteredElementCollector(doc);
            var filter    = new ElementClassFilter(typeof(FamilySymbol));

            var adaptiveComponents = from fs in collector.WherePasses(filter).Cast <FamilySymbol>()
                                     where AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(fs.Family) &&
                                     AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) > 1
                                     select fs;


            //Display dialog and prompt for selection
            FormFamilySymbolSelector selector = new FormFamilySymbolSelector(adaptiveComponents);

            selector.ShowDialog();


            //select edge reference
            Reference hostEdge   = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Edge, "Select edge:");
            var       selectedId = hostEdge.ElementId;

            Element e = doc.GetElement(selectedId);



            //get the selected family
            var selectedFamilySymbol = selector.SelectedElement();


            //activate familySymbol
            selectedFamilySymbol.Activate();

            using (TransactionGroup transGroup = new TransactionGroup(doc))
            {
                transGroup.Start("Place Dimensions");



                //hack join the element to a wall
                ElementId wallId = null;


                if (e is FamilyInstance & JoinGeometryUtils.GetJoinedElements(doc, e).Count < 1)
                {
                    using (Transaction transaction = new Transaction(doc))
                    {
                        transaction.Start("Create wall");

                        //////setup a failure handler to handle any warnings
                        ////FailureHandlingOptions failOpts = transaction.GetFailureHandlingOptions();
                        ////failOpts.SetFailuresPreprocessor(new WarningSwallower());
                        ////transaction.SetFailureHandlingOptions(failOpts);


                        wallId = Utils.CreateJoinedWall(doc, wallId, e as FamilyInstance);


                        doc.Regenerate();

                        transaction.Commit();
                    }
                }



                using (Transaction transaction = new Transaction(doc))
                {
                    transaction.Start("Create Family");

                    //get number of placement point
                    var numberOfPoints =
                        AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(selectedFamilySymbol.Family);
                    double numberOfSpaces = numberOfPoints - 1;

                    //create family
                    var familyInstance =
                        AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, selectedFamilySymbol);


                    //adjust placment point locations
                    var placementPoints =
                        AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance);

                    for (int i = 0; i < placementPoints.Count; i++)
                    {
                        double interval = i / numberOfSpaces;

                        var location = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter,
                                                                interval, PointOnCurveMeasureFrom.Beginning);

                        var pointOnEdge = doc.Application.Create.NewPointOnEdge(hostEdge, location);


                        var p = doc.GetElement(placementPoints[i]) as ReferencePoint;

                        p.SetPointElementReference(pointOnEdge);
                    }



                    transaction.Commit();
                }

                transGroup.Assimilate();
            }

            return(Result.Succeeded);
        }
示例#18
0
        public bool MovePoint(int idx, XYZ trans)
        {
            var ptId = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(this.RevitInstance)[idx];

            return(MovePointById(ptId, trans));
        }
示例#19
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            FSharpList <Value> pts = ((Value.List)args[0]).Item;
            var fs = (FamilySymbol)((Value.Container)args[1]).Item;

            FamilyInstance ac;

            var instData = new List <FamilyInstanceCreationData>();

            var sw = new Stopwatch();

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //mutate
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(Elements[0], out ac))
                {
                    sw.Start();
                    ac.Symbol = fs;
                    sw.Stop();
                    Debug.WriteLine(string.Format("{0} elapsed for updating family type on AC.", sw.Elapsed));
                    sw.Reset();
                }
                else
                {
                    sw.Start();
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                    sw.Stop();
                    Debug.WriteLine(string.Format("{0} elapsed for creating an AC.", sw.Elapsed));
                    sw.Reset();
                }
            }
            else
            {
                sw.Start();
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
                sw.Stop();
                Debug.WriteLine(string.Format("{0} elapsed for creating an AC.", sw.Elapsed));
                sw.Reset();
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != pts.Count())
            {
                throw new Exception("The input list of points does not have the same number of values required by the adaptive component.");
            }

            sw.Start();
            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var pt    = (XYZ)((Value.Container)pts.ElementAt(i)).Item;
                point.Position = pt;
                i++;
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for updating placement points of the AC.", sw.Elapsed));
            sw.Reset();


            return(Value.NewContainer(ac));
        }
示例#20
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            if (!args[0].IsList)
            {
                throw new Exception("A list of UVs is required to place the Adaptive Component.");
            }

            FSharpList <Value> uvs = ((Value.List)args[0]).Item;

            var faceRef = ((Value.Container)args[1]).Item as Reference;
            var f       = faceRef == null
                         ? (Face)((Value.Container)args[1]).Item
                         : (Face)dynRevitSettings.Doc.Document.GetElement(faceRef.ElementId).GetGeometryObjectFromReference(faceRef);

            var fs = (FamilySymbol)((Value.Container)args[2]).Item;

            FamilyInstance ac = null;

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //mutate
                Element e;
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e))
                {
                    ac        = e as FamilyInstance;
                    ac.Symbol = fs;
                }
                else
                {
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                }
            }
            else
            {
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = new List <ElementId>();

            placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != uvs.Count())
            {
                throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var uv    = (UV)((Value.Container)uvs.ElementAt(i)).Item;
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var peref = dynRevitSettings.Revit.Application.Create.NewPointOnFace(f.Reference, uv);
                point.SetPointElementReference(peref);
                i++;
            }

            return(Value.NewContainer(ac));
        }
示例#21
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            if (!args[0].IsList)
            {
                throw new Exception("A list of UVs is required to place the Adaptive Component.");
            }

            FSharpList <Value> parameters = ((Value.List)args[0]).Item;

            var curveRef = ((Value.Container)args[1]).Item as Reference;
            var c        = curveRef == null
                         ? (Curve)((Value.Container)args[1]).Item
                         : (Curve)dynRevitSettings.Doc.Document.GetElement(curveRef.ElementId).GetGeometryObjectFromReference(curveRef);

            var fs = (FamilySymbol)((Value.Container)args[2]).Item;

            FamilyInstance ac = null;

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(this.Elements[0], out ac))
                {
                    ac.Symbol = fs;
                }
                else
                {
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                }
            }
            else
            {
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = new List <ElementId>();

            placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != parameters.Count())
            {
                throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var t     = ((Value.Number)parameters.ElementAt(i)).Item;
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var ploc  = new PointLocationOnCurve(PointOnCurveMeasurementType.NonNormalizedCurveParameter, t,
                                                     PointOnCurveMeasureFrom.Beginning);
                var peref = dynRevitSettings.Revit.Application.Create.NewPointOnEdge(c.Reference, ploc);
                point.SetPointElementReference(peref);
                i++;
            }

            return(Value.NewContainer(ac));
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var doc = commandData.Application.ActiveUIDocument.Document;

            //create point list
            List <XYZ> pointList = new List <XYZ>();

            pointList.Add(new XYZ(0, 0, 0));
            pointList.Add(new XYZ(0, 20, 0));


            //Collect all adaptive component family symbols with 2 placement points
            var collector = new FilteredElementCollector(doc);
            var filter    = new ElementClassFilter(typeof(FamilySymbol));

            var adaptiveComponents = from fs in collector.WherePasses(filter).Cast <FamilySymbol>()
                                     where AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(fs.Family) &&
                                     AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) == 2
                                     select fs;


            //Display dialog and prompt for selection
            FormFamilySymbolSelector selector = new FormFamilySymbolSelector(adaptiveComponents);

            selector.ShowDialog();

            if (selector.DialogResult.Equals(DialogResult.OK))
            {
                //get the selected family
                var selectedFamilySymbol = selector.SelectedElement();

                //activate familySymbol
                selectedFamilySymbol.Activate();


                //create family
                using (Transaction transaction = new Transaction(doc))
                {
                    transaction.Start("Create Family");

                    var familyInstance =
                        AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, selectedFamilySymbol);


                    //adjust placment point locations
                    var placementPoints =
                        AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance);


                    for (int i = 0; i < placementPoints.Count; i++)
                    {
                        var p = doc.GetElement(placementPoints[i]) as ReferencePoint;

                        p.Position = pointList[i];
                    }

                    transaction.Commit();
                }
            }

            return(Result.Succeeded);
        }
示例#23
0
        void ReconstructAdaptiveComponentByPoints
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            IList <Rhino.Geometry.Point3d> points,
            Autodesk.Revit.DB.FamilySymbol type
        )
        {
            var scaleFactor    = 1.0 / Revit.ModelUnits;
            var adaptivePoints = points.Select(x => x.Scale(scaleFactor).ToHost()).ToArray();

            if (!type.IsActive)
            {
                type.Activate();
            }

            // Type
            ChangeElementTypeId(ref element, type.Id);

            if (element is FamilyInstance instance && AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance))
            {
                var adaptivePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance);
                if (adaptivePointIds.Count == adaptivePoints.Length)
                {
                    int index = 0;
                    foreach (var vertex in adaptivePointIds.Select(id => doc.GetElement(id)).Cast <ReferencePoint>())
                    {
                        vertex.Position = adaptivePoints[index++];
                    }

                    return;
                }
            }

            {
                var creationData = new List <Autodesk.Revit.Creation.FamilyInstanceCreationData>
                {
                    Revit.ActiveUIApplication.Application.Create.NewFamilyInstanceCreationData(type, adaptivePoints)
                };

                var newElementIds = doc.IsFamilyDocument ?
                                    doc.FamilyCreate.NewFamilyInstances2(creationData) :
                                    doc.Create.NewFamilyInstances2(creationData);

                if (newElementIds.Count != 1)
                {
                    doc.Delete(newElementIds);
                    throw new InvalidOperationException();
                }

                var parametersMask = new BuiltInParameter[]
                {
                    BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
                    BuiltInParameter.ELEM_FAMILY_PARAM,
                    BuiltInParameter.ELEM_TYPE_PARAM
                };

                ReplaceElement(ref element, doc.GetElement(newElementIds.First()), parametersMask);
            }
        }
        public static bool TryGetAdaptiveComponentPoint3Ds(this FamilyInstance familyInstance, out List <Point3D> point3Ds, out List <Point3D> point3Ds_Placement, out List <Point3D> point3Ds_ShapeHandle)
        {
            point3Ds             = null;
            point3Ds_Placement   = null;
            point3Ds_ShapeHandle = null;

            if (familyInstance == null)
            {
                return(false);
            }

            if (!AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(familyInstance))
            {
                return(false);
            }

            Document document = familyInstance.Document;

            IList <ElementId> elementIds = null;

            elementIds = AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(familyInstance);
            if (elementIds != null)
            {
                point3Ds = new List <Point3D>();
                foreach (ElementId elementId in elementIds)
                {
                    ReferencePoint referencePoint = document.GetElement(elementId) as ReferencePoint;
                    if (referencePoint == null || referencePoint.Position == null)
                    {
                        continue;
                    }

                    point3Ds.Add(referencePoint.Position.ToSAM());
                }
            }

            elementIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance);
            if (elementIds != null)
            {
                point3Ds_Placement = new List <Point3D>();
                foreach (ElementId elementId in elementIds)
                {
                    ReferencePoint referencePoint = document.GetElement(elementId) as ReferencePoint;
                    if (referencePoint == null || referencePoint.Position == null)
                    {
                        continue;
                    }

                    point3Ds_Placement.Add(referencePoint.Position.ToSAM());
                }
            }

            elementIds = AdaptiveComponentInstanceUtils.GetInstanceShapeHandlePointElementRefIds(familyInstance);
            if (elementIds != null)
            {
                point3Ds_ShapeHandle = new List <Point3D>();
                foreach (ElementId elementId in elementIds)
                {
                    ReferencePoint referencePoint = document.GetElement(elementId) as ReferencePoint;
                    if (referencePoint == null || referencePoint.Position == null)
                    {
                        continue;
                    }

                    point3Ds_ShapeHandle.Add(referencePoint.Position.ToSAM());
                }
            }

            return(true);
        }
示例#25
0
        private void MatchElementsToAlignments()
        {
            // find all elements for the curves (railings and sleepers)
            var railParts = new FilteredElementCollector(_document)
                            .OfClass(typeof(FamilyInstance))
                            .ToElements()
                            .Cast <FamilyInstance>()
                            .Where(e => AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(e))
                            .ToList();

            foreach (var element in railParts)
            {
                // get adaptive points
                var points = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(element)
                             .Select(r => _document.GetElement(r))
                             .Cast <ReferencePoint>()
                             .ToList();

                // match addaptive points to curves
                if (points.Count > 0)
                {
                    foreach (var record in _alignments)
                    {
                        if (ArePointsOnCurve(record.Polylines, points))
                        {
                            // find IFC element
                            IfcGloballyUniqueId id = GetIfcGUID(element);
                            var ifcElement         = i.FirstOrDefault <IfcBuildingElement>(e => e.GlobalId == id);
                            if (ifcElement != null)
                            {
                                record.Elements.Add(ifcElement);
                            }
                        }
                    }
                }
            }

            // find building elements which were not matched, possibly because they were not modelled with adaptive points
            var notMatched = i.Where <IfcBuildingElement>(e => !_alignments.Any(a => a.Elements.Contains(e)))
                             .ToList();

            foreach (var element in notMatched)
            {
                var matrix   = GetMatrixRelativeToSite(element);
                var position = matrix.Transform(new XbimPoint3D(0, 0, 0));

                Intersection    intersection = null;
                AlignmentRecord record       = null;
                // find closes alignment intersection (if any)
                foreach (var alignmentRecord in _alignments)
                {
                    var i = GetIntersection2D(alignmentRecord.Segments.ToList(), position);
                    if (i == null)
                    {
                        continue;
                    }
                    if (intersection == null || Math.Abs(intersection.OffsetLateral) > Math.Abs(i.OffsetLateral))
                    {
                        intersection = i;
                        record       = alignmentRecord;
                    }
                }

                // we found one working so lets use it
                if (record != null)
                {
                    record.Elements.Add(element);
                }
            }
        }