Grasshopper

algorithmic modeling for Rhino

Hi List,

 I am looking for a solution to save status of input for a custom component. What make it difficult to me is that the component has two input by default and user could raise an event and more input is registered.

Param_GenericObject pointInput = new Param_GenericObject();
pointInput.Name = "Point";
pointInput.NickName = "P";
pointInput.Description = "Point Input";
pointInput.Access = GH_ParamAccess.list;
this.Params.RegisterInputParam(pointInput, 2);
this.Params.Input[2].ExpireSolution(true);
this.Params.OnParametersChanged();

What I am trying to do is to save the status of these user added inputs. By default, the component is initialized with two input. If I saved a file with user added input and reopen it, I will loose the user added input and all the connections to these input.

I can think of two solution, 

(1) Save status of the component at file writing. I tried

public override bool Write(GH_IO.Serialization.GH_IWriter writer)

{

bool writeStatus = this.WriteFull(writer);

}

I guess because I have custom class input to the component which cannot be serialized by default,  it always return false.

(2) I could get the component connected to the input when saving the file with Params.Input[*].Sources.Attributes.GetTopLevel.DocObject

And then register the input manually when the component is initialized,

I still need to connect the new registered input to the previous connected components. Any suggestions on this?

Thank you for your help.

Xiaoming

Views: 368

Replies to This Discussion

You should implement the IGH_VariableParameterComponent interface. If you always add parameters through your own code you can provide null implementations for all the methods (just return false or null), but just implementing that interface means the component will be better at (de)serializing inputs and outputs that are not set up during construction.

Thank you David. It works great. 

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