Grasshopper

algorithmic modeling for Rhino

This is a question that follows a post of a month ago by Vicente Soler:

http://www.grasshopper3d.com/forum/topics/datadam-custom-interval?c...

I rewrote the VB component he provides (expire_02) in C# and it does not give any runtime errors. The goal of the component is to only alter a second component (onoff) when an input value changes, even when attached to a timer. But when I rewrote the VB component the onoff component keeps telling me that it has "failed to collect data". Although when I scroll over with my mouse, it does give me the correct value...

The only difference my C# has to the VB component is that I do have to type hint the x input as double to make it work this far. Keeping the x and xo as "object" does not work at all.

GH_Document doc = owner.OnPingDocument();
Grasshopper.Kernel.GH_Param<Grasshopper.Kernel.Types.GH_String> obj = null;

foreach( IGH_DocumentObject objt in doc.Objects ){
if(objt.NickName.Equals(y, StringComparison.Ordinal)){
obj = (Grasshopper.Kernel.GH_Param<Grasshopper.Kernel.Types.GH_String>) objt;
break;
}
}

if (x != xo) {
xo = x;
obj.ExpireSolution(true);
}
obj.AddVolatileData(new GH_Path(0), 0, xo);
}

// <Custom additional code>

double xo;

 


Would anyone would maybe know what's up?

Jesse

Views: 2848

Replies to This Discussion

Pushing data into a parameter from someplace else is quite a naughty thing to do. Grasshopper doesn't expect this to happen so there will be all kinds of weird side-effects.

First of all, this:

obj.ExpireSolution(true);

is highly illegal during a solution. If you start expiring stuff while a solution is trying to solve it all there's no predicting what state the document will end up in. It might be fine, it might be f*cked.

The only proper way of doing this is to trigger a new solution and assign your data before that solution starts. This involves scheduling a solution with a callback delegate. Wiping the target parameter in the callback, assigning the local data and fooling the parameter into thinking it never expired in the first place.

I attached a C# component that does this, but I cannot guarantee that I didn't miss something. One thing that definitely doesn't work is any parameter post-processes. If the target parameter has an expression, or a Graft or Flatten or Reverse flag, those will be ignored.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

For now it seems to work, thank you

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service