Hi All,
I was trying to use Menu_AppendTextItem in context menu to get user input and pass it to the IGH_Attributes Interface class (for future displaying such user input).
So far what I was able to update the value in the component side after click the “commit change” button, with the following structure:
namespace newComp.Components
{
public class newComp : Grasshopper.Kernel.Special.GH_NumberSlider
{
public List<double> keyvalue;
public newComp()
: base()
{
this.keyvalue = new List<double> { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };
}
public override GH_Exposure Exposure
{
get { return GH_Exposure.primary; }
}
public override void CreateAttributes()
{
{
this.m_attributes = (IGH_Attributes)new newCompAttributes(this, keyvalue);
}
}
public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
ToolStripMenuItem PDDropdown = GH_DocumentObject.Menu_AppendItem(menu, "Custom keyvalue");
Menu_AppendTextItem(PDDropdown.DropDown,
"Custom keyvalue",
null,
new GH_MenuTextBox.TextChangedEventHandler(updatePD),
true);
PDDropdown.DropDown.Items[1].Click += (obj, e) => OK_Click(obj, e);
PDDropdown.DropDown.Items[2].Click += (obj, e) => Cancel_Click(obj, e);
base.AppendAdditionalMenuItems(menu);
}
private void OK_Click(object sender, EventArgs e)
{
// update the keyvalue in component
}
}
public class newCompAttributes : Grasshopper.Kernel.Special.GH_NumberSliderAttributes
{
private List<double> keyvalue;
PSlider own;
public PSliderAttributes(newComp owner, List<double> values) :
base(owner)
{
keyvalue = values;
own = owner;
}
protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics,
Grasshopper.GUI.Canvas.GH_CanvasChannel channel)
{
// ...
}
}
}
I was wondering how I can pass the user input value (keyValue) to the attribute side so it could be reflected on the UI?
Many thanks!