public void ByPointsOnCurve_ValidInput()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(1, 0, 0),
                Point.ByCoordinates(3, 0, 0),
                Point.ByCoordinates(10, 0, 0),
                Point.ByCoordinates(12, 0, 0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);

            Assert.NotNull(modCurve);

            // obtain the family from the document
            var fs = FamilySymbol.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, fs);

            Assert.NotNull(ac);
        }
Exemple #2
0
        public void ByParametersOnFace_CreatesValidACFromElementFaceReference()
        {
            var ele = ElementSelector.ByType <Autodesk.Revit.DB.Form>(true).FirstOrDefault();

            Assert.NotNull(ele);

            var form  = ele as Form;
            var faces = form.ElementFaceReferences;

            Assert.IsTrue(faces.All(x => x != null));
            Assert.AreEqual(6, faces.Length);

            var ft = FamilyType.ByName("3PointAC");

            var uvs = new[]
            {
                Autodesk.DesignScript.Geometry.UV.ByCoordinates(0, 0),
                Autodesk.DesignScript.Geometry.UV.ByCoordinates(0.5, 0.5),
                Autodesk.DesignScript.Geometry.UV.ByCoordinates(0.5, 0)
            };

            var ac = AdaptiveComponent.ByParametersOnFace(uvs, faces.First(), ft);

            Assert.NotNull(ac);
        }
Exemple #3
0
        public void ByPoints_PointArray_ProducesValidAdaptiveComponentAndLocations()
        {
            var pts = new Point[][]
            {
                new Point[]
                {
                    Point.ByCoordinates(0, 0, 0),
                    Point.ByCoordinates(10, 0, 10),
                    Point.ByCoordinates(20, 0, 0)
                }
            };
            var fs = FamilyType.ByName("3PointAC");
            var ac = AdaptiveComponent.ByPoints(pts, fs);

            var locs = ac.First().Locations;

            var pairs = locs.Zip(pts.First(), (point, point1) => new Tuple <Point, Point>(point, point1));

            // compares after unit conversion
            foreach (var pair in pairs)
            {
                pair.Item1.ShouldBeApproximately(pair.Item2);
            }

            var unconvertedPairs = pts.First().Zip(GetInternalPoints((FamilyInstance)ac.First().InternalElement),
                                                   (point, point1) => new Tuple <Point, XYZ>(point, point1));

            foreach (var pair in unconvertedPairs)
            {
                pair.Item1.ShouldBeApproximately(pair.Item2 * UnitConverter.HostToDynamoFactor(SpecTypeId.Length));
            }

            Assert.NotNull(ac);
        }
Exemple #4
0
        /// <summary>
        /// Converts the MultiPoint into an adaptive component of the specified type.
        /// </summary>
        /// <param name="familyType">Type of the family.</param>
        /// <returns></returns>
        public AdaptiveComponent ToAdaptiveComponent(FamilyType familyType)
        {
            Utils.Log(string.Format("MultiPoint.ToAdaptiveComponent started...", ""));

            AdaptiveComponent output = null;

            try
            {
                if (!SessionVariables.ParametersCreated)
                {
                    UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
                }

                output = AdaptiveComponent.ByPoints(new Point[][] { this.ShapePoints.Points.Select(p => p.RevitPoint).ToArray() }, familyType)[0];
                output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, this.SerializeJSON());
                output.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1);
                output.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0);
            }
            catch (Exception ex)
            {
                Utils.Log(ex.Message);
            }

            Utils.Log(string.Format("MultiPoint.ToAdaptiveComponent completed.", ""));

            return(output);
        }
        public void ByPoints_NullFamilySymbol()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10),
                Point.ByCoordinates(20, 0, 0)
            };

            Assert.Throws(typeof(ArgumentNullException), () => AdaptiveComponent.ByPoints(pts, null));
        }
        public void ByPoints_NonMatchingNumberOfPoints()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10)
            };
            var fs = FamilySymbol.ByName("3PointAC");

            Assert.Throws(typeof(Exception), () => AdaptiveComponent.ByPoints(pts, fs));
        }
Exemple #7
0
        public void ByPoints_ShouldThrowExceptionWithNonMatchingNumberOfPoints()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10)
            };
            var ft = FamilyType.ByName("3PointAC");

            Assert.Throws(typeof(ArgumentException), () => AdaptiveComponent.ByPoints(pts, ft));
        }
Exemple #8
0
        public ApplicationPlaceholderObject AdaptiveComponentToNative(AdaptiveComponent speckleAc)
        {
            var docObj = GetExistingElementByApplicationId(speckleAc.applicationId);

            string familyName = speckleAc["family"] as string != null ? speckleAc["family"] as string : "";

            DB.FamilySymbol   familySymbol = GetElementType <DB.FamilySymbol>(speckleAc);
            DB.FamilyInstance revitAc      = null;

            //try update existing
            if (docObj != null)
            {
                try
                {
                    var revitType = Doc.GetElement(docObj.GetTypeId()) as ElementType;

                    // if family changed, tough luck. delete and let us create a new one.
                    if (familyName != revitType.FamilyName)
                    {
                        Doc.Delete(docObj.Id);
                    }
                    else
                    {
                        revitAc = (DB.FamilyInstance)docObj;

                        // check for a type change
                        if (speckleAc.type != null && speckleAc.type != revitType.Name)
                        {
                            revitAc.ChangeTypeId(familySymbol.Id);
                        }
                    }
                }
                catch
                {
                    //something went wrong, re-create it
                }
            }

            //create family instance
            if (revitAc == null)
            {
                revitAc = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Doc, familySymbol);
            }

            SetAdaptivePoints(revitAc, speckleAc.basePoints);
            AdaptiveComponentInstanceUtils.SetInstanceFlipped(revitAc, speckleAc.flipped);

            SetInstanceParameters(revitAc, speckleAc);

            return(new ApplicationPlaceholderObject {
                applicationId = speckleAc.applicationId, ApplicationGeneratedId = revitAc.UniqueId, NativeObject = revitAc
            });
        }
        public void ByPoints_ValidInput()
        {
            var pts = new Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(10, 0, 10),
                Point.ByCoordinates(20, 0, 0)
            };
            var fs = FamilySymbol.ByName("3PointAC");
            var ac = AdaptiveComponent.ByPoints(pts, fs);

            Assert.NotNull(ac);
        }
Exemple #10
0
        private AdaptiveComponent AdaptiveComponentToSpeckle(DB.FamilyInstance revitAc)
        {
            var speckleAc = new AdaptiveComponent();

            speckleAc.type        = Doc.GetElement(revitAc.GetTypeId()).Name;
            speckleAc.basePoints  = GetAdaptivePoints(revitAc);
            speckleAc.flipped     = AdaptiveComponentInstanceUtils.IsInstanceFlipped(revitAc);
            speckleAc.displayMesh = GetElementMesh(revitAc);

            GetAllRevitParamsAndIds(speckleAc, revitAc);

            return(speckleAc);
        }
Exemple #11
0
        public void ByPointsOnCurve_ProducesValidAdaptiveComponentAndLocations()
        {
            // create spline
            var pts = new Autodesk.DesignScript.Geometry.Point[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(1, 0, 0),
                Point.ByCoordinates(3, 0, 0),
                Point.ByCoordinates(10, 0, 0),
                Point.ByCoordinates(12, 0, 0),
            };

            var spline = NurbsCurve.ByControlPoints(pts, 3);

            Assert.NotNull(spline);

            // build model curve from spline
            var modCurve = ModelCurve.ByCurve(spline);

            Assert.NotNull(modCurve);

            // obtain the family from the document
            var ft = FamilyType.ByName("3PointAC");

            // build the AC
            var parms = new double[]
            {
                0, 0.5, 1
            };

            var ac = AdaptiveComponent.ByParametersOnCurveReference(parms, modCurve.ElementCurveReference, ft);

            // with unit conversion
            foreach (var pt in ac.Locations)
            {
                spline.DistanceTo(pt).ShouldBeApproximately(0);
            }

            // without unit conversion
            var unconvertedPoints = GetInternalPoints((FamilyInstance)ac.InternalElement);

            foreach (var pt in unconvertedPoints)
            {
                spline.DistanceTo(pt.ToPoint()).ShouldBeApproximately(0);
            }

            Assert.NotNull(ac);
        }
        public void ByPoints_NullPts()
        {
            var fs = FamilySymbol.ByName("3PointAC");

            Assert.Throws(typeof(ArgumentNullException), () => AdaptiveComponent.ByPoints(null, fs));
        }