Grasshopper

algorithmic modeling for Rhino

David,

Do you have any examples of catching the event that occurs when user Right Clicks on the input and changes its name. Custom defined input names are not serializing for me, for IGH_VariableParameterComponent. They are getting reset to original names. Every time file gets open. 

Any ideas? 

Here's what my variable param overrides look like:

public bool CanInsertParameter(GH_ParameterSide side, int index)
{
if (side == GH_ParameterSide.Output) return false;
if (index == 0) return false;
if (index == 1) return false;
return true;
}

public bool CanRemoveParameter(GH_ParameterSide side, int index)
{
if (side == GH_ParameterSide.Output) return false;
if (Params.Input.Count <= 2) return false;
if (index == 0) return false;
if (index == 1) return false;
return true;
}

public IGH_Param CreateParameter(GH_ParameterSide side, int index)
{
Param_GenericObject param = new Param_GenericObject();
param.Optional = true;
Params.RegisterInputParam(param, index);

return param;
}

public bool DestroyParameter(GH_ParameterSide side, int index)
{
return true;
}

public void VariableParameterMaintenance()
{
for (int i = 2; i < Params.Input.Count; i++)
{
IGH_Param param = Params.Input[i];

param.NickName = String.Format("D{0}", i);
param.Name = String.Format("Data{0}", i);
param.Description = String.Format("Data value {0}", i);
param.Access = GH_ParamAccess.tree;
}
}

Views: 664

Attachments:

Replies to This Discussion

You're specifically setting the name and nickname of your parameters in VariableParameterMaintenance()

param.NickName = String.Format("D{0}", i);
param.Name = String.Format("Data{0}", i);

Maybe you should only set the name if the parameter doesn't have one yet, i.e. string.Empty?

This makes perfect sense now. For some reason I thought that this particular information was being serialized and then de-serialized when file is open again. I will clean that up. 

Again, is there a way to catch the user right clicking on the component and changing input names? I am interested in re-executing the component when that happens since I want to pass input names out with my data. 

For some reason I thought that this particular information was being serialized and then de-serialized when file is open again. I will clean that up. 

It is. But after Grasshopper deserialized the custom nickname, you overwrite it again in VariableParameterMaintenance.

There are events for parameter nickname changes. If you handle the ObjectChanged event you'll catch all nickname changes, although note that event is used to funnel a lot of different types of changes. You need to look at the Type property of the event arguments and make sure it's NickName or NickNameAccepted.

(Initially the idea was that NickName is any change to the nickname, whereas NickNameAccepted would only be called when the editing stops. However I seem to remember this does not work as reliably as intended.)

Actually i found it. If anyone else was wondering: 

Subscribe to the ParameterNickNameChanged event. You can do that in the constructor for your custom class like this: 

public MantisShrimpComponent()
: base("MSObject", "Object",
"Mantis Shrimp object.",
"MantisShrimp", "Export")
{
this.CurrentKey = string.Empty;
Message = this.CurrentKey;
this.Params.ParameterNickNameChanged += new GH_ComponentParamServer.ParameterNickNameChangedEventHandler(OnParameterNickNameChanged);
}

Then implement a handler: 

protected virtual void OnParameterNickNameChanged(object sender, GH_ParamServerEventArgs e)
{
ExpireSolution(true);
}

I didn't realize that there was an event that fired here. Thanks for help David. 

Ah, good catch. I forgot the Params re-emits the nickname events.

David,

I just ran into something else now. I am able to catch the `ParameterNickNameChanged` event and force it to re-execute. However, that even only fires when user right clicks on component input, types in a new value and then hits Enter. It is also possible to change input name via right click, type in new value, and then click off the component using left mouse button. That stores the new value, but doesn't post an event. Is that intentional? Any ideas on how to catch that as well? 

Ps. I guess I can just use ParameterChanged event but would like to avoid re-computing the whole thing just to register input name changes. 

Cheers! 

See my earlier comment. This is an example where that NickNameAccepted event was not reliable.

As for recomputing, could you potentially just set a 'dirty' flag when a nickname is changed in any way, and then do the necessary computing during the next SolutionStart event?

Now that I think about it I think I am OK just forcing re-execution of the component since input nickname is being attached to data that comes into the input. What I have now, seems to be working just fine: 

this.Params.ParameterChanged += new GH_ComponentParamServer.ParameterChangedEventHandler(OnParameterChanged);

thanks for help! 

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2022   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service