Grasshopper

algorithmic modeling for Rhino

Hi David,

I would like to pass a class object as a custom parameter between my custom components. The problem is though that I cannot get the behavior as how the 'native' Grasshopper parameters behave.

Say I have a simple class A, that has a list property called SomeList:

public class A
{
    public A()
    {
        SomeList = new List<string>();
        SomeList.Add("_init");
    }
    public List<string> SomeList { get; set; }
}

Now I make a custom parameter for this class as we discussed in the other question: 

(http://www.grasshopper3d.com/forum/topics/custom-parameter-base-cla...)

I have a component (left in the picture below) that initializes the class A and passes it to the DA.SetData output as a GH_AParam.

(I pass the 'SomeProperty' list to the DA.SetData output in each of the components to show what is happening to this class property)

Now I have an operator component that adds an "ITEM" to this property list. In the initial component the class number 1 is made and has stage 0 so (1.0). When I operate on this original parameter the stage number is increased with one so (1.1) and so it progresses as (1.++) downstream. In other words the SomeList property should progress in the first stream as:

(1.0) SomeProperty: 

0 _init

(1.1) SomeProperty:

0 _init

1 ITEM

(1.2) SomeProperty:

0 _init

1 ITEM

2 ITEM

When I create a new stream from the original I would like to take again the initial value from the initial component in other words; Duplicate stage (1.0) to a new one (2.0) as:

(2.0) SomeProperty: 

0 _init

(2.1) SomeProperty: 

0 _init

1 ITEM

However the operator on the second stream gives me the latest version of the class.

I have tried getting the Volatile data from the GH_InputParamManager input parameter of each of the components but this still always gives me the most updated version of this parameter.

Since you basically do this with all your parameters I was wondering if there is an override property you can set in a custom parameter so that it always returns the 'local' state of the parameter in every component instead of the 'current' state.

I hope this is clear and thanks in advance!

Dion

Views: 842

Attachments:

Replies to This Discussion

Your class A doesn't implement IGH_Goo, do you have a wrapper class for that? 

Note that when you use IGH_Goo level access to inputs, you do not get copies of the data inside parameters. You get the actual data. So when you don't make copies of that data yourself before you modify it, the changes will affect all components which have another instance of that same data.

Basically, make sure you copy your goo before changing it.

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi David,

I am using a wrapper class GH_SomethingData to implement the IGH_Goo, as you can find attached.

(I made an identical B class to compare the results)

Now in my operator component I can call the Duplicate() method on the input to create a new IGH_Goo instance of the param like:

protected override void SolveInstance(IGH_DataAccess DA)
{
    GH_BData input = null;
    DA.GetData<GH_BData>(0, ref input);

    IGH_Goo duplicate = input.Duplicate();

    B m_B = ((GH_BData)duplicate).Value;

    m_B.SomeList.Add("ITEM");

    GH_BData output = null;
    List<string> notes = new List<string>();

    output = new GH_BData(m_B);

    notes = m_B.SomeList;

    DA.SetData(0, output);
    DA.SetDataList(1, notes);
}

The problem is that the Duplicate method creates a whole new (empty) instance of the param and thus reverts at each operator the state back to the initial, so that the downstream effect of multiple operators in a stream is gone.

Overriding from the input goo always gives me the most recent state so that calling in my SolveInstance of the operators:

    m_B.SomeList =  input.Value.SomeList;

Doesn't work because it returns - as you said - the actual data.

How then can I get access to the let's say, local state of an output parameter? Is there even such a thing and is this the right way of achieving my goal, or is there something else I can use?

Thanks again,

Dion

Attachments:

I think your Duplicate function isn't really duplicating properly. See attached.

--

David Rutten

david@mcneel.com

Tirol, Austria

Attachments:

Thank you David, this is working perfectly!

I think I am finally starting to understand these wrapper classes and how they work.

Thanks again,

Dion

Hi guys,

Is this really working for you?

I have everything compiling correctly, but if I register an input or output like this:

pManager.AddParameter(new GH_BParam(), etc..);

the component won't appear anymore...

Has this ever happend to you?

sorry, e

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