Beispiel #1
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            string path = ((Value.String)args[0]).Item;
            string name = ((Value.String)args[1]).Item;

            System.Drawing.Image image = (System.Drawing.Image)((Value.Container)args[2]).Item;
            string pathName            = path + "\\" + name + ".png";

            try
            {
                //if (image != null)
                //{
                image.Save(pathName);
                dynSettings.Controller.DynamoViewModel.Log("Saved Image File " + pathName);
                //}
            }
            catch (Exception e)
            {
                dynSettings.Controller.DynamoViewModel.Log("Error Saving Image File " + pathName);
                dynSettings.Controller.DynamoViewModel.Log(e);
                return(Value.NewNumber(0));
            }

            return(Value.NewNumber(1));
        }
Beispiel #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));
        }
Beispiel #3
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            port = (SerialPort)((Value.Container)args[0]).Item;
            string dataToWrite = ((Value.String)args[1]).Item;// ((Value.Container)args[1]).Item;

            if (port != null)
            {
                bool isOpen = true;// Convert.ToBoolean(InPortData[0].Object);

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

                    //write data to the serial port
                    WriteDataToArduino(dataToWrite);
                }
                else if (isOpen == false)
                {
                    if (port.IsOpen)
                    {
                        port.Close();
                    }
                }
            }


            return(Value.NewNumber(1));// catch failures here
        }
Beispiel #4
0
        private static Value _getParam(Parameter p)
        {
            switch (p.StorageType)
            {
            case StorageType.ElementId:
                return(Value.NewContainer(p.AsElementId()));

            case StorageType.String:
                return(Value.NewString(p.AsString()));

            case StorageType.Integer:
            case StorageType.Double:
                switch (p.Definition.ParameterType)
                {
                case ParameterType.Length:
                    return(Value.NewContainer(Units.Length.FromFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)));

                case ParameterType.Area:
                    return(Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)));

                case ParameterType.Volume:
                    return(Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)));

                default:
                    return(Value.NewNumber(p.AsDouble()));
                }

            default:
                throw new Exception(string.Format("Parameter {0} has no storage type.", p));
            }
        }
Beispiel #5
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());
        }
Beispiel #6
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var a = (XYZ)((Value.Container)args[0]).Item;
            var b = (XYZ)((Value.Container)args[1]).Item;

            return(Value.NewNumber(a.DistanceTo(b)));
        }
Beispiel #7
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            double area = 0.0;

            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)
            {
                area = f.Area;
            }

            //Fin
            return(Value.NewNumber(area));
        }
Beispiel #8
0
        //protected override void OnRunCancelled()
        //{
        //    if (delayThread != null && delayThread.IsAlive)
        //        delayThread.Abort();
        //}

        public override Value Evaluate(FSharpList <Value> args)
        {
            int delay = (int)((Value.Number)args[0]).Item;

            if (delayThread == null || !delayThread.IsAlive)
            {
                delayThread = new Thread(new ThreadStart(
                                             delegate
                {
                    Thread.Sleep(delay);

                    if (Controller.RunCancelled)
                    {
                        return;
                    }

                    while (Controller.Running)
                    {
                        Thread.Sleep(1);
                        if (Controller.RunCancelled)
                        {
                            return;
                        }
                    }

                    this.RequiresRecalc = true;
                }
                                             ));

                delayThread.Start();
            }

            return(Value.NewNumber(1));
        }
Beispiel #9
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var    watcher = (FileWatcher)((Value.Container)args[0]).Item;
            double timeout = ((Value.Number)args[1]).Item;

            timeout = timeout == 0 ? double.PositiveInfinity : timeout;

            int tick = 0;

            while (!watcher.Changed)
            {
                if (Controller.RunCancelled)
                {
                    throw new Controls.CancelEvaluationException(false);
                }

                Thread.Sleep(10);
                tick += 10;

                if (tick >= timeout)
                {
                    throw new Exception("File watcher timeout!");
                }
            }

            return(Value.NewNumber(1));
        }
Beispiel #10
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Surface s = (Surface)((Value.Container)args[0]).Item;

            double a = s.area();

            return(Value.NewNumber(a));
        }
Beispiel #11
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Point p = (Point)((Value.Container)args[0]).Item;

            double y = p.y();

            return(Value.NewNumber(y));
        }
Beispiel #12
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Vector p = (Vector)((Value.Container)args[0]).Item;

            double z = p.z();

            return(Value.NewNumber(z));
        }
Beispiel #13
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Curve c = (Curve)((Value.Container)args[0]).Item;

            double l = c.length();

            return(Value.NewNumber(l));
        }
Beispiel #14
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            int ms = (int)((Value.Number)args[0]).Item;

            Thread.Sleep(ms);

            return(Value.NewNumber(1));
        }
Beispiel #15
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var xyz      = (XYZ)((Value.Container)args[0]).Item;
            var inputArg = ((Value.Container)args[1]).Item;

            XYZ    pt;
            UV     uv;
            double d;
            Edge   e;
            double et;

            var face = inputArg is Face ? (Face)inputArg : null;

            if (face == null && !(inputArg is Plane))
            {
                throw new Exception(" Project Point On Face needs Face or Plane as argument no. 1");
            }
            if (face == null)
            {
                var pln = (Plane)inputArg;
                uv = new UV(
                    pln.XVec.DotProduct(xyz - pln.Origin), pln.YVec.DotProduct(xyz - pln.Origin));
                pt = pln.Origin + uv[0] * pln.XVec + uv[1] * pln.YVec;
                d  = xyz.DistanceTo(pt);
                e  = null;
                et = 0.0;
            }
            else
            {
                IntersectionResult ir = face.Project(xyz);

                pt = ir.XYZPoint;
                uv = ir.UVPoint;
                d  = ir.Distance;
                e  = null;
                et = 0;

                try
                {
                    e = ir.EdgeObject;
                }
                catch { }

                try
                {
                    et = ir.EdgeParameter;
                }
                catch { }
            }

            pts.Add(pt);

            outPuts[_xyzPort]   = Value.NewContainer(xyz);
            outPuts[_uvPort]    = Value.NewContainer(uv);
            outPuts[_dPort]     = Value.NewNumber(d);
            outPuts[_edgePort]  = Value.NewContainer(e);
            outPuts[_edgeTPort] = Value.NewNumber(et);
        }
Beispiel #16
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            //Grab our inputs and turn them into XYZs.
            XYZ ptA = this.getXYZ(((Value.Container)args[0]).Item);
            XYZ ptB = this.getXYZ(((Value.Container)args[1]).Item);

            //Return the calculated distance.
            return(Value.NewNumber(ptA.DistanceTo(ptB)));
        }
Beispiel #17
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var c = (System.Drawing.Color)((Value.Container)args[0]).Item;

            outPuts[_alphaOut] = Value.NewNumber(c.A);
            outPuts[_redOut]   = Value.NewNumber(c.R);
            outPuts[_greenOut] = Value.NewNumber(c.G);
            outPuts[_blueOut]  = Value.NewNumber(c.B);
        }
Beispiel #18
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            resultImageUI.ResultImage = (Image)((Value.Container)args[0]).Item;

            //DispatchOnUIThread(delegate
            //{

            //   image1.Source = resultImage;
            //});

            return(Value.NewNumber(1));
        }
Beispiel #19
0
 public override Value Evaluate(FSharpList <Value> args)
 {
     if (this.SelectedIndex < this.Items.Length)
     {
         var value = Value.NewNumber(this.SelectedIndex);
         return(value);
     }
     else
     {
         throw new Exception("There is nothing selected.");
     }
 }
Beispiel #20
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));
        }
Beispiel #21
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var xyz = (XYZ)((Value.Container)args[0]).Item;
            var crv = (Curve)((Value.Container)args[1]).Item;

            IntersectionResult ir = crv.Project(xyz);
            XYZ    pt             = ir.XYZPoint;
            double t = ir.Parameter;
            double d = ir.Distance;

            outPuts[_xyzPort] = Value.NewContainer(pt);
            outPuts[_tPort]   = Value.NewNumber(t);
            outPuts[_dPort]   = Value.NewNumber(d);
        }
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var    partSys  = (ParticleSystem)((Value.Container)args[0]).Item;
            double timeStep = ((Value.Number)args[1]).Item;

            partSys.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);

            outPuts[_vMaxPort]      = Value.NewNumber(partSys.getMaxNodalVelocity());
            outPuts[_convergedPort] = Value.NewNumber(Convert.ToInt16(partSys.getConverged()));
        }
Beispiel #23
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));
        }
Beispiel #24
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())) })
                                 ));
        }
Beispiel #25
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            string path = ((Value.String)args[0]).Item;
            string text = ((Value.String)args[1]).Item;

            try
            {
                File.WriteAllText(path, text);
            }
            catch (Exception e)
            {
                dynSettings.Controller.DynamoViewModel.Log(e);
                return(Value.NewNumber(0));
            }

            return(Value.NewNumber(1));
        }
Beispiel #26
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            string path = ((Value.String)args[0]).Item;
            string text = ((Value.String)args[1]).Item;

            try
            {
                File.WriteAllText(path, text);
            }
            catch (Exception e)
            {
                DynamoLogger.Instance.Log(e);
                return(Value.NewNumber(0));
            }

            return(Value.NewNumber(1));
        }
Beispiel #27
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var e = new Expression(FormulaString.ToLower(), EvaluateOptions.IgnoreCase);

            e.Parameters["pi"] = 3.14159265358979;

            var functionLookup = new Dictionary <string, Value>();

            foreach (var arg in args.Select((arg, i) => new { Value = arg, Index = i }))
            {
                var parameter = InPortData[arg.Index].NickName;
                if (arg.Value.IsFunction)
                {
                    functionLookup[parameter] = arg.Value;
                }
                else
                {
                    if (arg.Value.IsNumber)
                    {
                        e.Parameters[parameter] = ((Value.Number)arg.Value).Item;
                    }
                    else if (arg.Value.IsContainer)
                    {
                        e.Parameters[parameter] = Utils.UnwrapToSIUnit(arg.Value).Value *dynSettings.Controller.UnitsManager.UiLengthConversion;
                    }
                }
            }

            e.EvaluateFunction += delegate(string name, FunctionArgs fArgs)
            {
                if (functionLookup.ContainsKey(name))
                {
                    var func = ((Value.Function)functionLookup[name]).Item;
                    fArgs.Result = ((Value.Number)func.Invoke(
                                        Utils.ToFSharpList(
                                            fArgs.Parameters.Select(
                                                p => Value.NewNumber(Convert.ToDouble(p.Evaluate())))))).Item;
                }
                else
                {
                    fArgs.HasResult = false;
                }
            };

            return(Value.NewNumber(Convert.ToDouble(e.Evaluate())));
        }
Beispiel #28
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));
        }
Beispiel #29
0
 private static Value _getParam(FamilyInstance fi, Parameter p)
 {
     if (p.StorageType == StorageType.Double)
     {
         return(Value.NewNumber(p.AsDouble()));
     }
     else if (p.StorageType == StorageType.Integer)
     {
         return(Value.NewNumber(p.AsInteger()));
     }
     else if (p.StorageType == StorageType.String)
     {
         return(Value.NewString(p.AsString()));
     }
     else
     {
         return(Value.NewContainer(p.AsElementId()));
     }
 }
Beispiel #30
0
        /// <summary>
        /// Unwrap an FScheme value containing a number or a unit to a double.
        /// If the value contains a unit object, convert the internal value of the
        /// unit object to the units required by the host application as specified
        /// in the preference settings. If the value contains a number, do not
        /// apply a conversion.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Value UnwrapToDoubleWithHostUnitConversion(Value value)
        {
            if (value.IsList)
            {
                //recursively convert items in list
                return(ConvertListToHostUnits((Value.List)value));
            }

            if (value.IsContainer)
            {
                var unit = ((Value.Container)value).Item as SIUnit;
                if (unit != null)
                {
                    return(Value.NewNumber(unit.ConvertToHostUnits()));
                }
            }

            return(value);
        }