algorithmic modeling for Rhino
Hey, i have a question how i could get something out of a private void. The Question is in the c# code:
private void RunScript(object curve, ref object resFct)
{
//the following line needs to be exactly this. no changes are allowed,//because this function goes to another node wich then works with this...
Func < OpenTK.Vector2d, OpenTK.Vector2d, OpenTK.Vector2d > resultingFunction = TopologyReaction;
resFct = resultingFunction;
}// <Custom additional code>
public static OpenTK.Vector2d TopologyReaction(OpenTK.Vector2d parentPt, OpenTK.Vector2d newPt)
{//and here i need to work with the curve (object curve) from private void
//how do i do this?!? Whats the trick here?
parentPt = newPt;
return parentPt;
}
Tags:
Your TopologyReaction method needs to get a reference to the curve. Since you're not allowed to change the signature of it, you'll need to embed the function into a class instance which has this reference. Ie. instead of a public static method, what you do is create a new type:
public sealed class TopologyReactionWrapper
{
private readonly Curve _curve;
public TopologyReactionWrapper(Curve curve)
{
_curve = curve;
}
public OpenTK.Vector2d TopologyReaction(OpenTK.Vector2d parentPt, OpenTK.Vector2d newPt)
{
// You have access to parentPt and newPt here, as well as _curve.
}
}
Then you return a delegate to the instance method from within RunScript:
private void RunScript(Rhino.Geometry.Curve curve, ref object resFct)
{
TopologyReactionWrapper wrapper = new TopologyReactionWrapper(curve);
Func<OpenTK.Vector2d, OpenTK.Vector2d, OpenTK.Vector2d> func = wrapper.TopologyReaction;
resFct = resultingFunction;
}
I think.... I haven't tried this code, but if it doesn't work it should at least be close.
Hey, thank you so much!! it is hard for me to understand whats happening, so i dont really know how to fix the error in this line:
resFct = resultingFunction;
it sais:
"1. Error (CS0103): Der Name 'resultingFunction' ist im aktuellen Kontext nicht vorhanden. (line 90)"
translated it is something like: name "resultingFunction" is not available in the actual context...
Is there an easy fix for it?
Thank you so much - especially getting help from the master himself here! ;)
Cheers
NEVER MIND... Stuped me...
" resFct = func;"
Thank you so much, ill see how far i get till i ask the next question ;)
sorry, I renamed it func but forgot to rename it everywhere.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by