public override Value Evaluate(FSharpList<Value> args) { Value result = PythonEngine.Evaluator(_dirty, _script, MakeBindings(args)); _lastEvalValue = result; Draw(); return result; }
private void DrawContainers(Value val, RenderDescription rd) { if (val.IsList) { foreach (Value v in ((Value.List)val).Item) { DrawContainers(v, rd); } } if (val.IsContainer) { var drawable = ((Value.Container)val).Item; if(drawable is XYZ) { dynRevitTransactionNode.DrawXYZ(rd, (XYZ)drawable); } else { dynRevitTransactionNode.DrawGeometryObject(rd, (GeometryObject)drawable); } } }
private static Value setParam(Element fi, Definition paramDef, Value valueExpr) { var p = fi.get_Parameter(paramDef); if (p != null) { return _setParam(fi, p, valueExpr); } throw new Exception("Parameter \"" + paramDef.Name + "\" was not found!"); }
WatchNode Process(Value eIn, string prefix, int count, bool isListMember = false) { //content += prefix + string.Format("[{0}]:", count.ToString()); WatchNode node = null; if (eIn == null || eIn.IsDummy) { node = new WatchNode("null"); return node; } if (eIn.IsContainer) { if ((eIn as Value.Container).Item != null) { //content += (eIn as Value.Container).Item.ToString(); node = new WatchNode((eIn as Value.Container).Item.ToString(), isListMember, count); handlerManager.ProcessNode((eIn as Value.Container).Item, node); //node.Link = id; } } else if (eIn.IsFunction) { //content += eIn.ToString() + "\n"; node = new WatchNode("<function>", isListMember, count); } else if (eIn.IsList) { //content += "List\n"; string newPrefix = prefix + "\t"; var list = (eIn as Value.List).Item; node = new WatchNode(list.IsEmpty ? "Empty List" : "List", isListMember, count); foreach (var e in list.Select((x, i) => new { Element = x, Index = i })) { node.Children.Add( Process(e.Element, newPrefix, e.Index, true) ); } } else if (eIn.IsNumber) { //content += (eIn as Value.Number).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Number).Item.ToString(), isListMember, count); } else if (eIn.IsString) { //content += (eIn as Value.String).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.String).Item.ToString(), isListMember, count); } else if (eIn.IsSymbol) { //content += (eIn as Value.Symbol).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Symbol).Item.ToString(), isListMember, count); } return node; }
public override Value Evaluate(FSharpList<Value> args) { if (!args[0].IsList) { throw new Exception("Input must be a list of numbers."); } FSharpList<Value> vals = ((Value.List)args[0]).Item; var len = vals.Length; if (len % 3 != 0) throw new Exception("List size must be a multiple of 3"); var result = new Value[len / 3]; int count = 0; while (!vals.IsEmpty) { result[count] = Value.NewContainer(new XYZ( ((Value.Number)vals.Head).Item, ((Value.Number)vals.Tail.Head).Item, ((Value.Number)vals.Tail.Tail.Head).Item)); vals = vals.Tail.Tail.Tail; count++; } return Value.NewList(Utils.SequenceToFSharpList(result)); }
/// <summary> /// A better ToString() for Values. /// </summary> /// <param name="v"></param> /// <returns></returns> public static string Print(this Value v) { return(v.IsString ? (v as Value.String).Item : FScheme.print(v)); }
private Value evalIfDirty(FSharpList<Value> args) { if (!SaveResult || RequiresRecalc || oldValue == null) { //Evaluate arguments, then evaluate oldValue = evaluateNode(args); } else OnEvaluate(); return oldValue; }
void registerButt_Click(object sender, System.Windows.RoutedEventArgs e) { //data = Value.NewList(FSharpList<Value>.Empty); View activeView = dynRevitSettings.Doc.ActiveView; PickedSunAndShadowSettings = activeView.SunAndShadowSettings; if (PickedSunAndShadowSettings != null) { sunAndShadowSettingsID = activeView.SunAndShadowSettings.Id; this.RegisterEvalOnModified(sunAndShadowSettingsID); // register with the DMU, TODO - watch out for view changes, as sun is view specific XYZ sunVector = GetSunDirection(PickedSunAndShadowSettings); this.data = Value.NewContainer(sunVector); this.tb.Text = PickedSunAndShadowSettings.Name; } else { //sunPathButt.Content = "Select Instance"; this.tb.Text = "Nothing Selected"; } }
WatchNode Process(Value eIn, string prefix, int count, bool isListMember = false) { //content += prefix + string.Format("[{0}]:", count.ToString()); WatchNode node = null; if (eIn == null || eIn.IsDummy) { node = new WatchNode("null"); return(node); } if (eIn.IsContainer) { if ((eIn as Value.Container).Item != null) { //content += (eIn as Value.Container).Item.ToString(); node = new WatchNode((eIn as Value.Container).Item.ToString(), isListMember, count); handlerManager.ProcessNode((eIn as Value.Container).Item, node); //node.Link = id; } } else if (eIn.IsFunction) { //content += eIn.ToString() + "\n"; node = new WatchNode("<function>", isListMember, count); } else if (eIn.IsList) { //content += "List\n"; string newPrefix = prefix + "\t"; var list = (eIn as Value.List).Item; node = new WatchNode(list.IsEmpty ? "Empty List" : "List", isListMember, count); foreach (var e in list.Select((x, i) => new { Element = x, Index = i })) { node.Children.Add(Process(e.Element, newPrefix, e.Index, true)); } } else if (eIn.IsNumber) { //content += (eIn as Value.Number).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Number).Item.ToString(), isListMember, count); } else if (eIn.IsString) { //content += (eIn as Value.String).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.String).Item.ToString(), isListMember, count); } else if (eIn.IsSymbol) { //content += (eIn as Value.Symbol).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Symbol).Item.ToString(), isListMember, count); } return(node); }
public override Value Evaluate(FSharpList <Value> args) { var curves = ((Value.List)args[0]).Item.Select( x => ((Curve)((Value.Container)x).Item)).ToList(); List <Curve> curvesWithFlip = new List <Curve>(); bool bStart = true; XYZ prevEnd = new XYZ(); double tolMax = 0.0001; double tolMin = 0.00001; foreach (Curve c in curves) { if (!bStart) { XYZ thisEnd = c.Evaluate(1.0, true); XYZ thisStart = c.Evaluate(0.0, true); double thisDist = thisStart.DistanceTo(prevEnd); if (thisDist > tolMax && thisEnd.DistanceTo(prevEnd) < tolMin && (c is Line)) { prevEnd = thisStart; Curve flippedCurve = /* Line.CreateBound */ dynRevitSettings.Revit.Application.Create.NewLineBound(thisEnd, thisStart); curvesWithFlip.Add(flippedCurve); continue; } } else { bStart = false; prevEnd = c.Evaluate(1.0, true); if (curves.Count > 1) { XYZ nextStart = curves[1].Evaluate(0.0, true); double thisDist = prevEnd.DistanceTo(nextStart); if (thisDist > tolMax) { XYZ nextEnd = curves[1].Evaluate(1.0, true); if (nextEnd.DistanceTo(prevEnd) > tolMax) { XYZ thisStart = c.Evaluate(0.0, true); if (thisStart.DistanceTo(nextEnd) < tolMin || thisStart.DistanceTo(nextStart) < tolMin) { if (c is Line) { Curve flippedCurve = /* Line.CreateBound */ dynRevitSettings.Revit.Application.Create.NewLineBound(prevEnd, thisStart); prevEnd = thisStart; curvesWithFlip.Add(flippedCurve); continue; } } } } } } prevEnd = c.Evaluate(1.0, true); curvesWithFlip.Add(c); } Autodesk.Revit.DB.CurveLoop result = Autodesk.Revit.DB.CurveLoop.Create(curvesWithFlip); return(Value.NewContainer(result)); }
private Value extractCurve(object c, int count) { Curve curve = ((CurveElement)c).GeometryCurve; return(Value.NewContainer(curve)); }
public override Value Evaluate(FSharpList <Value> args) { //Our eventual output. Autodesk.Revit.DB.CurveByPoints c = null; var input = args[0]; Curve gc = (Curve)((Value.Container)args[0]).Item; XYZ start = gc.get_EndPoint(0); XYZ end = gc.get_EndPoint(1); //If we've made any elements previously... if (this.Elements.Any()) { bool replaceElement = true; //...try to get the first one... if (dynUtils.TryGetElement(this.Elements[0], out c)) { //..and if we do, update it's position. ReferencePointArray existingPts = c.GetPoints(); //update the points on the curve to match if (gc.GetType() == typeof(Line) && existingPts.Size == 2) { existingPts.get_Item(0).Position = start; existingPts.get_Item(1).Position = end; replaceElement = false; } // NOTE: there is no way I found in REVITAPI to tell if existing curve by points is arc else if (gc.GetType() == typeof(Arc) && existingPts.Size == 3) { if (existingPts.Size != 3) { var newPts = new ReferencePointArray(); newPts.Append(existingPts.get_Item(0)); if (existingPts.Size < 3) { newPts.Append(this.UIDocument.Document.FamilyCreate.NewReferencePoint(gc.Evaluate(0.5, true))); } else { newPts.Append(existingPts.get_Item(1)); } newPts.Append(existingPts.get_Item(existingPts.Size - 1)); c.SetPoints(newPts); existingPts = c.GetPoints(); } existingPts.get_Item(0).Position = start; existingPts.get_Item(2).Position = end; existingPts.get_Item(1).Position = gc.Evaluate(0.5, true); replaceElement = false; } else if (gc.GetType() != typeof(Arc)) { int nPoints = existingPts.Size; IList <XYZ> xyzList = gc.Tessellate(); int numPoints = xyzList.Count; if (nPoints != numPoints) { var newPts = new ReferencePointArray(); newPts.Append(existingPts.get_Item(0)); newPts.get_Item(0).Position = xyzList[0]; for (int iPoint = 1; iPoint < numPoints; iPoint++) { if (iPoint == numPoints - 1) { newPts.Append(existingPts.get_Item(nPoints - 1)); newPts.get_Item(iPoint).Position = xyzList[iPoint]; } else if (iPoint < nPoints - 1) { newPts.Append(existingPts.get_Item(iPoint)); newPts.get_Item(iPoint).Position = xyzList[iPoint]; } else { newPts.Append(this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyzList[iPoint])); } } if (nPoints > numPoints) { //have to delete as API call to SetPoints leaves points in the doc for (int iPoint = numPoints - 1; iPoint < nPoints - 1; iPoint++) { this.DeleteElement(existingPts.get_Item(iPoint).Id); } } c.SetPoints(newPts); existingPts = c.GetPoints(); } else { for (int iPoint = 0; iPoint < numPoints; iPoint++) { if (iPoint == 0) { existingPts.get_Item(iPoint).Position = start; } else if (iPoint == nPoints - 1) { existingPts.get_Item(iPoint).Position = end; } else { existingPts.get_Item(iPoint).Position = xyzList[iPoint]; } } } replaceElement = false; } if (replaceElement) { IList <XYZ> xyzList = gc.Tessellate(); int numPoint = xyzList.Count; double step = 1.0 / (numPoint - 1.0); double tolerance = 0.0000001; replaceElement = false; for (int index = 0; index < numPoint; index++) { IntersectionResult projXYZ = c.GeometryCurve.Project(xyzList[index]); if (projXYZ.XYZPoint.DistanceTo(xyzList[index]) > tolerance) { replaceElement = true; break; } } } } if (replaceElement) { this.DeleteElement(this.Elements[0]); ReferencePointArray existingPts = c.GetPoints(); c = null; c = CreateCurveByPoints(c, gc, start, end); this.Elements[0] = c.Id; } } else { c = CreateCurveByPoints(c, gc, start, end); this.Elements.Add(c.Id); } return(Value.NewContainer(c)); }
public override Value Evaluate(FSharpList <Value> args) { var transform = (Transform)((Value.Container)args[0]).Item; return(Value.NewContainer(transform.Origin)); }
public override Value Evaluate(FSharpList <Value> args) { Transform t = Transform.Identity; return(Value.NewContainer(t)); }
public override Value Evaluate(FSharpList<Value> args) { Value result = PythonEngine.Evaluator(dirty, script, makeBindings(args)); lastEvalValue = result; return result; }
/// <summary> /// Convert an input Value into and expected type if possible. /// Ex. If a node expects an XYZ, a user can pass in a ReferencePoint object /// and the position (XYZ) of that object will be returned. /// </summary> /// <param name="input">The value of the input.</param> /// <param name="output">The desired output type.</param> /// <returns></returns> public static object ConvertInput(Value input, Type output) { if (input.IsContainer) { object item = ((Value.Container)input).Item; #region ModelCurve if (item.GetType() == typeof(ModelCurve)) { ModelCurve a = (ModelCurve)item; if (output == typeof(Curve)) { return ((ModelCurve)item).GeometryCurve; } } #endregion #region SketchPlane else if (item.GetType() == typeof(SketchPlane)) { SketchPlane a = (SketchPlane)item; if (output == typeof(Plane)) { return a.Plane; } else if (output == typeof(ReferencePlane)) { return a.Plane; } else if (output == typeof(string)) { return string.Format("{0},{1},{2},{3},{4},{5}", a.Plane.Origin.X, a.Plane.Origin.Y, a.Plane.Origin.Z, a.Plane.Normal.X, a.Plane.Normal.Y, a.Plane.Normal.Z); } } #endregion #region Point else if (item.GetType() == typeof(Point)) { Point a = (Point)item; if (output == typeof(XYZ)) { return a.Coord; } else if (output == typeof(string)) { return string.Format("{0},{1},{2}", a.Coord.X, a.Coord.Y, a.Coord.Z); } } #endregion #region ReferencePoint else if (item.GetType() == typeof(ReferencePoint)) { ReferencePoint a = (ReferencePoint)item; if (output == typeof(XYZ)) { return a.Position; } else if (output == typeof(Reference)) { return a.GetCoordinatePlaneReferenceXY(); } else if (output == typeof(Transform)) { return a.GetCoordinateSystem(); } else if (output == typeof(string)) { return string.Format("{0},{1},{2}", a.Position.X, a.Position.Y, a.Position.Z); } else if (output == typeof(ElementId)) { return a.Id; } } #endregion #region ElementId else if (item.GetType() == typeof(ElementId)) { if (output == typeof(ReferencePoint)) { ElementId a = (ElementId)item; Element el = dynRevitSettings.Doc.Document.GetElement(a); ReferencePoint rp = (ReferencePoint)el; return rp; } } #endregion #region Reference else if (item.GetType() == typeof(Reference)) { Reference a = (Reference)item; if(output.IsAssignableFrom(typeof(Element))) { Element e = dynRevitSettings.Doc.Document.GetElement(a); } else if (output == typeof(Face)) { Face f = (Face)dynRevitSettings.Doc.Document.GetElement(a.ElementId).GetGeometryObjectFromReference(a); return f; } } #endregion #region XYZ if (item.GetType() == typeof(XYZ)) { XYZ a = (XYZ)item; if (output == typeof(Transform)) { Transform t = Transform.get_Translation(a); return t; } } #endregion return item; } else if (input.IsNumber) { double a = (double)((Value.Number)input).Item; if (output == typeof(bool)) { return Convert.ToBoolean(a); } else if (output == typeof(Int32)) { return Convert.ToInt32(a); } return a; } else if(input.IsString) { string a = ((Value.String)input).Item.ToString(); return a; } else if (input.IsList) { FSharpList<Value> a = ((Value.List)input).Item; if (output == typeof(ReferenceArrayArray)) { return DynamoTypeConverter.ConvertFSharpListListToReferenceArrayArray(a); } else if (output == typeof(ReferenceArray)) { return DynamoTypeConverter.ConvertFSharpListListToReferenceArray(a); } else if (output == typeof(CurveArrArray)) { return DynamoTypeConverter.ConvertFSharpListListToCurveArray(a); } else if (output == typeof(CurveArray)) { return DynamoTypeConverter.ConvertFSharpListListToCurveArray(a); } return a; } //return the input by default return input; }
public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts) { _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 _useRl = 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(); } outPuts[_psPort] = Value.NewContainer(ParticleSystem); outPuts[_forcesPort] = Value.NewList(Utils.SequenceToFSharpList( ParticleSystem.Springs.Select(s => Value.NewNumber(s.getResidualForce())))); }
public override Value Evaluate(FSharpList<Value> args) { var result = new List<List<FamilyInstance>>(); //"Get an interface to the divided surfaces on this element." //TODO: do we want to select a face instead and try to get //the divided surface that way? DividedSurfaceData dsd = SelectedElement.GetDividedSurfaceData(); if(dsd == null) throw new Exception("The selected form has no divided surface data."); foreach (Reference r in dsd.GetReferencesWithDividedSurfaces()) { Autodesk.Revit.DB.DividedSurface ds = dsd.GetDividedSurfaceForReference(r); var gn = new GridNode(); int u = 0; while (u < ds.NumberOfUGridlines) { var lst = new List<FamilyInstance>(); gn.UIndex = u; int v = 0; while (v < ds.NumberOfVGridlines) { gn.VIndex = v; //"Reports whether a grid node is a "seed node," a node that is associated with one or more tiles." if (ds.IsSeedNode(gn)) { FamilyInstance fi = ds.GetTileFamilyInstance(gn, 0); //put the family instance into the tree lst.Add(fi); } v = v + 1; } //don't add list if it's empty if (lst.Any()) result.Add(lst); u = u + 1; } } _data = Value.NewList( Utils.SequenceToFSharpList( result.Select( row => Value.NewList( Utils.SequenceToFSharpList( row.Select(Value.NewContainer)))))); return _data; }
public override Value Evaluate(FSharpList <Value> args) { double parameter = ((Value.Number)args[0]).Item; Curve thisCurve = null; Edge thisEdge = null; if (((Value.Container)args[1]).Item is Curve) { thisCurve = ((Value.Container)args[1]).Item as Curve; } else if (((Value.Container)args[1]).Item is Edge) { thisEdge = ((Value.Container)args[1]).Item as Edge; } else if (((Value.Container)args[1]).Item is Reference) { Reference r = (Reference)((Value.Container)args[1]).Item; if (r != null) { Element refElem = dynRevitSettings.Doc.Document.GetElement(r.ElementId); if (refElem != null) { GeometryObject geob = refElem.GetGeometryObjectFromReference(r); thisEdge = geob as Edge; if (thisEdge == null) { thisCurve = geob as Curve; } } else { throw new Exception("Could not accept second in-port for Evaluate curve or edge node"); } } } else if (((Value.Container)args[1]).Item is CurveElement) { CurveElement cElem = ((Value.Container)args[1]).Item as CurveElement; if (cElem != null) { thisCurve = cElem.GeometryCurve; } else { throw new Exception("Could not accept second in-port for Evaluate curve or edge node"); } } else { throw new Exception("Could not accept second in-port for Evaluate curve or edge node"); } XYZ result = (thisCurve != null) ? (!curveIsReallyUnbound(thisCurve) ? thisCurve.Evaluate(parameter, true) : thisCurve.Evaluate(parameter, false)) : (thisEdge == null ? null : thisEdge.Evaluate(parameter)); pts.Add(result); return(Value.NewContainer(result)); }
public static string PrintValue(Value eIn, int currentListIndex, int maxListIndex, int currentDepth, int maxDepth, int maxStringLength = 20) { if (eIn == null) return "<null>"; string accString = String.Concat(Enumerable.Repeat(" ", currentDepth)); if (maxDepth == currentDepth || currentListIndex == maxListIndex) { accString += "..."; return accString; } if (eIn.IsContainer) { var str = (eIn as Value.Container).Item != null ? (eIn as Value.Container).Item.ToString() : "<empty>"; accString += str; } else if (eIn.IsFunction) { accString += "<function>"; } else if (eIn.IsList) { accString += "List"; var list = (eIn as Value.List).Item; if (!list.Any()) { accString += " (empty)"; } // when children will be at maxDepth, just do 1 if (currentDepth + 1 == maxDepth) { maxListIndex = 0; } // build all elements of sub list accString = list.Select((x, i) => new { Element = x, Index = i }) .TakeWhile(e => e.Index <= maxListIndex) .Aggregate( accString, (current, e) => current + "\n" + PrintValue(e.Element, e.Index, maxListIndex, currentDepth + 1, maxDepth, maxStringLength)); } else if (eIn.IsNumber) { var num = (eIn as Value.Number).Item; var numFloat = (float) num; accString += numFloat.ToString(); } else if (eIn.IsString) { var str = (eIn as Value.String).Item; if (str.Length > maxStringLength) { str = str.Substring(0, maxStringLength) + "..."; } accString += "\"" + str + "\""; } else if (eIn.IsSymbol) { accString += "<" + (eIn as Value.Symbol).Item + ">"; } return accString; }
public override Value Evaluate(FSharpList <Value> args) { var symbol = (FamilySymbol)((Value.Container)args[0]).Item; var curves = ((Value.List)args[1]).Item; IEnumerable <Tuple <Curve, XYZ> > data; if (args[2].IsList) { var targets = ((Value.List)args[2]).Item; if (curves.Count() != targets.Count()) { throw new Exception("The number of curves and the number of up vectors must be the same."); } //if we get a list of up vectors, then pair each //curve with a corresponding up vector data = curves.Zip(targets, (first, second) => new Tuple <Curve, XYZ>((Curve)((Value.Container)first).Item, (XYZ)((Value.Container)second).Item)); } else { //if we get a single up vector, then pair each //curve with that up vector data = curves.Select(x => new Tuple <Curve, XYZ>((Curve)((Value.Container)x).Item, (XYZ)((Value.Container)args[2]).Item)); } var instData = new List <FamilyInstanceCreationData>(); int count = 0; foreach (var pair in data) { var curve = pair.Item1; var target = pair.Item2; //calculate the desired rotation //we do this by finding the angle between the z axis //and vector between the start of the beam and the target point //both projected onto the start plane of the beam. XYZ zAxis = new XYZ(0, 0, 1); XYZ yAxis = new XYZ(0, 1, 0); //flatten the beam line onto the XZ plane //using the start's z coordinate XYZ start = curve.get_EndPoint(0); XYZ end = curve.get_EndPoint(1); XYZ newEnd = new XYZ(end.X, end.Y, start.Z); //drop end point to plane ////use the x axis of the curve's transform ////as the normal of the start plane //XYZ planeNormal = (curve.get_EndPoint(0) - curve.get_EndPoint(1)).Normalize(); //catch the case where the end is directly above //the start, creating a normal with zero length //in that case, use the Z axis XYZ planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize(); XYZ target_project = target - target.DotProduct(planeNormal) * planeNormal; XYZ z_project = zAxis - zAxis.DotProduct(planeNormal) * planeNormal; //double gamma = target_project.AngleTo(z_project); double gamma = target.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal); FamilyInstance instance = null; if (this.Elements.Count > count) { if (dynUtils.TryGetElement(this.Elements[count], out instance)) { if (instance.Symbol != symbol) { instance.Symbol = symbol; } //update the curve var locCurve = instance.Location as LocationCurve; locCurve.Curve = curve; } else { var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam) { RotateAngle = gamma }; instData.Add(beamData); } } else { var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam) { RotateAngle = gamma }; instData.Add(beamData); } count++; } //trim the elements collection foreach (var e in this.Elements.Skip(count)) { this.DeleteElement(e); } FSharpList <Value> results = FSharpList <Value> .Empty; if (instData.Any()) { var ids = dynRevitSettings.Doc.Document.Create.NewFamilyInstances2(instData); //add our batch-created instances ids' //to the elements collection ids.ToList().ForEach(x => Elements.Add(x)); } //add all of the instances results = Elements.Aggregate(results, (current, id) => FSharpList <Value> .Cons(Value.NewContainer(dynRevitSettings.Doc.Document.GetElement(id)), current)); results.Reverse(); return(Value.NewList(results)); }
internal static dynamic convertFromValue(Value exp) { if (exp.IsList) return ((Value.List)exp).Item.Select(x => convertFromValue(x)).ToList(); else if (exp.IsNumber) return ((Value.Number)exp).Item; else if (exp.IsString) return ((Value.String)exp).Item; else if (exp.IsContainer) return ((Value.Container)exp).Item; //else if (exp.IsFunction) //{ // return new Func<IList<dynamic>, dynamic>( // args => // ((Value.Function)exp).Item // .Invoke(ExecutionEnvironment.IDENT) // .Invoke(Utils.convertSequence(args.Select( // x => (Value)Converters.convertToValue(x) // ))) // ); //} //else if (exp.IsSpecial) //{ // return new Func<IList<dynamic>, dynamic>( // args => // ((Value.Special)exp).Item // .Invoke(ExecutionEnvironment.IDENT) // .Invoke( //} //else if (exp.IsCurrent) //{ // return new Func<dynamic, dynamic>( // ex => // Converters.convertFromValue( // ((Value.Current)exp).Item.Invoke(Converters.convertToValue(ex)) // ) // ); //} else throw new Exception("Not allowed to pass Functions into a Python Script."); }
/// <summary> /// Convert an input Value into and expected type if possible. /// Ex. If a node expects an XYZ, a user can pass in a ReferencePoint object /// and the position (XYZ) of that object will be returned. /// </summary> /// <param name="input">The value of the input.</param> /// <param name="output">The desired output type.</param> /// <returns></returns> public static object ConvertInput(Value input, Type output) { if (input.IsContainer) { object item = ((Value.Container)input).Item; #region ModelCurve if (item.GetType() == typeof(ModelCurve)) { ModelCurve a = (ModelCurve)item; if (output == typeof(Curve)) { return(((ModelCurve)item).GeometryCurve); } } #endregion #region SketchPlane else if (item.GetType() == typeof(SketchPlane)) { SketchPlane a = (SketchPlane)item; if (output == typeof(Plane)) { return(a.Plane); } else if (output == typeof(ReferencePlane)) { return(a.Plane); } else if (output == typeof(string)) { return(string.Format("{0},{1},{2},{3},{4},{5}", a.Plane.Origin.X, a.Plane.Origin.Y, a.Plane.Origin.Z, a.Plane.Normal.X, a.Plane.Normal.Y, a.Plane.Normal.Z)); } } #endregion #region Point else if (item.GetType() == typeof(Point)) { Point a = (Point)item; if (output == typeof(XYZ)) { return(a.Coord); } else if (output == typeof(string)) { return(string.Format("{0},{1},{2}", a.Coord.X, a.Coord.Y, a.Coord.Z)); } } #endregion #region ReferencePoint else if (item.GetType() == typeof(ReferencePoint)) { ReferencePoint a = (ReferencePoint)item; if (output == typeof(XYZ)) { return(a.Position); } else if (output == typeof(Reference)) { return(a.GetCoordinatePlaneReferenceXY()); } else if (output == typeof(Transform)) { return(a.GetCoordinateSystem()); } else if (output == typeof(string)) { return(string.Format("{0},{1},{2}", a.Position.X, a.Position.Y, a.Position.Z)); } else if (output == typeof(ElementId)) { return(a.Id); } } #endregion #region ElementId else if (item.GetType() == typeof(ElementId)) { if (output == typeof(ReferencePoint)) { ElementId a = (ElementId)item; Element el = dynRevitSettings.Doc.Document.GetElement(a); ReferencePoint rp = (ReferencePoint)el; return(rp); } } #endregion #region Reference else if (item.GetType() == typeof(Reference)) { Reference a = (Reference)item; if (output.IsAssignableFrom(typeof(Element))) { Element e = dynRevitSettings.Doc.Document.GetElement(a); } else if (output == typeof(Face)) { Face f = (Face)dynRevitSettings.Doc.Document.GetElement(a.ElementId).GetGeometryObjectFromReference(a); return(f); } } #endregion #region XYZ if (item.GetType() == typeof(XYZ)) { XYZ a = (XYZ)item; if (output == typeof(Transform)) { Transform t = Transform.get_Translation(a); return(t); } } #endregion return(item); } else if (input.IsNumber) { double a = (double)((Value.Number)input).Item; if (output == typeof(bool)) { return(Convert.ToBoolean(a)); } else if (output == typeof(Int32)) { return(Convert.ToInt32(a)); } return(a); } else if (input.IsString) { string a = ((Value.String)input).Item.ToString(); return(a); } else if (input.IsList) { FSharpList <Value> a = ((Value.List)input).Item; if (output == typeof(ReferenceArrayArray)) { return(DynamoTypeConverter.ConvertFSharpListListToReferenceArrayArray(a)); } else if (output == typeof(ReferenceArray)) { return(DynamoTypeConverter.ConvertFSharpListListToReferenceArray(a)); } else if (output == typeof(CurveArrArray)) { return(DynamoTypeConverter.ConvertFSharpListListToCurveArray(a)); } else if (output == typeof(CurveArray)) { return(DynamoTypeConverter.ConvertFSharpListListToCurveArray(a)); } return(a); } //return the input by default return(input); }
void DrawPython(Value val, RenderDescription rd) { DrawContainers(val, rd); }
/// <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)); } }
WatchNode Process(Value eIn, ref string content, string prefix, int count) { content += prefix + string.Format("[{0}]:", count.ToString()); WatchNode node = null; if (eIn.IsContainer) { if ((eIn as Value.Container).Item != null) { //TODO: make clickable hyperlinks to show the element in Revit //http://stackoverflow.com/questions/7890159/programmatically-make-textblock-with-hyperlink-in-between-text content += (eIn as Value.Container).Item.ToString(); node = new WatchNode((eIn as Value.Container).Item.ToString()); handlerManager.ProcessNode((eIn as Value.Container).Item, node); //node.Link = id; } } else if (eIn.IsFunction) { content += eIn.ToString() + "\n"; node = new WatchNode(eIn.ToString()); } else if (eIn.IsList) { content += eIn.GetType().ToString() + "\n"; string newPrefix = prefix + "\t"; int innerCount = 0; node = new WatchNode(eIn.GetType().ToString()); foreach(Value eIn2 in (eIn as Value.List).Item) { node.Children.Add(Process(eIn2, ref content, newPrefix, innerCount)); innerCount++; } } else if (eIn.IsNumber) { content += (eIn as Value.Number).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Number).Item.ToString()); } else if (eIn.IsString) { content += (eIn as Value.String).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.String).Item.ToString()); } else if (eIn.IsSymbol) { content += (eIn as Value.Symbol).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Symbol).Item.ToString()); } return node; }
protected override Expression compileBody( Dictionary <INode, string> symbols, Dictionary <INode, List <INode> > letEntries, HashSet <string> initializedIds, HashSet <string> conditionalIds) { var arg = arguments.First() .Value.compile( symbols, letEntries, initializedIds, conditionalIds); //idle :: (() -> A) -> A //Evaluates the given function in the Revit Idle thread. var idle = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( args => { var f = (args[0] as Value.Function).Item; if (dynSettings.Controller.DynamoViewModel.RunInDebug) { _node.OldValue = f.Invoke(FSharpList <Value> .Empty); return(_node.OldValue); } return(IdlePromise <Value> .ExecuteOnIdle( () => { _node.OldValue = f.Invoke(FSharpList <Value> .Empty); return _node.OldValue; })); })); //startTransaction :: () -> () //Starts a Dynamo Transaction. var startTransaction = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( _ => { if (_node.Controller.RunCancelled) { throw new CancelEvaluationException(false); } if (!dynSettings.Controller.DynamoViewModel.RunInDebug) { dynRevitSettings.Controller.InIdleThread = true; dynRevitSettings.Controller.InitTransaction(); } return(Value.NewDummy("started transaction")); })); //endTransaction :: () -> () //Ends a Dynamo Transaction. var endTransaction = Expression.NewFunction_E( FSharpFunc <FSharpList <Value>, Value> .FromConverter( _ => { if (!dynRevitSettings.Controller.DynamoViewModel.RunInDebug) { dynRevitSettings.Controller.EndTransaction(); dynRevitSettings.Controller.InIdleThread = false; dynSettings.Controller.DynamoModel.OnRequestLayoutUpdate( this, EventArgs.Empty); _node.ValidateConnections(); } return(Value.NewDummy("ended transaction")); })); /* (define (idleArg) * (startTransaction) * (let ((a <arg>)) * (endTransaction) * a)) */ var idleArg = Expression.NewFun( FSharpList <FScheme.Parameter> .Empty, Expression.NewBegin( new[] { Expression.NewList_E( new[] { startTransaction }.SequenceToFSharpList()), Expression.NewLet( new[] { "__result" }.SequenceToFSharpList(), new[] { arg }.SequenceToFSharpList(), Expression.NewBegin( new[] { Expression.NewList_E( new[] { endTransaction }.SequenceToFSharpList()), Expression.NewId("__result") }.SequenceToFSharpList())) }.SequenceToFSharpList())); // (idle idleArg) return (Expression.NewList_E( new[] { idle, idleArg }.SequenceToFSharpList())); }
private static Value _setParam(Element ft, Parameter p, Value valueExpr) { if (p.StorageType == StorageType.Double) { p.Set(((Value.Number) valueExpr).Item); } else if (p.StorageType == StorageType.Integer) { p.Set((int) ((Value.Number) valueExpr).Item); } else if (p.StorageType == StorageType.String) { p.Set(((Value.String) valueExpr).Item); } else if (p.StorageType == StorageType.ElementId) { p.Set((ElementId) ((Value.Container) valueExpr).Item); } else if (valueExpr.IsNumber) { p.Set(new ElementId((int) (valueExpr as Value.Number).Item)); } else { p.Set((ElementId) ((Value.Container) valueExpr).Item); } return Value.NewContainer(ft); }
public override Value Evaluate(FSharpList<Value> args) { var c = (System.Drawing.Color)((Value.Container)args[0]).Item; return Value.NewNumber(c.GetBrightness()); }
RenderDescription DrawPython(Value val) { RenderDescription rd = new RenderDescription(); DrawContainers(val, rd); return rd; }
public override Value Evaluate(FSharpList <Value> args) { if (!args[0].IsList) { throw new Exception("A list of UVs is required to place the Adaptive Component."); } FSharpList <Value> uvs = ((Value.List)args[0]).Item; var faceRef = ((Value.Container)args[1]).Item as Reference; var f = faceRef == null ? (Face)((Value.Container)args[1]).Item : (Face)dynRevitSettings.Doc.Document.GetElement(faceRef.ElementId).GetGeometryObjectFromReference(faceRef); var fs = (FamilySymbol)((Value.Container)args[2]).Item; FamilyInstance ac = null; //if the adapative component already exists, then move the points if (Elements.Any()) { //mutate Element e; //...we attempt to fetch it from the document... if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e)) { ac = e as FamilyInstance; ac.Symbol = fs; } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements[0] = ac.Id; } } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements.Add(ac.Id); } if (ac == null) { throw new Exception("An adaptive component could not be found or created."); } IList <ElementId> placePointIds = new List <ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac); if (placePointIds.Count() != uvs.Count()) { throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component."); } // Set the position of each placement point int i = 0; foreach (ElementId id in placePointIds) { var uv = (UV)((Value.Container)uvs.ElementAt(i)).Item; var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; var peref = dynRevitSettings.Revit.Application.Create.NewPointOnFace(f.Reference, uv); point.SetPointElementReference(peref); i++; } return(Value.NewContainer(ac)); }
WatchNode Process(WatchNode root, Value eIn, string prefix, int count, bool isListMember = false) { WatchNode node = null; if (eIn == null || eIn.IsDummy) { node = new WatchNode("null"); return node; } if (eIn.IsContainer) { var value = (eIn as Value.Container).Item; if (value != null) { node = new WatchNode(value.ToString(), isListMember, count); handlerManager.ProcessNode(root, value, node); } } else if (eIn.IsFunction) { node = new WatchNode("<function>", isListMember, count); } else if (eIn.IsList) { string newPrefix = prefix + "\t"; var list = (eIn as Value.List).Item; node = new WatchNode(list.IsEmpty ? "Empty List" : "List", isListMember, count); foreach (var e in list.Select((x, i) => new { Element = x, Index = i })) { node.Children.Add( Process(root, e.Element, newPrefix, e.Index, true) ); } } else if (eIn.IsNumber) { node = new WatchNode((eIn as Value.Number).Item.ToString(), isListMember, count); } else if (eIn.IsString) { node = new WatchNode((eIn as Value.String).Item, isListMember, count); } else if (eIn.IsSymbol) { node = new WatchNode((eIn as Value.Symbol).Item, isListMember, count); } // This is a fix for the following defect. "VirtualizingStackPanel" // does not quite work well with "WatchNode" being 'null' value. // // https://github.com/ikeough/Dynamo/issues/832 // return node ?? (new WatchNode("null")); }
/// <summary> /// Called during Evaluation, this method handles the /// conversion of an FScheme.Value object into a watchnode. /// This process uses the IWatchHandler registered on /// the controller to dynamically dispatch watch node /// processing based on the unboxed Value's object. /// </summary> /// <param name="value"></param> /// <param name="tag"></param> /// <param name="showRawData"></param> /// <returns></returns> public WatchItem Process(Value value, string tag, bool showRawData = true) { WatchItem node; if (value == null || value.IsDummy) { node = new WatchItem("null"); } else if (value.IsFunction) { node = new WatchItem("<function>"); } else if (value.IsList) { var list = ((Value.List) value).Item; node = new WatchItem(list.IsEmpty ? "Empty List" : string.Format("[{0}] List", tag)); foreach (var e in list.Select((x, i) => new {Element = x, Index = i})) { node.Children.Add(Process(e.Element, e.Index.ToString(CultureInfo.InvariantCulture), showRawData)); } } else { node = dynSettings.Controller.WatchHandler.Process(value.ToDynamic(), tag, showRawData); } return node ?? (new WatchItem("null")); }
public override Value Evaluate(FSharpList<Value> args) { if (PickedSunAndShadowSettings.Id.IntegerValue == sunAndShadowSettingsID.IntegerValue) // sanity check { XYZ sunVector = GetSunDirection(PickedSunAndShadowSettings); this.data = Value.NewContainer(sunVector); return data; } else throw new Exception("SANITY CHECK FAILED"); }
public static Curve UnwrapCurveOrEdgeFromValue(Value arg) { var crv = ((Value.Container) arg).Item as Curve; if (crv == null) { var edge = ((Value.Container) arg).Item as Edge; if (edge != null) { crv = edge.AsCurve(); } else { throw new Exception("The first argument is not a curve or an edge."); } } return crv; }
private void DrawPython(Value val, string id) { //DrawContainers(val, id); }
WatchNode Process(Value eIn, ref string content, string prefix, int count) { content += prefix + string.Format("[{0}]:", count.ToString()); WatchNode node = null; if (eIn.IsContainer) { if ((eIn as Value.Container).Item != null) { //TODO: make clickable hyperlinks to show the element in Revit //http://stackoverflow.com/questions/7890159/programmatically-make-textblock-with-hyperlink-in-between-text content += (eIn as Value.Container).Item.ToString(); node = new WatchNode((eIn as Value.Container).Item.ToString()); handlerManager.ProcessNode((eIn as Value.Container).Item, node); //node.Link = id; } } else if (eIn.IsFunction) { content += eIn.ToString() + "\n"; node = new WatchNode("<function>"); } else if (eIn.IsList) { content += "List\n"; string newPrefix = prefix + "\t"; var list = (eIn as Value.List).Item; node = new WatchNode(list.IsEmpty ? "Empty List" : "List"); foreach (var e in list.Select((x, i) => new { Element = x, Index = i })) { node.Children.Add(Process(e.Element, ref content, newPrefix, e.Index)); } } else if (eIn.IsNumber) { content += (eIn as Value.Number).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Number).Item.ToString()); } else if (eIn.IsString) { content += (eIn as Value.String).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.String).Item.ToString()); } else if (eIn.IsSymbol) { content += (eIn as Value.Symbol).Item.ToString() + "\n"; node = new WatchNode((eIn as Value.Symbol).Item.ToString()); } return node; }
private void DrawList(Value input) { #region points and curves //FSharpList<Value> list = ((Value.List)args[0]).Item; var inList = ((Value.List)input).Item; foreach (Value e in inList) { if (e.IsList) { DrawList(e); } else if (e.IsContainer) { XYZ ptTest = (inList.First() as Value.Container).Item as XYZ; Curve cvTest = (inList.First() as Value.Container).Item as Curve; if (ptTest != null) { pt = (e as Value.Container).Item as XYZ; DrawPoint(pt); } else if (cvTest != null) { c = (e as Value.Container).Item as Curve; DrawCurve(c); } } } RaisePropertyChanged("Points"); #endregion }
private static Value setParam(FamilySymbol fi, string paramName, Value valueExpr) { var p = fi.get_Parameter(paramName); if (p != null) { return _setParam(fi, p, valueExpr); } throw new Exception("Parameter \"" + paramName + "\" was not found!"); }
protected virtual bool AcceptsListOfLists(Value value) { return false; }
public override Value Evaluate(FSharpList<Value> args) { var bindings = new List<KeyValuePair<string, dynamic>> { new KeyValuePair<string, dynamic>("__persistent__", _stateDict) }; Value result = PythonEngine.Evaluator(_dirty, _script, bindings, MakeBindings(args)); _lastEvalValue = result; Draw(); return result; }
private Value evalIfDirty(FSharpList<Value> args) { if (SaveResult) { //If this node requires a re-calc or if we haven't calc'd yet... if (IsDirty || oldValue == null) //Evaluate arguments, then evaluate oldValue = evaluateNode(args); else //Otherwise, just increment the run counter. runCount++; //We're done here return oldValue; } else return evaluateNode(args); }
public override Value Evaluate(FSharpList <Value> args) { double xi; //, x0, xs; xi = ((Value.Number)args[1]).Item; // Number xi = Math.Round(xi); if (xi < Double.Epsilon) { throw new Exception("The point count must be larger than 0."); } //x0 = ((Value.Number)args[2]).Item;// Starting Coord //xs = ((Value.Number)args[3]).Item;// Spacing var result = FSharpList <Value> .Empty; Curve crvRef = null; if (((Value.Container)args[0]).Item is CurveElement) { var c = (CurveElement)((Value.Container)args[0]).Item; // Curve crvRef = c.GeometryCurve; } else { crvRef = (Curve)((Value.Container)args[0]).Item; // Curve } double t = 0.0; XYZ startPoint = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false); result = FSharpList <Value> .Cons(Value.NewContainer(startPoint), result); pts.Add(startPoint); t = 1.0; XYZ endPoint = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false); if (xi > 2.0 + Double.Epsilon) { int numParams = Convert.ToInt32(xi - 2.0); var curveParams = new List <double>(); for (int ii = 0; ii < numParams; ii++) { curveParams.Add((ii + 1.0) / (xi - 1.0)); } int maxIterNum = 15; int iterNum = 0; for (; iterNum < maxIterNum; iterNum++) { XYZ prevPoint = startPoint; XYZ thisXYZ = null; XYZ nextXYZ = null; Vector <double> distValues = DenseVector.Create(numParams, (c) => 0.0); Matrix <double> iterMat = DenseMatrix.Create(numParams, numParams, (r, c) => 0.0); double maxDistVal = -1.0; for (int iParam = 0; iParam < numParams; iParam++) { t = curveParams[iParam]; if (nextXYZ != null) { thisXYZ = nextXYZ; } else { thisXYZ = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false); } double tNext = (iParam == numParams - 1) ? 1.0 : curveParams[iParam + 1]; nextXYZ = (iParam == numParams - 1) ? endPoint : !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(tNext, true) : crvRef.Evaluate(tNext * crvRef.Period, false); distValues[iParam] = thisXYZ.DistanceTo(prevPoint) - thisXYZ.DistanceTo(nextXYZ); if (Math.Abs(distValues[iParam]) > maxDistVal) { maxDistVal = Math.Abs(distValues[iParam]); } Transform thisDerivTrf = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.ComputeDerivatives(t, true) : crvRef.ComputeDerivatives(t * crvRef.Period, false); XYZ derivThis = thisDerivTrf.BasisX; double distPrev = thisXYZ.DistanceTo(prevPoint); if (distPrev > Double.Epsilon) { double valDeriv = (thisXYZ - prevPoint).DotProduct(derivThis) / distPrev; iterMat[iParam, iParam] += valDeriv; if (iParam > 0) { iterMat[iParam - 1, iParam] -= valDeriv; } } double distNext = thisXYZ.DistanceTo(nextXYZ); if (distNext > Double.Epsilon) { double valDeriv = (thisXYZ - nextXYZ).DotProduct(derivThis) / distNext; iterMat[iParam, iParam] -= valDeriv; if (iParam < numParams - 1) { iterMat[iParam + 1, iParam] += valDeriv; } } prevPoint = thisXYZ; } Matrix <double> iterMatInvert = iterMat.Inverse(); Vector <double> changeValues = iterMatInvert.Multiply(distValues); for (int iParam = 0; iParam < numParams; iParam++) { curveParams[iParam] -= changeValues[iParam]; if (iParam == 0 && curveParams[iParam] < 0.000000001) { curveParams[iParam] = 0.5 * (changeValues[iParam] + curveParams[iParam]); } else if (iParam > 0 && curveParams[iParam] < 0.000000001 + curveParams[iParam - 1]) { curveParams[iParam] = 0.5 * (curveParams[iParam - 1] + changeValues[iParam] + curveParams[iParam]); } else if (iParam == numParams - 1 && curveParams[iParam] > 1.0 - 0.000000001) { curveParams[iParam] = 0.5 * (1.0 + changeValues[iParam] + curveParams[iParam]); } } if (maxDistVal < 0.000000001) { for (int iParam = 0; iParam < numParams; iParam++) { t = curveParams[iParam]; thisXYZ = !dynXYZOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false); result = FSharpList <Value> .Cons(Value.NewContainer(thisXYZ), result); pts.Add(thisXYZ); } break; } } if (iterNum == maxIterNum) { throw new Exception("could not solve for equal distances"); } } if (xi > 1.0 + Double.Epsilon) { result = FSharpList <Value> .Cons(Value.NewContainer(endPoint), result); pts.Add(endPoint); } return(Value.NewList( ListModule.Reverse(result) )); }