Forum

How to get instance of c# class from pin in plugin

devvvv

#1

hi,

I’m writing plugin with VS now.
define multiple classes as vvvv node with IPluginEvaluate in single dll, then sharing same custom data by Pin.
I could use connected and disconnected event for checking pin status and get node info each other.
but I cannot find good way to get an instance of c# class from different instance of other class.

for example, class A looks like

[PluginInfo ...
public class A : IPluginEvaluate
{
    public int V;
    
    [Input(Name = "Input")](Input(Name = "Input"))
    Pin<bool> FInput;
    
    public void Evaluate(int SpreadMax)
    {
    }
}

and class B

[PluginInfo ...
public class B : IPluginEvaluate, IPartImportsSatisfiedNotification
{
    [Output(Name = "Output")](Output(Name = "Output"))
    Pin<bool> FOutput;
    
    public void OnImportsSatisfied()
    {
        FOutput.Connected += OnConnected;
    }
    
    public void Evaluate(int SpreadMax)
    {
    }
    
    void OnConnected(object sender, PinConnectionEventArgs args)
    {
        // I wanna get value V of instance of class A here.
    }
}

is this possible with vvvv plugin interfaces or c#?


#2

it is better to structure your classes in a different way, do not do any logic or functionality in the node class, only have your own classes which interact with each other and let the node classes create/assign/delete and call them. something like this:

//everything happens here
public class MyFunctionality
{
    public int V;
    public int MakeSomethingCool()
    {
        //cool code
    }
}

//only handles slices, no logic in here
[PluginInfo ...
public class NodeA : IPluginEvaluate
{

    [Output(Name = "Output")](Output(Name = "Output"))
    ISpread<MyFunctionality> FOutput;

    private List<MyFunctinality> FInstances = new List<MyFunctinality>();
    
    public void Evaluate(int SpreadMax)
    {
        for (int i = 0; i < SpreadMax; i++)
        {
            //something like
            FInstances[i](i) = new MyFunctionality();
        }
    }
}

and class B

//everything happens here
public class MyOtherClass
{
    public int V;
    public int MakeSomethingElse(MyFunctionality other)
    {
        //cool code
    }
}

//only handles slices, no logic in here
[PluginInfo ...
public class NodeB : IPluginEvaluate
{
    [Input(Name = "Input")](Input(Name = "Input"))
    IDiffSpread<MyFunctionality> FInput;

    MyOtherClass FInstance = new MyOtherClass();

    public void Evaluate(int SpreadMax)
    {
        for (int i = 0; i < SpreadMax; i++)
        {
            var value = FInput[i](i).V;
            FInstance.MakeSomethingElse(FInput[i](i));
        }
    }
}

#3

thanks for your advice. but I noticed misunderstand about input & output pin. my question was how to get data from output pin, but it is reverse way of vvvv logic. so it can’t.
anyway, define class and create it from node class will useful.