cscs icon indicating copy to clipboard operation
cscs copied to clipboard

Import and Export Variables from real c#

Open michalss opened this issue 6 years ago • 15 comments

Hi, i would like to import value from my selected source once i run the script, somewhere from my code. For example from listview or grid? Like i select something and get value from it and save it as cscs variable before any commands start process. Same for exporting variable, so example, saved some variable from cscs and i want to export it back to my code as variable. Can this be done pls ?

Thx

michalss avatar Jul 23 '18 05:07 michalss

Hi, actually it sounds like a cool and useful feature. I am going to implement it and let you know when ready. Thanks, Vassili

vassilych avatar Jul 23 '18 15:07 vassilych

Any news on this pls ? I kind of need it :)

michalss avatar Jul 25 '18 21:07 michalss

Can you give me an example of kind of C# variables that you will be using in CSCS scripts? The problem is whether they are static or not. If static, ok, then you can mention the scope, like MyClass.MyStaticVariable. But if they are not static, how would you propose to access them?

vassilych avatar Jul 25 '18 22:07 vassilych

Simple pass it to executable procedure void script. same once the script ends. And yes static is fine., There is not need to change it dynamically i guess..

image

Something like this, but it can be list of variable or anything else if someone need pass more then 1. And also it could be good to change it from void to Task or make it as function to get return values, for example. Just an idea.. :) Ahh as u can see i was trying to do it with global variable but it is useless once u want to thread it :( Thx

michalss avatar Jul 26 '18 05:07 michalss

any news pls?

michalss avatar Jul 30 '18 17:07 michalss

I am actually still struggling to get an example on how you can use it (I mean what kind of variables you can have in C# code that you want to access later in CSCS?)

vassilych avatar Aug 08 '18 03:08 vassilych

well string would be enought. Simple, in void ProcessScript i would like to add variable and pass it to cscs and once script finnish to get variable back from cscs to c#. It is not hard to do it with global varialbe, but as i said threading is a problem...

michalss avatar Aug 08 '18 21:08 michalss

Any update pls ?

michalss avatar Aug 14 '18 07:08 michalss

Working on it pls ? Jut let me know if so or i need to make it different way.. Thx

michalss avatar Aug 17 '18 07:08 michalss

Hi, I committed it. Main file where it is defined is Statics.cs It has the following variables, that can be updated from the CSCS code:

public static string StringVar = ""; public static double DoubleVar = 0.0; public static bool BoolVar = false; public static int IntVar = 0;

The CSCS functions to use are GetNative("C# variable name") and SetNative("C# variable name", value):

Here is an example in CSCS of the usage:

SetNative("StringVar", "abc"); x = GetNative("StringVar"); print("x=", x);

SetNative("DoubleVar", 123.45); d = GetNative("DoubleVar"); print("d=", d);

Note that how is everything set up, the variables are all defined in the Statics.cs class. You can define there other variables as well, just keep "public static " for them, so that you can access those variables anywhere from your C# code, e.g.:

string x = Statics.StringVar;

Let me know if it works for you.

Cheers, Vassili

vassilych avatar Aug 17 '18 20:08 vassilych

Hi,

Can this variables be instancseable pls ? I would like to get return variable per thread..

michalss avatar Aug 21 '18 09:08 michalss

is there any chance to pls do it ? If so how ?

michalss avatar Nov 19 '18 07:11 michalss

Yes, these variables are static. But you can add there a unique id (e.g. just a counter, or a thread id, etc.) to make them unique per thread. E.g.:

name = "StringVar" + someId; SetNative(name, "abc"); x = GetNative(name); print("x=", x);

Wouldn't setting a unique name make the trick?

vassilych avatar Dec 03 '18 11:12 vassilych

I am working on a module that would allow dynamic runtime import/export of variables to and from C# without the need to define and compile them in the Statics.cs file. I already have this working in some of my own projects, but will try to extract it into it's own module and commit it as a pull request soon.

JasonLWalker avatar Oct 05 '20 03:10 JasonLWalker

Hi Jason,

Looks very good! Let me merge it once I am back from my vacation on Sunday.

Thanks, Vassili

On Mon, 5 Oct 2020 at 06:32, JasonLWalker [email protected] wrote:

I am working on a module that would allow dynamic runtime import/export of variables to and from C# without the need to define and compile them in the Statics.cs file. I already have this working in some of my own projects, but will try to extract it into it's own module and commit it as a pull request soon.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vassilych/cscs/issues/5#issuecomment-703377446, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE74VFASHVGQ63YN37JJIATSJE43FANCNFSM4FLJPQ7Q .

vassilych avatar Oct 05 '20 18:10 vassilych