Exemple #1
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            String file_name = ((Value.String)args[0]).Item;

            DSObjectList objects = ASMImporter.import_file(file_name);

            _result.Clear();

            foreach (DSObject obj in objects)
            {
                DSObject restored = RestoreProperDSType(obj);

                _result.Add(restored);

                GraphicItem item = restored as GraphicItem;

                if (item == null)
                {
                    continue;
                }

                GraphicItem.persist(item);
                _graphicItems.Add(item);
            }

            List <Value> return_values = new List <Value>();

            foreach (DSObject obj in _result)
            {
                return_values.Add(Value.NewContainer(obj));
            }

            return(Value.NewList(Utils.SequenceToFSharpList(return_values)));
        }
Exemple #2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects = new IntersectionResultArray();
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);
            var results = FSharpList <Value> .Empty;

            var xsect_results = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    var xsect = FSharpList <Value> .Empty;
                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xsect);

                    xsect_results = FSharpList <Value> .Cons(Value.NewList(xsect), xsect_results);

                    pts.Add(ir.XYZPoint);
                }
            }
            results = FSharpList <Value> .Cons(Value.NewList(xsect_results), results);

            results = FSharpList <Value> .Cons(Value.NewString(result.ToString()), results);

            return(Value.NewList(results));
        }
Exemple #3
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects;
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);

            var xyz = FSharpList <Value> .Empty;
            var u   = FSharpList <Value> .Empty;
            var v   = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    xyz = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xyz);

                    u = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), u);

                    v = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), v);

                    pts.Add(ir.XYZPoint);
                }
            }

            outPuts[_vPort]      = Value.NewList(v);
            outPuts[_uPort]      = Value.NewList(u);
            outPuts[_xyzPort]    = Value.NewList(xyz);
            outPuts[_resultPort] = Value.NewString(result.ToString());
        }
Exemple #4
0
        private Value GetCurvesFromFamily(Autodesk.Revit.DB.FamilyInstance fi, int count,
                                          Autodesk.Revit.DB.Options options)
        {
            FamilySymbol fs = fi.Symbol;

            //Autodesk.Revit.DB.GeometryElement geomElem = fs.get_Geometry(options);
            Autodesk.Revit.DB.GeometryElement geomElem = fi.get_Geometry(options);
            // our particular case of a loaded mass family with no joins has no geom in the instance

            //fi.GetOriginalGeometry(options);
            //fi.GetTransform()

            Autodesk.Revit.DB.CurveArray     curves    = new CurveArray();
            Autodesk.Revit.DB.ReferenceArray curveRefs = new ReferenceArray();


            //Find all curves and insert them into curve array
            AddCurves(fi, geomElem, count, ref curves);

            //curves.Append(GetCurve(fi, options)); //test

            //extract references for downstream use
            foreach (Curve c in curves)
            {
                curveRefs.Append(c.Reference);
            }

            //convert curvearray into list using Stephens MakeEnumerable
            Value result = Value.NewList(Utils.SequenceToFSharpList(
                                             dynUtils.MakeEnumerable(curves).Select(Value.NewContainer)
                                             ));


            return(result);
        }
Exemple #5
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            port  = (SerialPort)((Value.Container)args[0]).Item;
            range = (int)((Value.Number)args[1]).Item;


            if (port != null)
            {
                bool isOpen = true;

                if (isOpen == true)
                {
                    if (!port.IsOpen)
                    {
                        port.Open();
                    }

                    //get the values from the serial port as a list of strings
                    serialLine = GetArduinoData();
                }
                else if (isOpen == false)
                {
                    if (port.IsOpen)
                    {
                        port.Close();
                    }
                }
            }


            return(Value.NewList(Utils.SequenceToFSharpList(serialLine.Select(Value.NewString))));
        }
Exemple #6
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var input  = args[0];
            var result = FSharpList <Value> .Empty;

            if (input.IsList)
            {
                var ptList = (input as Value.List).Item;
                int length = ptList.Length;

                var verts = new List <Vertex3>();

                for (int i = 0; i < length; i++)
                {
                    var pt   = (XYZ)((Value.Container)ptList[i]).Item;
                    var vert = new Vertex3(pt.X, pt.Y, pt.Z);
                    verts.Add(vert);
                }

                // make triangulation
                var triResult = DelaunayTriangulation <Vertex3, Tetrahedron> .Create(verts);

                _tessellationLines.Clear();

                // make edges
                foreach (var cell in triResult.Cells)
                {
                    foreach (var face in cell.MakeFaces())
                    {
                        var start1 = cell.Vertices[face[0]].ToXYZ();
                        var end1   = cell.Vertices[face[1]].ToXYZ();

                        var start2 = cell.Vertices[face[1]].ToXYZ();
                        var end2   = cell.Vertices[face[2]].ToXYZ();

                        var start3 = cell.Vertices[face[2]].ToXYZ();
                        var end3   = cell.Vertices[face[0]].ToXYZ();

                        var l1 = this.UIDocument.Application.Application.Create.NewLineBound(start1, end1);
                        _tessellationLines.Add(l1);

                        var l2 = this.UIDocument.Application.Application.Create.NewLineBound(start2, end2);
                        _tessellationLines.Add(l2);

                        var l3 = this.UIDocument.Application.Application.Create.NewLineBound(start3, end3);
                        _tessellationLines.Add(l3);

                        result = FSharpList <Value> .Cons(Value.NewContainer(l1), result);

                        result = FSharpList <Value> .Cons(Value.NewContainer(l2), result);

                        result = FSharpList <Value> .Cons(Value.NewContainer(l3), result);
                    }
                }

                return(Value.NewList(result));
            }

            return(Value.NewList(result));
        }
Exemple #7
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            ParticleSystem particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;

            var result = FSharpList <Value> .Empty;

            ParticleSpring s;
            Particle       springEnd1;
            Particle       springEnd2;
            XYZ            springXYZ1;
            XYZ            springXYZ2;
            Line           springLine;

            //create a geometry curve from each spring
            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                s          = particleSystem.getSpring(i);
                springEnd1 = s.getOneEnd();
                springEnd2 = s.getTheOtherEnd();

                springXYZ1 = springEnd1.getPosition();
                springXYZ2 = springEnd2.getPosition();
                springLine = dynRevitSettings.Doc.Application.Application.Create.NewLineBound(springXYZ1, springXYZ2);

                result = FSharpList <Value> .Cons(Value.NewContainer(springLine), result);
            }

            return(Value.NewList(result));
        }
Exemple #8
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var pts = (args[0] as Value.List).Item;

            if (pts.Length < 3)
            {
                throw new Exception("3 or more XYZs are necessary to form the best fit plane.");
            }

            var        ptList = dynBestFitLine.AsGenericList <XYZ>(pts);
            XYZ        meanPt;
            List <XYZ> orderedEigenvectors;

            dynBestFitLine.PrincipalComponentsAnalysis(ptList, out meanPt, out orderedEigenvectors);

            var normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]);

            var results = FSharpList <Value> .Empty;

            results = FSharpList <Value> .Cons(Value.NewContainer(meanPt), results);

            results = FSharpList <Value> .Cons(Value.NewContainer(normal), results);

            return(Value.NewList(results));
        }
Exemple #9
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var input  = args[0];
            var result = FSharpList <Value> .Empty;

            if (input.IsList)
            {
                var uvList = (input as Value.List).Item;
                int length = uvList.Length;

                var verts = new List <Vertex2>();

                for (int i = 0; i < length; i++)
                {
                    UV      uv   = (UV)((Value.Container)uvList[i]).Item;
                    Vertex2 vert = new Vertex2(uv.U, uv.V);
                    verts.Add(vert);
                }

                var voronoiMesh = VoronoiMesh.Create <Vertex2, Cell2>(verts);

                _tessellationLines.Clear();

                object arg1 = ((Value.Container)args[1]).Item;
                var    f    = arg1 as Face;

                if (f != null)
                {
                    foreach (VoronoiEdge <Vertex2, Cell2> edge in voronoiMesh.Edges)
                    {
                        var from = edge.Source.Circumcenter;
                        var to   = edge.Target.Circumcenter;

                        var uv1 = new UV(from.X, from.Y);
                        var uv2 = new UV(to.X, to.Y);

                        if (!f.IsInside(uv1) || !f.IsInside(uv2))
                        {
                            continue;
                        }

                        var start = f.Evaluate(uv1);
                        var end   = f.Evaluate(uv2);

                        if (start.DistanceTo(end) > 0.1)
                        {
                            var l = this.UIDocument.Application.Application.Create.NewLineBound(start, end);
                            _tessellationLines.Add(l);

                            result = FSharpList <Value> .Cons(Value.NewContainer(l), result);
                        }
                    }
                }

                return(Value.NewList(result));
            }

            return(Value.NewList(result));
        }
Exemple #10
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var param = args[1];

            if (param.IsString)
            {
                var paramName = ((Value.String)param).Item;

                var input = args[0];
                if (input.IsList)
                {
                    var fiList = (input as Value.List).Item;
                    return(Value.NewList(
                               Utils.SequenceToFSharpList(
                                   fiList.Select(
                                       x =>
                                       getParam(
                                           (FamilyInstance)((Value.Container)x).Item,
                                           paramName
                                           )
                                       )
                                   )
                               ));
                }
                else
                {
                    var fi = (FamilyInstance)((Value.Container)input).Item;

                    return(getParam(fi, paramName));
                }
            }
            else
            {
                var paramDef = (Definition)((Value.Container)param).Item;

                var input = args[0];
                if (input.IsList)
                {
                    var fiList = (input as Value.List).Item;
                    return(Value.NewList(
                               Utils.SequenceToFSharpList(
                                   fiList.Select(
                                       x =>
                                       getParam(
                                           (FamilyInstance)((Value.Container)x).Item,
                                           paramDef
                                           )
                                       )
                                   )
                               ));
                }
                else
                {
                    var fi = (FamilyInstance)((Value.Container)input).Item;

                    return(getParam(fi, paramDef));
                }
            }
        }
        public override Value Evaluate(FSharpList <Value> args)
        {
            var particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;

            return(Value.NewList(
                       Utils.SequenceToFSharpList(
                           particleSystem.Particles.Select(p => Value.NewContainer(p.getPosition())))));
        }
Exemple #12
0
        public override void  Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var origin    = (XYZ)((Value.Container)args[0]).Item;
            var direction = (XYZ)((Value.Container)args[1]).Item;
            var rayLimit  = ((Value.Number)args[2]).Item;
            var view      = (View3D)((Value.Container)args[3]).Item;

            XYZ startpt  = origin;
            int rayCount = 0;

            var bouncePts      = FSharpList <Value> .Empty;
            var bounceElements = FSharpList <Value> .Empty;

            bouncePts = FSharpList <Value> .Cons(Value.NewContainer(origin), bouncePts);

            for (int ctr = 1; ctr <= rayLimit; ctr++)
            {
                var referenceIntersector = new ReferenceIntersector(view);
                IList <ReferenceWithContext> references = referenceIntersector.Find(startpt, direction);
                ReferenceWithContext         rClosest   = null;
                rClosest = FindClosestReference(references);
                if (rClosest == null)
                {
                    break;
                }
                else
                {
                    var reference        = rClosest.GetReference();
                    var referenceElement = dynRevitSettings.Doc.Document.GetElement(reference);
                    bounceElements = FSharpList <Value> .Cons(Value.NewContainer(referenceElement), bounceElements);

                    var referenceObject = referenceElement.GetGeometryObjectFromReference(reference);
                    var endpt           = reference.GlobalPoint;
                    if (startpt.IsAlmostEqualTo(endpt))
                    {
                        break;
                    }
                    else
                    {
                        rayCount = rayCount + 1;
                        currFace = referenceObject as Face;
                        var endptUV    = reference.UVPoint;
                        var FaceNormal = currFace.ComputeDerivatives(endptUV).BasisZ;                          // face normal where ray hits
                        FaceNormal = rClosest.GetInstanceTransform().OfVector(FaceNormal);                     // transformation to get it in terms of document coordinates instead of the parent symbol
                        var directionMirrored = direction - 2 * direction.DotProduct(FaceNormal) * FaceNormal; //http://www.fvastro.org/presentations/ray_tracing.htm
                        direction = directionMirrored;                                                         // get ready to shoot the next ray
                        startpt   = endpt;

                        bouncePts = FSharpList <Value> .Cons(Value.NewContainer(endpt), bouncePts);
                    }
                }
            }
            bouncePts.Reverse();
            bounceElements.Reverse();

            outPuts[intersections] = Value.NewList(bouncePts);
            outPuts[elements]      = Value.NewList(bounceElements);
        }
Exemple #13
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            if (SelectedElements == null)
            {
                throw new Exception("Nothing selected.");
            }

            var els = SelectedElements.Select(Value.NewContainer).ToList();

            return(Value.NewList(Utils.SequenceToFSharpList(els)));
        }
Exemple #14
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var input = args[0];

            //create some geometry options so that we compute references
            Autodesk.Revit.DB.Options opts = new Options();
            opts.ComputeReferences        = true;
            opts.DetailLevel              = ViewDetailLevel.Medium;
            opts.IncludeNonVisibleObjects = false;


            if (input.IsList)
            {
                var familyList = (input as Value.List).Item;
                int count      = 0;

                var result = Value.NewList(
                    Utils.SequenceToFSharpList(
                        familyList.Select(
                            x =>
                            this.GetCurvesFromFamily(
                                (FamilyInstance)((Value.Container)x).Item,
                                count++,
                                opts
                                )
                            )
                        )
                    );

                foreach (var e in this.Elements.Skip(count))
                {
                    this.DeleteElement(e);
                }

                return(result);
            }
            else // single instance passed in
            {
                int count  = 0;
                var result = this.GetCurvesFromFamily(
                    (FamilyInstance)((Value.Container)input).Item,
                    count,
                    opts
                    );

                foreach (var e in this.Elements.Skip(1)) // cleanup in case of going from list to single instance.
                {
                    this.DeleteElement(e);
                }

                return(result);
            }
        }
Exemple #15
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var elementType = (Type)((Value.Container)args[0]).Item;

            var collector = new FilteredElementCollector(dynRevitSettings.Doc.Document);

            collector.OfClass(elementType);

            var results = collector.ToElements().Aggregate(FSharpList <Value> .Empty, (current, el) => FSharpList <Value> .Cons(Value.NewContainer(el), current));

            return(Value.NewList(results));
        }
Exemple #16
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var topo = (TopographySurface)((Value.Container)args[0]).Item;

            if (!topo.GetPoints().Any())
            {
                throw new Exception("There are no points in the topography surface.");
            }

            var pts = topo.GetPoints().Select(Value.NewContainer);

            return(Value.NewList(Utils.SequenceToFSharpList(pts)));
        }
Exemple #17
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            _points    = ((Value.List)args[0]).Item;                      //point list
            _curves    = ((Value.List)args[1]).Item;                      //spring list
            _d         = ((Value.Number)args[2]).Item;                    //dampening
            _s         = ((Value.Number)args[3]).Item;                    //spring constant
            _r         = ((Value.Number)args[4]).Item;                    //rest length
            _use_rl    = Convert.ToBoolean(((Value.Number)args[5]).Item); //use rest length
            _rlf       = ((Value.Number)args[6]).Item;                    //rest length factor
            _m         = ((Value.Number)args[7]).Item;                    //nodal mass
            _g         = ((Value.Number)args[8]).Item;                    //gravity z component
            _threshold = ((Value.Number)args[9]).Item;                    //convergence threshold

            //if we are in the evaluate, this has been
            //marked dirty and we should set it to unconverged
            //in case one of the inputs has changed.
            particleSystem.setConverged(false);
            particleSystem.setGravity(_g);
            particleSystem.setThreshold(_threshold);

            //if the particle system has a different layout, then
            //clear it instead of updating
            if (particleSystem.numberOfParticles() == 0 ||
                _fixPtCount != _points.Count() ||
                _curves.Count() != particleSystem.numberOfSprings() ||
                _reset)
            {
                ResetSystem(_points, _curves);
            }
            else
            {
                UpdateSystem();
            }

            FSharpList <Value> forces = FSharpList <Value> .Empty;

            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                forces = FSharpList <Value> .Cons(Value.NewNumber(particleSystem.getSpring(i).getResidualForce()), forces);
            }
            forces.Reverse();

            FSharpList <Value> results = FSharpList <Value> .Empty;

            results = FSharpList <Value> .Cons(Value.NewList(forces), results);

            results = FSharpList <Value> .Cons(Value.NewContainer(particleSystem), results);

            //return Value.NewContainer(particleSystem);
            return(Value.NewList(results));
        }
Exemple #18
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var fs    = (FamilySymbol)((Value.Container)args[1]).Item;
            var input = args[0];
            var level = (Autodesk.Revit.DB.Level)((Value.Container)args[2]).Item;

            if (input.IsList)
            {
                var locList = (input as Value.List).Item;

                int count = 0;

                var result = Value.NewList(
                    Utils.SequenceToFSharpList(
                        locList.Select(
                            x =>
                            this.makeFamilyInstance(
                                ((Value.Container)x).Item,
                                fs,
                                count++,
                                level
                                )
                            )
                        )
                    );

                foreach (var e in this.Elements.Skip(count))
                {
                    this.DeleteElement(e);
                }

                return(result);
            }
            else
            {
                var result = this.makeFamilyInstance(
                    ((Value.Container)input).Item,
                    fs,
                    0,
                    level
                    );

                foreach (var e in this.Elements.Skip(1))
                {
                    this.DeleteElement(e);
                }

                return(result);
            }
        }
Exemple #19
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var cat = (BuiltInCategory)((Value.Container)args[0]).Item;

            //get the selected category and select all elements
            //in the document of that category
            var fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);

            fec.OfCategory(cat);

            var results = fec.ToElements().Aggregate(FSharpList <Value> .Empty, (current, el) => FSharpList <Value> .Cons(Value.NewContainer(el), current));

            return(Value.NewList(results));
        }
Exemple #20
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var c = (Color)((Value.Container)args[0]).Item;

            var results = FSharpList <Value> .Empty;

            results = FSharpList <Value> .Cons(Value.NewNumber(c.B), results);

            results = FSharpList <Value> .Cons(Value.NewNumber(c.G), results);

            results = FSharpList <Value> .Cons(Value.NewNumber(c.R), results);

            results = FSharpList <Value> .Cons(Value.NewNumber(c.A), results);

            return(Value.NewList(results));
        }
Exemple #21
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var    particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;
            double timeStep       = ((Value.Number)args[1]).Item;

            particleSystem.step(timeStep);//in ms

            //trigger an intermittent update on the controller
            //this is useful for when this node is used in an infinite
            //loop and you need to draw its contents
            dynSettings.Controller.OnRequestsRedraw(this, EventArgs.Empty);

            return(Value.NewList(Utils.MakeFSharpList <Value>(
                                     new Value[] { Value.NewNumber(particleSystem.getMaxNodalVelocity()), Value.NewNumber(Convert.ToInt16(particleSystem.getConverged())) })
                                 ));
        }
Exemple #22
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).");
        }
Exemple #23
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var pts = (args[0] as Value.List).Item;

            var        ptList = AsGenericList <XYZ>(pts);
            XYZ        meanPt;
            List <XYZ> orderedEigenvectors;

            PrincipalComponentsAnalysis(ptList, out meanPt, out orderedEigenvectors);

            var results = FSharpList <Value> .Empty;

            results = FSharpList <Value> .Cons(Value.NewContainer(meanPt), results);

            results = FSharpList <Value> .Cons(Value.NewContainer(orderedEigenvectors[0]), results);

            return(Value.NewList(results));
        }
Exemple #24
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            FSharpList <Value> result = FSharpList <Value> .Empty;
            BoundingBoxUV      bbox   = null;

            object arg0 = ((Value.Container)args[0]).Item;

            Autodesk.Revit.DB.Face f;

            Reference faceRef = arg0 as Reference;

            if (faceRef != null)
            {
                f = dynRevitSettings.Doc.Document.GetElement(faceRef.ElementId).GetGeometryObjectFromReference(faceRef) as Autodesk.Revit.DB.Face;
            }
            else
            {
                f = arg0 as Autodesk.Revit.DB.Face;
            }

            if (f != null)
            {
                bbox = f.GetBoundingBox();
            }

            result = FSharpList <Value> .Cons(
                Value.NewNumber(bbox.Max.V - bbox.Min.V),
                result);

            result = FSharpList <Value> .Cons(
                Value.NewNumber(bbox.Max.U - bbox.Min.U),
                result);

            result = FSharpList <Value> .Cons(
                Value.NewContainer(bbox.Max),
                result);

            result = FSharpList <Value> .Cons(
                Value.NewContainer(bbox.Min),
                result);

            //Fin
            return(Value.NewList(result));
        }
Exemple #25
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            ParticleSystem particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;

            var result = FSharpList <Value> .Empty;

            Particle p;
            XYZ      pt;

            //create an XYZ from each Particle
            for (int i = 0; i < particleSystem.numberOfParticles(); i++)
            {
                p      = particleSystem.getParticle(i);
                pt     = new XYZ(p.getPosition().X, p.getPosition().Y, p.getPosition().Z);
                result = FSharpList <Value> .Cons(Value.NewContainer(pt), result);
            }

            return(Value.NewList(result));
        }
Exemple #26
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            //Build a sequence that unwraps the input list from it's Value form.
            var pts = ((Value.List)args[0]).Item.Select(
                x => (XYZ)((Value.Container)x).Item
                );

            var results = FSharpList <Value> .Empty;

            var enumerable = pts as XYZ[] ?? pts.ToArray();

            for (var i = 1; i < enumerable.Count(); i++)
            {
                var l = dynRevitSettings.Revit.Application.Create.NewLineBound(enumerable.ElementAt(i), enumerable.ElementAt(i - 1));

                results = FSharpList <Value> .Cons(Value.NewContainer(l), results);
            }

            return(Value.NewList(results));
        }
Exemple #27
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var input = args[0];

            if (input.IsList)
            {
                int count  = 0;
                var result = Value.NewList(
                    Utils.SequenceToFSharpList(
                        (input as Value.List).Item.Select(
                            x =>
                            this.extractCurve(
                                ((Value.Container)x).Item,
                                count++
                                )
                            )
                        )
                    );
                foreach (var e in this.Elements.Skip(count))
                {
                    this.DeleteElement(e);
                }

                return(result);
            }
            else
            {
                var result = this.extractCurve(
                    ((Value.Container)input).Item,
                    0

                    );

                foreach (var e in this.Elements.Skip(1))
                {
                    this.DeleteElement(e);
                }

                return(result);
            }
        }
Exemple #28
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var curve = (Curve)((Value.Container)args[0]).Item;
            var plane = (Autodesk.Revit.DB.Plane)((Value.Container)args[1]).Item;

            var curvePts = curve.Tessellate();
            var xSects   = new List <XYZ>();

            for (int i = 0; i < curvePts.Count - 1; ++i)
            {
                var a     = curvePts[i];
                var b     = curvePts[i + 1];
                var xsect = linePlaneIntersection(plane, a, b);
                if (xsect != null)
                {
                    xSects.Add(xsect);
                }
            }

            return(Value.NewList(Utils.SequenceToFSharpList(xSects.Select(Value.NewContainer))));
        }
Exemple #29
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Autodesk.Revit.DB.CurveLoop curveLoop = (Autodesk.Revit.DB.CurveLoop)((Value.Container)args[0]).Item;

            CurveLoopIterator CLiter = curveLoop.GetCurveLoopIterator();

            List <Curve> listCurves = new List <Curve>();

            for (; CLiter.MoveNext();)
            {
                listCurves.Add(CLiter.Current.Clone());
            }

            var result = FSharpList <Value> .Empty;

            for (int indexCurve = listCurves.Count - 1; indexCurve > -1; indexCurve--)
            {
                result = FSharpList <Value> .Cons(Value.NewContainer(listCurves[indexCurve]), result);
            }

            return(Value.NewList(result));
        }
Exemple #30
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Geometry geom1 = (Geometry)((Value.Container)args[0]).Item;
            Geometry geom2 = (Geometry)((Value.Container)args[1]).Item;

            GeometryList result = geom1.intersect(geom2);

            foreach (Geometry g in _result)
            {
                GraphicItem.unpersist(g);
            }

            _result.Clear();

            foreach (Geometry g in result)
            {
                Geometry restored = RestoreProperType(g);

                GraphicItem.persist(restored);
                _result.Add(restored);
                _graphicItems.Add(restored);
            }

            if (_result.Count == 1)
            {
                return(Value.NewContainer(_result[0]));
            }
            else
            {
                List <Value> return_values = new List <Value>();

                foreach (Geometry g in _result)
                {
                    return_values.Add(Value.NewContainer(g));
                }

                return(Value.NewList(Utils.SequenceToFSharpList(return_values)));
            }
        }