Grasshopper

algorithmic modeling for Rhino

C# How to refer input parameters between //custom additional code//

Hello everyone,

I'd like to refer DataTree<double> parameter that connected left side of GH Component.

Usually, I succeeded in private void RunScript(DataTree<double> Input, ref object Output)

There is no need to think this.

But I failed to refer in custom additional code area.

Is there anyone knows how to refer input parameters between //custom additional code//?

Sorry for my poor knowledge of C#.....

Best,

Shimpei

Views: 1251

Replies to This Discussion

I don't understand. Whatever code you write in the additional block is necessarily in a different method than the RunScript method. As such that code will have to be encapsulated in a method signature of your own devising. You can choose whatever arguments you want for these methods. For example:

private void DoSomething(DataTree<double> data, double min, double max)
{
  for (int p = 0; p < data.BranchCount; p++)
  {
    List<double> branch = data.Branch(p);
    for (int i = 0; i < branch.Count; i++)
    branch[i] = Math.Min(Math.Max(branch[i], min), max);
  }
}

Attachments:

Dear David,

Thank you for your answer.

I made mistake to explain what I struggle.

I want to make global value in the additional block like this

And, I attach my .gh file.

private void RunScript(DataTree<double> Input, ref object A)
{

etc...

}

// <Custom additional code>

//refering global value
public int num = 4;
public int nnode = (int) Input.Branch(new GH_Path(0))[0];
public int nelem = (int) Input.Branch(new GH_Path(1))[0];
public int nmat = (int) Input.Branch(new GH_Path(2))[0];
public int nprop = (int) Input.Branch(new GH_Path(3))[0];


// </Custom additional code>

Attachments:

I don't think you can set Input to be a 'global' value (a class wide variable), since it is defined as an input of the method runscript. 

But, what you can do is create a declaring another Datatree<double> outside of the method and copying Input into it. 

Would that help?

private void RunScript(DataTree<int> x, ref object A)
{
y = x;
// Do Whatever you want here
A = y;

}

// <Custom additional code>
DataTree<int> y;


hacking services

WHO needs money??
need travel VISA??
PAYPAL AND BANK TRANSFER AVAILABLE
flight ticket available all destinations
ATM clone cards ready to ship all country
western union services back in the game
online shopping, ask me how it works
original FAKE or REAL id, dl, pp, skul docs available for all countries.

CONTACT ME NOW AT

watsap @0014242429194
icq @745215892
inbox @cleanhackdeals at gmail dot com

NB: dont waste your time to contact for fb, ig or twitter hack... few serious buyers needed

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service