Grasshopper

algorithmic modeling for Rhino

Hi All,

I have a problem with c# scripted components in GH. Its seems like data is being stored inside component and changing input or turning on and of component doesn't. Actually it appears like new input is being stored on top of the old one so results are double. 

Only way i found out to refresh solution is to create a bug in a code, disable component, clear caches, remove the bug and enable component again. 

My suspection fall on Class I'm creating to store values. 

class iV
{
public static string _familyNameBase;
public static char _splitChar;
public static List<string> _parametersNames = new List<string>();
public static DataTree<Point3d> _newPts = new DataTree<Point3d>();
public static DataTree<string> _parameters = new DataTree<string>();
public static List<string> _typeNamesOut = new List<string>();

}

Is it possible that variables declared in a separate class are not being refreshed automatically?!? :||

Thanks a lot for input.

Views: 1194

Replies to This Discussion

If the stuff is static and you keep appending more to those lists, then yeah, it'll keep piling on. Any reason these variables have to be static?

I want to have them directly accessible from any function. Is there a way to do it without static variable? 

Best practice is to share that class with all functions rather than make it static. Or put the methods and the variables in the same class.

or maybe there is a way to clean them at every run from inside the code?

Sure, you can call _parametersNames.Clear(); when you enter your script. That'll erase the previous data. Or you can clear the data just before you exit.

what do you mean by share the class? i'm sorry i'm a bit noob :)

If i instantiate class inside main void function is becoming private.. this also doesn't work for me

btw, why main function is private?

We're getting out of my comfort zone quickly here, I'm not a python programmer. However in pseudo-code it would look like this:

class iV { ... }

EntryMethod(...)

{

  iV ivInstance = new iV();

  ivInstance.SetupData(...);

  Method1(argument 1, argument2, ivInstance);

  Method2(argument 3, ivInstance);

  Method3(argument4, argument4, ivInstance);

  return some value;

}

Method1(type1, type2, iV)

{

  ...

}

The other approach is to put the methods inside the iV class:

class iV

{

  variable1;

  variable2;

  variable3;

  Method1(...) {}

  Method2(...) {}

}

EntryMethod(...)

{

  iV ivInstance = new iV();

  ivInstance.SetupData(...);

  ivInstance.Method1(argument 1, argument2);

  ivInstance.Method2(argument 3);

  return ivInstance.Result;

}

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