Exemplo n.º 1
0
        private static Form ByLoftCrossSectionsInternal(object[] curves, bool isSolid = true)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("curves");
            }

            // if the arguments are polycurves, explode them
            if (curves.Any(x => x is PolyCurve))
            {
                var ca = curves.Select(x => x is PolyCurve ? ((PolyCurve)x).Curves() : new[] { x }).ToArray();
                return(ByLoftMultiPartCrossSectionsInternal(ca, isSolid));
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curves)
            {
                if (l == null)
                {
                    throw new ArgumentNullException("curves");
                }
                var refArr = new ReferenceArray();

                refArr.Append(ElementCurveReference.TryGetCurveReference(l, "Form").InternalReference);
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Exemplo n.º 2
0
        public static Form ByLoftingCurveReferences(object[][] curveReferences, bool isSolid = true)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curveReferences)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Exemplo n.º 3
0
        public void ByCurveAndEqualDivisions_NullArgument()
        {
            // build dividedPath
            ElementCurveReference faceRef = null;

            Assert.Throws(typeof(ArgumentNullException), () => DividedPath.ByCurveAndDivisions(faceRef, 5));

            Autodesk.DesignScript.Geometry.Curve surface = null;
            Assert.Throws(typeof(ArgumentNullException), () => DividedPath.ByCurveAndDivisions(surface, 5));

            Revit.Elements.Element element = null;
            Assert.Throws(typeof(ArgumentNullException), () => DividedPath.ByCurveAndDivisions(element, 5));
        }
Exemplo n.º 4
0
        public static DividedPath ByCurveAndDivisions(Revit.Elements.Element element, int divisions)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (divisions < 2)
            {
                throw new Exception("The number of divisions must be greater than 2!");
            }

            return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(element) }, divisions));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a Reference Point at a particular length along a curve
        /// </summary>
        /// <param name="elementCurveReference"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static ReferencePoint ByLengthOnCurveReference(ElementCurveReference elementCurveReference, double length)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception("ReferencePoint Elements can only be created in a Family Document");
            }

            if (elementCurveReference == null)
            {
                throw new ArgumentNullException("elementCurveReference");
            }

            return(new ReferencePoint(elementCurveReference.InternalReference, length, PointOnCurveMeasurementType.SegmentLength, PointOnCurveMeasureFrom.Beginning));
        }
Exemplo n.º 6
0
        public static DividedPath ByCurveAndDivisions(object curveReference, int divisions)
        {
            if (curveReference == null)
            {
                throw new ArgumentNullException("curveReference");
            }

            if (divisions < 2)
            {
                throw new Exception("The number of divisions must be greater than 2!");
            }

            return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(curveReference) }, divisions));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a Reference Point at a parameter on an Curve.  This introduces a persistent relationship between
        /// Elements in the Revit document.
        /// </summary>
        /// <param name="elementCurveReference"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static ReferencePoint ByParameterOnCurveReference(object elementCurveReference, double parameter)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception("ReferencePoint Elements can only be created in a Family Document");
            }

            if (elementCurveReference == null)
            {
                throw new ArgumentNullException("elementCurveReference");
            }

            return(new ReferencePoint(ElementCurveReference.TryGetCurveReference(elementCurveReference).InternalReference, parameter, PointOnCurveMeasurementType.NormalizedCurveParameter, PointOnCurveMeasureFrom.Beginning));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a Revit divided path on the given curve with specified amount of division
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="divisions"></param>
        /// <returns></returns>
        public static DividedPath ByCurveAndDivisions(Autodesk.DesignScript.Geometry.Curve curve, int divisions)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            if (divisions < 2)
            {
                throw new Exception(Properties.Resources.NumberOfDivisionsMustBeGreaterThan2);
            }

            return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(curve) }, divisions));
        }
Exemplo n.º 9
0
        public static DividedPath ByCurveAndDivisions(Revit.Elements.Element element, int divisions)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (divisions < 2)
            {
                throw new Exception(Properties.Resources.NumberOfDivisionsMustBeGreaterThan2);
            }

            return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(element) }, divisions));
        }
Exemplo n.º 10
0
        public static DividedPath ByCurveAndDivisions(Autodesk.DesignScript.Geometry.Curve curve, int divisions)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            if (divisions < 2)
            {
                throw new Exception("The number of divisions must be greater than 2!");
            }

            return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(curve) }, divisions));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a Reference Point at a particular length along a curve
        /// </summary>
        /// <param name="elementCurveReference"></param>
        /// <param name="length">Distance in meters along the curve</param>
        /// <returns></returns>
        public static ReferencePoint ByLengthOnCurveReference(object elementCurveReference, double length)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception("ReferencePoint Elements can only be created in a Family Document");
            }

            if (elementCurveReference == null)
            {
                throw new ArgumentNullException("elementCurveReference");
            }

            return(new ReferencePoint(ElementCurveReference.TryGetCurveReference(elementCurveReference).InternalReference,
                                      UnitConverter.DynamoToHostFactor(UnitType.UT_Length) * length, PointOnCurveMeasurementType.SegmentLength, PointOnCurveMeasureFrom.Beginning));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Create a Reference Point at a particular length along a curve
        /// </summary>
        /// <param name="elementCurveReference"></param>
        /// <param name="length">Distance in meters along the curve</param>
        /// <returns></returns>
        public static ReferencePoint ByLengthOnCurveReference(object elementCurveReference, double length)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception(Properties.Resources.ReferencePointCreationFailure);
            }

            if (elementCurveReference == null)
            {
                throw new ArgumentNullException("elementCurveReference");
            }

            return(new ReferencePoint(ElementCurveReference.TryGetCurveReference(elementCurveReference).InternalReference,
                                      UnitConverter.DynamoToHostFactor(SpecTypeId.Length) * length, PointOnCurveMeasurementType.SegmentLength, PointOnCurveMeasureFrom.Beginning));
        }
Exemplo n.º 13
0
        public static Form ByLoftingCurveReferences(object[] curveReferences, bool isSolid = true)
        {
            var refArrArr = new ReferenceArrayArray();

            foreach (var l in curveReferences)
            {
                if (l == null)
                {
                    throw new ArgumentNullException("curveReferences");
                }
                var refArr = new ReferenceArray();
                refArr.Append(ElementCurveReference.TryGetCurveReference(l, "Form").InternalReference);
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Exemplo n.º 14
0
        public static Form ByLoftCrossSections(object[][] curves, bool isSolid = true)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("curves");
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Exemplo n.º 15
0
        private static Form ByLoftMultiPartCrossSectionsInternal(object[][] curves, bool isSolid = true)
        {
            if (curves == null || curves.SelectMany(x => x).Any(x => x == null))
            {
                throw new ArgumentNullException("Some of the input curves are null.");
            }

            var refArrArr = new ReferenceArrayArray();

            foreach (var curveArr in curves)
            {
                var refArr = new ReferenceArray();
                curveArr.ForEach(x => refArr.Append(ElementCurveReference.TryGetCurveReference(x, "Form").InternalReference));
                refArrArr.Append(refArr);
            }

            return(new Form(isSolid, refArrArr));
        }
Exemplo n.º 16
0
        public static DividedPath ByCurvesAndDivisions(Revit.Elements.Element[] elements, int divisions)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }

            if (divisions < 2)
            {
                throw new Exception(Properties.Resources.NumberOfDivisionsMustBeGreaterThan2);
            }

            if (elements.Any(x => x == null))
            {
                throw new ArgumentNullException(String.Format("curves[{0}]", Array.FindIndex(elements, x => x == null)));
            }

            return(new DividedPath(elements.Select(x => ElementCurveReference.TryGetCurveReference(x)).ToArray(), divisions));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Creates a Revit divided path on the given collection of curves with specified amount of division
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="divisions"></param>
        /// <returns></returns>
        public static DividedPath ByCurvesAndDivisions(Autodesk.DesignScript.Geometry.Curve[] curve, int divisions)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            if (divisions < 2)
            {
                throw new Exception(Properties.Resources.NumberOfDivisionsMustBeGreaterThan2);
            }

            if (curve.Any(x => x == null))
            {
                throw new ArgumentNullException(String.Format("curves[{0}]", Array.FindIndex(curve, x => x == null)));
            }

            return(new DividedPath(curve.Select(x => ElementCurveReference.TryGetCurveReference(x)).ToArray(), divisions));
        }
Exemplo n.º 18
0
        public static DividedPath ByCurvesAndDivisions(object[] curveReferences, int divisions)
        {
            if (curveReferences == null)
            {
                throw new ArgumentNullException("curveReferences");
            }

            if (divisions < 2)
            {
                throw new Exception("The number of divisions must be greater than 2!");
            }

            if (curveReferences.Any(x => x == null))
            {
                throw new ArgumentNullException(String.Format("curves[{0}]", Array.FindIndex(curveReferences, x => x == null)));
            }

            return(new DividedPath(curveReferences.Select(x => ElementCurveReference.TryGetCurveReference(x)).ToArray(), divisions));
        }
Exemplo n.º 19
0
        public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, ElementCurveReference revitCurve, FamilySymbol familySymbol)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (revitCurve == null)
            {
                throw new ArgumentNullException("revitCurve");
            }

            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return(new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(revitCurve).InternalReference, familySymbol));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create an adaptive component referencing the parameters on a Curve reference
        /// </summary>
        /// <param name="parameters">The parameters on the curve</param>
        /// <param name="curve">The curve to reference</param>
        /// <param name="familySymbol">The family symbol to construct</param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, Autodesk.DesignScript.Geometry.Curve curve, FamilySymbol familySymbol)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            if (familySymbol == null)
            {
                throw new ArgumentNullException("familySymbol");
            }

            return(new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(curve).InternalReference, familySymbol));
        }
Exemplo n.º 21
0
        public void Curves_ExtractsCurvesAccountingForInstanceTransform()
        {
            var ele  = ElementSelector.ByElementId(32107, true);
            var crvs = ele.Curves;

            Assert.AreEqual(4, crvs.Length);
            Assert.AreEqual(4, crvs.OfType <Autodesk.DesignScript.Geometry.Line>().Count());

            var bbox = BoundingBox.ByGeometry(crvs);

            bbox.MaxPoint.ShouldBeApproximately(50.0, 0, 0, 1e-3);
            bbox.MinPoint.ShouldBeApproximately(0, -100.0, 0, 1e-3);

            var refs = crvs.Select(x => ElementCurveReference.TryGetCurveReference(x));

            foreach (var refer in refs)
            {
                Assert.AreEqual(32107, refer.InternalReference.ElementId.IntegerValue);
            }
        }
Exemplo n.º 22
0
        public void Curves_ExtractsCurvesFromNestedNonSharedFamilyInstanceAccountingForInstanceTransform()
        {
            var ele  = ElementSelector.ByElementId(186006, true);
            var crvs = ele.Curves;

            Assert.AreEqual(4, crvs.Length);
            Assert.AreEqual(4, crvs.OfType <Autodesk.DesignScript.Geometry.Line>().Count());

            var bbox = BoundingBox.ByGeometry(crvs);

            bbox.MinPoint.ShouldBeApproximately(-103.697, -88.156, 0, 1e-2);
            bbox.MaxPoint.ShouldBeApproximately(83.445, 108.963, 0, 1e-2);

            var refs = crvs.Select(x => ElementCurveReference.TryGetCurveReference(x));

            foreach (var refer in refs)
            {
                Assert.AreEqual(186006, refer.InternalReference.ElementId.IntegerValue);
            }
        }
Exemplo n.º 23
0
        public static AdaptiveComponent[] ByParametersOnCurveReference(double[][] parameters, ElementCurveReference revitCurve, FamilyType familyType)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (revitCurve == null)
            {
                throw new ArgumentNullException("revitCurve");
            }

            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

            return(parameters.Select(x => ByParametersOnCurveReference(x, revitCurve, familyType)).ToArray());
        }
Exemplo n.º 24
0
 private static Autodesk.DesignScript.Geometry.Curve Tag(Autodesk.DesignScript.Geometry.Curve curve,
                                                         Autodesk.Revit.DB.Reference reference)
 {
     return(reference != null?ElementCurveReference.AddTag(curve, reference) : curve);
 }