Exemplo n.º 1
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var input = args[0];
            var xi = ((Value.Number)args[1]).Item;// Number
            var x0 = ((Value.Number)args[2]).Item;// Starting Coord
            var xs = (SpacingRuleLayout)((Value.Container)args[3]).Item; // Spacing

            Autodesk.Revit.DB.DividedPath divPath;
            var refList = new List<Reference>();

            refList.Clear();

            var c = (CurveElement)((Value.Container)input).Item;

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

            Curve crvRef = c.GeometryCurve;

            refList.Add(crvRef.Reference);

            if (this.Elements.Any())
            {
                if (dynUtils.TryGetElement(this.Elements[0], out divPath))
                {
                    SetSpacing(divPath, xi, xs);
                }
                else
                {
                    divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                    SetSpacing(divPath, xi, xs);
                    this.Elements[0] = divPath.Id;
                }
            }
            else
            {
                divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                SetSpacing(divPath, xi, xs);
                this.Elements.Add(divPath.Id);
            }
            refList.Clear();

            return Value.NewContainer(divPath);
        }
Exemplo n.º 2
0
        internal void RegisterDeleteHook(Autodesk.Revit.DB.ElementId id, DynElementUpdateDelegate d)
        {
            DynElementUpdateDelegate del = delegate(List<Autodesk.Revit.DB.ElementId> deleted)
            {
                var valid = new List<Autodesk.Revit.DB.ElementId>();
                var invalid = new List<Autodesk.Revit.DB.ElementId>();
                foreach (var delId in deleted)
                {
                    try
                    {
                        Autodesk.Revit.DB.Element e = dynRevitSettings.Doc.Document.GetElement(delId);
                        if (e != null)
                        {
                            valid.Add(e.Id);
                        }
                        else
                            invalid.Add(delId);
                    }
                    catch
                    {
                        invalid.Add(delId);
                    }
                }
                valid.Clear();
                d(invalid);
                foreach (var invId in invalid)
                {
                    this.Updater.UnRegisterChangeHook(invId, ChangeTypeEnum.Modify);
                    this.Updater.UnRegisterChangeHook(invId, ChangeTypeEnum.Add);
                    this.Updater.UnRegisterChangeHook(invId, ChangeTypeEnum.Delete);
                }
            };

            DynElementUpdateDelegate mod = delegate(List<Autodesk.Revit.DB.ElementId> modded)
            {
                _transElements.RemoveAll(modded.Contains);

                foreach (var mid in modded)
                {
                    this.Updater.UnRegisterChangeHook(mid, ChangeTypeEnum.Modify);
                    this.Updater.UnRegisterChangeHook(mid, ChangeTypeEnum.Add);
                }
            };

            this.Updater.RegisterChangeHook(
               id, ChangeTypeEnum.Delete, del
            );
            this.Updater.RegisterChangeHook(
               id, ChangeTypeEnum.Modify, mod
            );
            this.Updater.RegisterChangeHook(
               id, ChangeTypeEnum.Add, mod
            );
            this._transElements.Add(id);
        }
Exemplo n.º 3
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var input = args[0];
            double xi;//, x0, xs;
            xi = ((Value.Number)args[1]).Item;// Number
            //x0 = ((Value.Number)args[2]).Item;// Starting Coord
            //xs = ((Value.Number)args[3]).Item;// Spacing

            DividedSurface divSurf;
            List<Reference> refList = new List<Reference>();

            // this node can take one or more face refs and create one or more divided surface elements

            //if (input.IsList)
            //{
            //    refList.Clear();

            //    var curveList = (input as Value.List).Item;

            //    //Counter to keep track of how many references and divided path. We'll use this to delete old
            //    //elements later.
            //    int count = 0;

            //    //We create our output by...
            //    var result = Utils.convertSequence(
            //       curveList.Select(
            //        //..taking each curve in the list and...
            //          delegate(Value x)
            //          {
            //              Reference r;
            //              CurveElement c;

            //              //...check to see if we already have a divided node made by this curve in a previous run
            //              if (this.Elements.Count > count)
            //              {
            //                  Element e;

            //                  //...we attempt to fetch it from the document...
            //                  if (dynUtils.TryGetElement(this.Elements[count], out e))
            //                  {
            //                      //...if we find a divided path and if we're successful matching it to the doc, update it's properties...
            //                      divPath = e as DividedPath;

            //                      if (divPath != null)
            //                      {
            //                          divPath.FixedNumberOfPoints = (int)xi;

            //                      }
            //                      else
            //                      {
            //                          //...otherwise, we can make a new divided path and replace it in the list of
            //                          //previously created divided paths.
            //                          //...we extract a curve element from the container.
            //                          c = (CurveElement)((Value.Container)x).Item;
            //                          //...we create a new curve ref
            //                          Curve crvRef = c.GeometryCurve;
            //                          refList.Add(crvRef.Reference);
            //                          divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
            //                          divPath.FixedNumberOfPoints = (int)xi;
            //                          this.Elements[count] = divPath.Id;
            //                          refList.Clear();

            //                      }
            //                  }
            //                  else
            //                  {
            //                      //...otherwise, we can make a new divided path and replace it in the list of
            //                      //previously created divided paths.
            //                      //...we extract a curve element from the container.
            //                      c = (CurveElement)((Value.Container)x).Item;
            //                      //...we create a new curve ref
            //                      Curve crvRef = c.GeometryCurve;
            //                      refList.Add(crvRef.Reference);
            //                      divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
            //                      divPath.FixedNumberOfPoints = (int)xi;
            //                      this.Elements[count] = divPath.Id;
            //                      refList.Clear();
            //                  }

            //              }
            //              //...otherwise...
            //              else
            //              {
            //                  //...we extract a curve element from the container.
            //                  c = (CurveElement)((Value.Container)x).Item;
            //                  //...we create a new curve ref
            //                  Curve crvRef = c.GeometryCurve;
            //                  refList.Add(crvRef.Reference);
            //                  divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
            //                  divPath.FixedNumberOfPoints = (int)xi;
            //                  //...and store the element in the element list for future runs.
            //                  this.Elements.Add(divPath.Id);
            //                  refList.Clear();
            //              }
            //              //Finally, we update the counter, and return a new Value containing the reference list.

            //              count++;
            //              return Value.NewContainer(divPath);
            //          }
            //       )
            //    );

            //    //Now that we've added all the divided paths from this run, we delete all of the
            //    //extra ones from the previous run.
            //    foreach (var eid in this.Elements.Skip(count))
            //    {

            //        this.DeleteElement(eid); // remove unused divided paths
            //    }

            //    return Value.NewList(result);
            //}

            ////If we're not receiving a list, we will just assume we received one curve.
            //else
            //{
                refList.Clear();

                Reference r = (Reference)((Value.Container)input).Item;

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

                refList.Add(r);

                //If we've made any elements previously...
                if (this.Elements.Any())
                {
                    Element e;
                    //...try to get the first one...
                    if (dynUtils.TryGetElement(this.Elements[0], out e))
                    {
                        //..and if we do, update it's data.
                        divSurf = e as DividedSurface;
                        //divSurf. = (int)xi;
                    }
                    else
                    {
                        //...otherwise, just make a new one and replace it in the list.

                        divSurf = this.UIDocument.Document.FamilyCreate.NewDividedSurface(r);

                        //divSurf.FixedNumberOfPoints = (int)xi;
                        this.Elements[0] = divSurf.Id;
                    }

                    //We still delete all extra elements, since in the previous run we might have received a list.
                    foreach (var el in this.Elements.Skip(1))
                    {
                        this.DeleteElement(el);
                    }
                }
                //...otherwise...
                else
                {
                    //...just make a divided curve and store it.
                    divSurf = this.UIDocument.Document.FamilyCreate.NewDividedSurface(r);
                    //divSurf.FixedNumberOfPoints = (int)xi;
                    this.Elements.Add(divSurf.Id);
                }
                refList.Clear();

                //Fin
                return Value.NewContainer(divSurf);
        }
Exemplo n.º 4
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var input = args[0];
            double xi;//, x0, xs;
            xi = ((Value.Number)args[1]).Item;// Number
            //x0 = ((Value.Number)args[2]).Item;// Starting Coord
            //xs = ((Value.Number)args[3]).Item;// Spacing

            DividedPath divPath;
            List<Reference> refList = new List<Reference>();

            // this node can take one or more curve elements and create one or more divided path elements
            // input is one or more user-selected curves for now
            // todo: - create a utility function that can handle curve loops and convert them into lists, perhaps makes this a node or just an allowed input of this node
            //       - enhance curve by selection node to handle multiple picks
            //       - allow selection of a family instance to extract a curve loop or reference list
            //
            // process input curve elements
            // - if we pass in a single curve element, we will extract it's reference and pass that into the divided path creation method
            // - if we pass in a collection of curve elements, we want to make a divided path for each curve from that collection
            //    for each curve element in list,
            //      manage curve list (determine whether we already had used that curve before to make this divided path, add new curves, remove old curves)
            //      extract curve refs for each curve element and create divided path
            //      update params of for the div path
            //  this.Elements should only hold divided paths not curves.
            // node should return a list of divided paths

            if (input.IsList)
            {
                refList.Clear();

                var curveList = (input as Value.List).Item;

                //Counter to keep track of how many references and divided path. We'll use this to delete old
                //elements later.
                int count = 0;

                //We create our output by...
                var result = Utils.SequenceToFSharpList(
                   curveList.Select(
                    //..taking each curve in the list and...
                      delegate(Value x)
                      {
                          //Reference r;
                          CurveElement c;

                          //...check to see if we already have a divided node made by this curve in a previous run
                          if (this.Elements.Count > count)
                          {
                              Element e;

                              //...we attempt to fetch it from the document...
                              if (dynUtils.TryGetElement(this.Elements[count], out e))
                              {
                                  //...if we find a divided path and if we're successful matching it to the doc, update it's properties...
                                  divPath = e as DividedPath;

                                  if (divPath != null)
                                  {
                                      divPath.FixedNumberOfPoints = (int)xi;

                                  }
                                  else
                                  {
                                      //...otherwise, we can make a new divided path and replace it in the list of
                                      //previously created divided paths.
                                      //...we extract a curve element from the container.
                                      c = (CurveElement)((Value.Container)x).Item;
                                      //...we create a new curve ref
                                      Curve crvRef = c.GeometryCurve;
                                      refList.Add(crvRef.Reference);
                                      divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                                      divPath.FixedNumberOfPoints = (int)xi;
                                      this.Elements[count] = divPath.Id;
                                      refList.Clear();

                                  }
                              }
                              else
                              {
                                  //...otherwise, we can make a new divided path and replace it in the list of
                                  //previously created divided paths.
                                  //...we extract a curve element from the container.
                                  c = (CurveElement)((Value.Container)x).Item;
                                  //...we create a new curve ref
                                  Curve crvRef = c.GeometryCurve;
                                  refList.Add(crvRef.Reference);
                                  divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                                  divPath.FixedNumberOfPoints = (int)xi;
                                  this.Elements[count] = divPath.Id;
                                  refList.Clear();
                              }

                          }
                          //...otherwise...
                          else
                          {
                              //...we extract a curve element from the container.
                              c = (CurveElement)((Value.Container)x).Item;
                              //...we create a new curve ref
                              Curve crvRef = c.GeometryCurve;
                              refList.Add(crvRef.Reference);
                              divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                              divPath.FixedNumberOfPoints = (int)xi;
                              //...and store the element in the element list for future runs.
                              this.Elements.Add(divPath.Id);
                              refList.Clear();
                          }
                          //Finally, we update the counter, and return a new Value containing the reference list.

                          count++;
                          return Value.NewContainer(divPath);
                      }
                   )
                );

                //Now that we've added all the divided paths from this run, we delete all of the
                //extra ones from the previous run.
                foreach (var eid in this.Elements.Skip(count))
                {

                    this.DeleteElement(eid); // remove unused divided paths
                }

                return Value.NewList(result);
            }

            //If we're not receiving a list, we will just assume we received one curve.
            else
            {
                refList.Clear();

                CurveElement c = (CurveElement)((Value.Container)input).Item;

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

                //double x = x0;
                Curve crvRef = c.GeometryCurve;

                refList.Add(crvRef.Reference);

                //If we've made any elements previously...
                if (this.Elements.Any())
                {
                    Element e;
                    //...try to get the first one...
                    if (dynUtils.TryGetElement(this.Elements[0], out e))
                    {
                        //..and if we do, update it's data.
                        divPath = e as DividedPath;
                        divPath.FixedNumberOfPoints = (int)xi;
                    }
                    else
                    {
                        //...otherwise, just make a new one and replace it in the list.
                        divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                        divPath.FixedNumberOfPoints = (int)xi;
                        this.Elements[0] = divPath.Id;
                    }

                    //We still delete all extra elements, since in the previous run we might have received a list.
                    foreach (var el in this.Elements.Skip(1))
                    {
                        this.DeleteElement(el);
                    }
                }
                //...otherwise...
                else
                {
                    //...just make a divided curve and store it.
                    divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                    divPath.FixedNumberOfPoints = (int)xi;
                    this.Elements.Add(divPath.Id);
                }
                refList.Clear();

                //Fin
                return Value.NewContainer(divPath);
            }
        }
Exemplo n.º 5
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            SpatialFieldManager sfm = ((Value.Container)args[2]).Item as SpatialFieldManager;

            // Place analysis results in the form of vectors at each of a beam or column's analytical model curve
            Curve curve = ((Value.Container)args[3]).Item as Curve;

            int index = sfm.AddSpatialFieldPrimitive(curve, Transform.Identity);

            IList<double> doubleList = new List<double>();
            doubleList.Add(curve.get_EndParameter(0)); // vectors will be at each end of the analytical model curve
            doubleList.Add(curve.get_EndParameter(1));
            FieldDomainPointsByParameter pointsByParameter = new FieldDomainPointsByParameter(doubleList);

            List<XYZ> xyzList = new List<XYZ>();
            xyzList.Add(curve.ComputeDerivatives(0, true).BasisX.Normalize()); // vectors will be tangent to the curve at its ends
            IList<VectorAtPoint> vectorList = new List<VectorAtPoint>();
            vectorList.Add(new VectorAtPoint(xyzList));
            xyzList.Clear();
            xyzList.Add(curve.ComputeDerivatives(1, true).BasisX.Normalize().Negate());
            vectorList.Add(new VectorAtPoint(xyzList));
            FieldDomainPointsByXYZ feildPoints = new FieldDomainPointsByXYZ(xyzList);
            FieldValues fieldValues = new FieldValues(vectorList);
            int n = 0;
            sfm.UpdateSpatialFieldPrimitive(index, feildPoints, fieldValues, n);

            /*
            //first, cleanup the old one
            if (idx != -1)
            {
                sfm.RemoveSpatialFieldPrimitive(idx);
            }

            Reference reference = ((Value.Container)args[3]).Item as Reference;
            idx = sfm.AddSpatialFieldPrimitive(reference);

            Face face = dynRevitSettings.Doc.Document.GetElement(reference).GetGeometryObjectFromReference(reference) as Face;

            //unwrap the sample locations
            IEnumerable<UV> pts = ((Value.List)args[1]).Item.Select(
               x => (UV)((Value.Container)x).Item
            );
            FieldDomainPointsByUV sample_pts = new FieldDomainPointsByUV(pts.ToList<UV>());

            //unwrap the values
            IEnumerable<double> nvals = ((Value.List)args[0]).Item.Select(
               x => (double)((Value.Number)x).Item
            );

            //for every sample location add a list
            //of valueatpoint objets. for now, we only
            //support one value per point
            IList<ValueAtPoint> valList = new List<ValueAtPoint>();
            foreach (var n in nvals)
            {
                valList.Add(new ValueAtPoint(new List<double> { n }));
            }
            FieldValues sample_values = new FieldValues(valList);

            int schemaIndex = 0;
            if (!sfm.IsResultSchemaNameUnique(DYNAMO_ANALYSIS_RESULTS_NAME, -1))
            {
                IList<int> arses = sfm.GetRegisteredResults();
                foreach (int i in arses)
                {
                    AnalysisResultSchema arsTest = sfm.GetResultSchema(i);
                    if (arsTest.Name == DYNAMO_ANALYSIS_RESULTS_NAME)
                    {
                        schemaIndex = i;
                        break;
                    }
                }
            }
            else
            {
                AnalysisResultSchema ars = new AnalysisResultSchema(DYNAMO_ANALYSIS_RESULTS_NAME, "Resulting analyses from Dynamo.");
                schemaIndex = sfm.RegisterResult(ars);
            }

            sfm.UpdateSpatialFieldPrimitive(idx, sample_pts, sample_values, schemaIndex);
            */

            return Value.NewContainer(idx);
        }