Grasshopper

algorithmic modeling for Rhino

I need to access a component which  has been written in GHpython in my loop And feed its input and evaluate its output,

 The python class file is accessible either

I  searched  and ended up with adding python class  in VS with .NET4 . but i need to work with C# script component inside GH.(its much easier to debug)

 -----------------------------------------------------------------------------

1.How can I access component or load its class that has written in python in myC# script component?

 

2.The component is Laydbug that use sticky for communicate between its sub components .

Could  I access s.th like sticky in C#?

 

 

 

 

 

 

thanks in advance for your help

Views: 1090

Replies to This Discussion

Hi Mostafa

yes, it's possible to do that. You can evaluate arbitrary Python expressions in the C# component using the IronPython engine that is integrated in Rhino using RhinoCommon. Here is how:

I hope this helps,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

thanks Giulio

if I have complex class in python and I want to use over sticky with c# how can I feed

my own variable in class and set a output for them?

in below pic I tried to elaborate.

Attachments:

I will not test this definition right now but it should also be relatively easily possible.

Basically you put everything you want to do ("statements") in the first string, and then the last string contains what you want to get ("expression"). The result of the expression is then transferred to C#.


@"import scriptcontext as sc
tst2 = sc.sticky[""testclass""](7,8)",

"tst2.area()"


Otherwise you can also make it all into one line,

"import scriptcontext as sc"

and

"sc.sticky[\"testclass\"](7,8).area()"

So, do as you wish. :)

Let me know if this helps,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

with this simple class it worked :)

m_ps.EvaluateExpression("import scriptcontext as sc\n" +
      "tst3= sc.sticky[\"testclss\"](7,8)", "tst3.area()");

I'll check it out tomorrow. Yes, sorry, you would have to put the literal value (like 7).

m_ps.EvaluateExpression(@"import scriptcontext as sc
tst2=sc.sticky[""testclass""](7,8)",

"tst2.area()");

(fixed above)

with simple definition that input could change to string it will work but for other definition  that need other object type as input  how could I feed them?

in GHpython script we make an instance of what sticky refers in main class

so we can easily feed them;

but in C# I dont know if its possible ?

Attachments:

any suggestion?

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