Grasshopper

algorithmic modeling for Rhino

Dear forum.

I've been struggling with getting a persistent parameter to work on my component after a file save. Basically, I'm creating my own parameter using the GH_PersistentParam<T> class, where I'm using a GH_ObjectWrapper type. This may not be the best way about doing this, but it does work.

localSettings of type EM_Settings is the data that gets wrapped and then added to the Parameter.

Whilst everything works fine first time around, when I re-open the GH file the persistent data is lost. I need to serialize the data in some way in order to write it to a GH file and I'm not entirely sure how to do this.... I've tried for quite a while now, looking through the forum & SDK which offer clues but no joy... so I'm admitting defeat and running here!!!

Here are some of the CS bits:


public class MyComponent : GH_Component
{
    .........
    private EM_SettingsParam myParam;

    private EM_Settings localSettings;

    private EM_Settings mySettings;

    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pm)
    {

          ...
       myParam = new EM_SettingsParam();
       EM_Settings localSettings = new EM_Settings();
       myParam.PersistentData.Append(new GH_ObjectWrapper(localSettings));
       pm.AddParameter(myParam, "Settings", "Se", "MySettings", GH_ParamAccess.item);
    }

    protected override void SolveInstance(IGH_DataAccess DA)
    {
       GH_ObjectWrapper temp = new GH_ObjectWrapper();
       if (!DA.GetData(5, ref temp)){ return; }
       mySettings = (EM_Settings)temp.Value;

       ...

    }
}


public class EM_SettingsParam : GH_PersistentParam<GH_ObjectWrapper>
{
     public EM_SettingsParam():
     base(new GH_InstanceDescription("Settings", "Settings", "Represents a collection of Settings", "Params", "Primitive"))
     {
     }

     ...blah singular blah plural blah exposure.hidden blah...

}

public class EM_Settings
{
     public bool Preview {get; set;}
     // (more parameters here)

     public EM_Settings()
     {
         Preview = true;
     }

}

Any help much appreciated $:)

John.

Views: 1109

Replies to This Discussion

Hi John,

I'm afraid IGH_Goo and GH_ObjectWrapper were not properly designed to be fully (de)serializable. This will be rectified in 2.0 but until then you probably won't be able to read and write object wrappers with custom data in them.

You'll have to provide a proper implementation of IGH_Goo for your data type and abandon GH_ObjectWrapper.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Ah, goodbye GH_ObjectWrapper!

Thanks for pointing me in the right direction David.

John.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service