Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            string url = ((Value.String)args[0]).Item;

            //send a webrequest to the URL
            // Initialize the WebRequest.
            System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url);

            // Return the response.
            WebResponse myResponse = myRequest.GetResponse();

            Stream dataStream = myResponse.GetResponseStream();

            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);

            // Read the content.
            string responseFromServer = reader.ReadToEnd();

            reader.Close();

            // Close the response to free resources.
            myResponse.Close();

            return(Value.NewString(responseFromServer));
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            port = (SerialPort)((Value.Container)args[0]).Item;
            var delim = ((Value.String)args[1]).Item;

            var lastValue = string.Empty;

            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
                    lastValue = GetArduinoData(port, delim);
                }
            }

            return(Value.NewString(lastValue));
        }
Exemplo n.º 6
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            listenPort = (int)((Value.Number)args[1]).Item; // udp port to listen to


            if (((Value.Number)args[0]).Item == 1) // if exec node has pumped
            {
                DispatchOnUIThread(ListenOnUDP);
            }

            return(Value.NewString(UDPResponse));
        }
Exemplo n.º 7
0
 public override Value Evaluate(FSharpList <Value> args)
 {
     if (this.SelectedIndex < this.Items.Length)
     {
         var value = Value.NewString(Items.GetValue(this.SelectedIndex).ToString());
         return(value);
     }
     else
     {
         throw new Exception("There is nothing selected.");
     }
 }
Exemplo n.º 8
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var face1 = (Face)((Value.Container)args[0]).Item;
            var face2 = (Face)((Value.Container)args[1]).Item;

            Type faceType = typeof(Face);

            MethodInfo[] faceMethods           = faceType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            const string nameOfMethodIntersect = "Intersect";

            bool set = false;

            foreach (MethodInfo mi in faceMethods)
            {
                //find a method that matches the name
                if (mi.Name == nameOfMethodIntersect)
                {
                    //find the method which matches the signature
                    ParameterInfo[] pi = mi.GetParameters();
                    if (pi.Length == 2 &&
                        pi[0].ParameterType == typeof(Face) &&
                        pi[1].ParameterType == typeof(Curve).MakeByRefType())
                    {
                        var methodArgs = new object[2];
                        methodArgs[0] = face2;
                        methodArgs[1] = null;

                        //var result = face1.Intersect(face2, out resultCurve);
                        var result = mi.Invoke(face1, methodArgs);
                        if (methodArgs[1] != null)
                        {
                            curves.Add((Curve)methodArgs[1]);
                        }

                        set = true;

                        outPuts[_resultPort] = Value.NewString(result.ToString());
                        outPuts[_curvePort]  = Value.NewContainer(methodArgs[1]);
                    }
                }
            }

            if (!set)
            {
                throw new Exception("No suitable method found to perform intersection");
            }
        }
Exemplo n.º 9
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            storedPath = ((Value.String)args[0]).Item;

            if (File.Exists(storedPath))
            {
                string contents;

                contents = File.ReadAllText(storedPath);

                return(Value.NewString(contents));
            }
            else
            {
                return(Value.NewString(""));
            }
        }
Exemplo n.º 10
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()));
     }
 }
Exemplo n.º 11
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var   crv       = (Curve)((Value.Container)args[0]).Item;
            Face  face      = null;
            Solid tempSolid = null;
            Plane thisPlane = null;

            if (((Value.Container)args[1]).Item is Face)
            {
                face = (Autodesk.Revit.DB.Face)((Value.Container)args[1]).Item;
            }
            else if (((Value.Container)args[1]).Item is Plane)
            {
                thisPlane = ((Value.Container)args[1]).Item as Plane;
                // tesselate curve and find uv envelope in projection to the plane
                IList <XYZ> tessCurve      = crv.Tessellate();
                var         curvePointEnum = tessCurve.GetEnumerator();
                XYZ         corner1        = new XYZ();
                XYZ         corner2        = new XYZ();
                bool        cornersSet     = false;
                for (; curvePointEnum.MoveNext();)
                {
                    if (!cornersSet)
                    {
                        corner1    = curvePointEnum.Current;
                        corner2    = curvePointEnum.Current;
                        cornersSet = true;
                    }
                    else
                    {
                        for (int coord = 0; coord < 3; coord++)
                        {
                            if (corner1[coord] > curvePointEnum.Current[coord])
                            {
                                corner1 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner1[coord],
                                                  coord == 1 ? curvePointEnum.Current[coord] : corner1[coord],
                                                  coord == 2 ? curvePointEnum.Current[coord] : corner1[coord]);
                            }
                            if (corner2[coord] < curvePointEnum.Current[coord])
                            {
                                corner2 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner2[coord],
                                                  coord == 1 ? curvePointEnum.Current[coord] : corner2[coord],
                                                  coord == 2 ? curvePointEnum.Current[coord] : corner2[coord]);
                            }
                        }
                    }
                }

                double dist1    = thisPlane.Origin.DistanceTo(corner1);
                double dist2    = thisPlane.Origin.DistanceTo(corner2);
                double sizeRect = 2.0 * (dist1 + dist2) + 100.0;


                CurveLoop cLoop = new CurveLoop();
                for (int index = 0; index < 4; index++)
                {
                    double coord0 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
                    double coord1 = (index < 2) ? -sizeRect : sizeRect;
                    XYZ    pnt0   = thisPlane.Origin + coord0 * thisPlane.XVec + coord1 * thisPlane.YVec;

                    double coord3 = (index < 2) ? sizeRect : -sizeRect;
                    double coord4 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
                    XYZ    pnt1   = thisPlane.Origin + coord3 * thisPlane.XVec + coord4 * thisPlane.YVec;
                    Line   cLine  = dynRevitSettings.Revit.Application.Create.NewLineBound(pnt0, pnt1);
                    cLoop.Append(cLine);
                }
                List <CurveLoop> listCLoops = new List <CurveLoop> ();
                listCLoops.Add(cLoop);

                tempSolid = GeometryCreationUtilities.CreateExtrusionGeometry(listCLoops, thisPlane.Normal, 100.0);

                //find right face

                FaceArray facesOfExtrusion = tempSolid.Faces;
                for (int indexFace = 0; indexFace < facesOfExtrusion.Size; indexFace++)
                {
                    Face faceAtIndex = facesOfExtrusion.get_Item(indexFace);
                    if (faceAtIndex is PlanarFace)
                    {
                        PlanarFace pFace = faceAtIndex as PlanarFace;
                        if (Math.Abs(thisPlane.Normal.DotProduct(pFace.Normal)) < 0.99)
                        {
                            continue;
                        }
                        if (Math.Abs(thisPlane.Normal.DotProduct(thisPlane.Origin - pFace.Origin)) > 0.1)
                        {
                            continue;
                        }
                        face = faceAtIndex;
                        break;
                    }
                }
                if (face == null)
                {
                    throw new Exception("Curve Face Intersection could not process supplied Plane.");
                }
            }

            IntersectionResultArray xsects = new IntersectionResultArray();
            SetComparisonResult     result = face.Intersect(crv, out xsects);

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

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    var xsect = FSharpList <Value> .Empty;
                    try
                    {
                        xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.EdgeParameter), xsect);
                    }
                    catch
                    {
                        xsect = FSharpList <Value> .Cons(Value.NewNumber(0), xsect);
                    }
                    xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.EdgeObject), xsect);

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

                    if (thisPlane != null)
                    {
                        UV planeUV = new UV(thisPlane.XVec.DotProduct(ir.XYZPoint - thisPlane.Origin),
                                            thisPlane.YVec.DotProduct(ir.XYZPoint - thisPlane.Origin));
                        xsect = FSharpList <Value> .Cons(Value.NewContainer(planeUV), xsect);
                    }
                    else
                    {
                        xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.UVPoint), xsect);
                    }

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

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

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

            return(Value.NewList(results));
        }
Exemplo n.º 12
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  = null;
            double et = 0.0;

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

            if (face == null && !(inputArg is Autodesk.Revit.DB.Plane))
            {
                throw new Exception(" Project Point On Face needs Face or Plane as argument no. 1");
            }
            if (face == null)
            {
                var pln = (Autodesk.Revit.DB.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);
                bool projectedOnFace  = true;
                if (ir == null)
                {
                    outPuts[_resultPort] = Value.NewString("Projected Outside Face");
                    double edgeDist = 1.0e12;
                    XYZ    edgePt   = xyz;

                    projectedOnFace = false;

                    EdgeArrayArray edges = face.EdgeLoops;
                    for (int iLoop = 0; iLoop < edges.Size; iLoop++)
                    {
                        for (int iEdge = 0; iEdge < edges.get_Item(iLoop).Size; iEdge++)
                        {
                            Edge  thisEdge             = edges.get_Item(iLoop).get_Item(iEdge);
                            Curve thisAsCurve          = thisEdge.AsCurve();
                            IntersectionResult irCurve = thisAsCurve.Project(xyz);
                            if (irCurve != null && irCurve.Distance < edgeDist - 1.0e-12)
                            {
                                edgeDist = irCurve.Distance;
                                e        = thisEdge;
                                edgePt   = irCurve.XYZPoint;
                            }
                            else if (irCurve == null)
                            {
                                XYZ vertex0 = thisEdge.Evaluate(0.0);
                                if (vertex0.DistanceTo(xyz) < edgeDist - 1.0e-12)
                                {
                                    edgeDist = vertex0.DistanceTo(xyz);
                                    e        = thisEdge;
                                    edgePt   = vertex0;
                                }
                                XYZ vertex1 = thisEdge.Evaluate(1.0);
                                if (vertex1.DistanceTo(xyz) < edgeDist - 1.0e-12)
                                {
                                    edgeDist = vertex1.DistanceTo(xyz);
                                    e        = thisEdge;
                                    edgePt   = vertex1;
                                }
                            }
                        }
                    }
                    if (1.01 * edgeDist < 1.0e12)
                    {
                        ir = face.Project(edgePt);
                        d  = edgePt.DistanceTo(xyz);
                        pt = edgePt;
                    }
                    else
                    {
                        throw new Exception(" Could not find closest point on Face to return as projection.");
                    }
                }
                else
                {
                    outPuts[_resultPort] = Value.NewString("Projected Into Face");
                    d  = ir.Distance;
                    pt = ir.XYZPoint;
                }

                uv = projectedOnFace ? ir.UVPoint : null;

                if (projectedOnFace)
                {
                    try
                    {
                        e  = ir.EdgeObject;
                        et = ir.EdgeParameter;
                    }
                    catch
                    {
                        e  = null;
                        et = 0.0;
                    }
                }
            }


            outPuts[_xyzPort]   = Value.NewContainer(pt);
            outPuts[_uvPort]    = Value.NewContainer(uv);
            outPuts[_dPort]     = Value.NewNumber(d);
            outPuts[_edgePort]  = Value.NewContainer(e);
            outPuts[_edgeTPort] = Value.NewNumber(et);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Convert the result of a wrapped Revit API method or property to it's correct Dynamo Value type.
        /// </summary>
        /// <param name="input">The result of the Revit API method.</param>
        /// <returns></returns>
        public static Value ConvertToValue(object input)
        {
            if (input == null)
            {
                return(Value.NewNumber(0));
            }

            if (input.GetType() == typeof(double))
            {
                return(Value.NewNumber(System.Convert.ToDouble(input)));
            }
            else if (input.GetType() == typeof(int))
            {
                return(Value.NewNumber(System.Convert.ToDouble(input)));
            }
            else if (input.GetType() == typeof(string))
            {
                return(Value.NewString(System.Convert.ToString(input)));
            }
            else if (input.GetType() == typeof(bool))
            {
                return(Value.NewNumber(System.Convert.ToInt16(input)));
            }
            else if (input.GetType() == typeof(List <ElementId>))
            {
                List <Value> vals = new List <Value>();
                foreach (ElementId id in (List <ElementId>)input)
                {
                    vals.Add(Value.NewContainer(id));
                }

                return(Value.NewList(Utils.SequenceToFSharpList(vals)));
            }
            else if (input.GetType() == typeof(IntersectionResultArray))
            {
                // for interesection results, send out two lists
                // a list for the XYZs and one for the UVs
                List <Value> xyzs = new List <Value>();
                List <Value> uvs  = new List <Value>();

                foreach (IntersectionResult ir in (IntersectionResultArray)input)
                {
                    xyzs.Add(Value.NewContainer(ir.XYZPoint));
                    uvs.Add(Value.NewContainer(ir.UVPoint));
                }

                FSharpList <Value> result = FSharpList <Value> .Empty;
                result = FSharpList <Value> .Cons(
                    Value.NewList(Utils.SequenceToFSharpList(uvs)),
                    result);

                result = FSharpList <Value> .Cons(
                    Value.NewList(Utils.SequenceToFSharpList(xyzs)),
                    result);

                if (xyzs.Count > 0 || uvs.Count > 0)
                {
                    return(Value.NewList(result));
                }
                else
                {
                    //TODO: if we don't have any XYZs or UVs, chances are
                    //we have just created an intersection result array to
                    //catch some values. in this case, don't convert.
                    return(Value.NewContainer(input));
                }
            }
            else
            {
                return(Value.NewContainer(input));
            }
        }
Exemplo n.º 14
0
 public static Value ToValue(string input)
 {
     return(Value.NewString(input));
 }
Exemplo n.º 15
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var  crv  = (Curve)((Value.Container)args[0]).Item;
            Face face = null;

            Autodesk.Revit.DB.Plane thisPlane = null;

            var geo = ((Value.Container)args[1]).Item;

            IntersectionResultArray xsects = null;

            if (geo is Face)
            {
                face = geo as Face;
            }
            else if (geo is Autodesk.Revit.DB.Plane)
            {
                #region plane processing

                thisPlane = geo as Autodesk.Revit.DB.Plane;

                face = buildFaceOnPlaneByCurveExtensions(crv, thisPlane);

                #endregion
            }

            var result = face.Intersect(crv, out xsects);

            //var xsect_results = FSharpList<Value>.Empty;
            var xsect_xyzs        = FSharpList <Value> .Empty;
            var xsect_face_uvs    = FSharpList <Value> .Empty;
            var xsect_params      = FSharpList <Value> .Empty;
            var xsect_edges       = FSharpList <Value> .Empty;
            var xsect_edge_params = FSharpList <Value> .Empty;

            var results = FSharpList <Value> .Empty;
            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    var xsect = FSharpList <Value> .Empty;
                    try
                    {
                        xsect_edge_params = FSharpList <Value> .Cons(Value.NewNumber(ir.EdgeParameter), xsect_edge_params);
                    }
                    catch
                    {
                        xsect_edge_params = FSharpList <Value> .Cons(Value.NewNumber(0), xsect_edge_params);
                    }
                    xsect_edges = FSharpList <Value> .Cons(Value.NewContainer(ir.EdgeObject), xsect_edges);

                    xsect_params = FSharpList <Value> .Cons(Value.NewNumber(ir.Parameter), xsect_params);

                    if (thisPlane != null)
                    {
                        UV planeUV = new UV(thisPlane.XVec.DotProduct(ir.XYZPoint - thisPlane.Origin),
                                            thisPlane.YVec.DotProduct(ir.XYZPoint - thisPlane.Origin));
                        xsect_face_uvs = FSharpList <Value> .Cons(Value.NewContainer(planeUV), xsect_face_uvs);
                    }
                    else
                    {
                        xsect_face_uvs = FSharpList <Value> .Cons(Value.NewContainer(ir.UVPoint), xsect_face_uvs);
                    }

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

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

            outPuts[_edgeTPort]  = Value.NewList(xsect_edge_params);
            outPuts[_edgePort]   = Value.NewList(xsect_edges);
            outPuts[_tPort]      = Value.NewList(xsect_params);
            outPuts[_uvPort]     = Value.NewList(xsect_face_uvs);
            outPuts[_xyzPort]    = Value.NewList(xsect_xyzs);
            outPuts[_resultPort] = Value.NewString(result.ToString());
        }