Hi Andrew, thanks for the reply. I tried to add the Read an Write functions and some of the extra things I found on your code just in case. I also looked at the Serialize file from JSwan: https://github.com/andrewheumann/jSwan/blob/master/jSwan/Serialize.cs
I am doing a similar logic to that. Please see files below and let me know if you have any ideas. What happens now is whether I copy or save/load the file the parameters custom context menu disappears (they don’t change type). Since I added a GUID on the parameter, I am also getting an error during load:
What I meant is that they seem to change their class type, instead of being the Param_GenericAccess, they become Param_GenericObject type, which doesn’t have any context menu modifications. I hope this makes things clearer!
My Parameter Class:
class Param_GenericAccess : Param_GenericObject, IDisposable
{
private const string ParamAccessKey = "ParamAccess";
public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
base.AppendAdditionalMenuItems(menu);
if (Kind != GH_ParamKind.output)
{
var item0 = Menu_AppendItem(menu, "Item", Menu_Clicked, true, Access == GH_ParamAccess.item);
item0.ToolTipText = "Make this parameter an Item";
var item1 = Menu_AppendItem(menu, "Array", Menu_Clicked, true, Access == GH_ParamAccess.list);
item1.ToolTipText = "Make this parameters an Array";
var item2 = Menu_AppendItem(menu, "Tree", Menu_Clicked, true, Access == GH_ParamAccess.tree);
item2.ToolTipText = "Make this parameter a Tree";
}
}
public void Dispose()
{
ClearData();
}
private void Menu_Clicked(object sender, EventArgs e)
{
var menu = sender as ToolStripMenuItem;
var name = menu.AccessibilityObject.Name;
RecordUndoEvent("Changing State");
if (name.Equals("Tree"))
{
//RecordUndoEvent("tree");
Access = GH_ParamAccess.tree;
}
else if (name.Equals("Array"))
{
//RecordUndoEvent("array");
Access = GH_ParamAccess.list;
}
else if (name.Equals("Item"))
{
//RecordUndoEvent("item");
Access = GH_ParamAccess.item;
}
OnObjectChanged(GH_ObjectEventType.DataMapping);
ExpireSolution(true);
}
public override bool Read(GH_IReader reader)
{
var result = base.Read(reader);
if(reader.ItemExists(ParamAccessKey))
{
try
{
//In case casting produces invalid Access enum
Access = (GH_ParamAccess)reader.GetInt32(ParamAccessKey);
}
catch (Exception)
{
}
}
return result;
}
public override Guid ComponentGuid => new Guid("{2E711E3A-A73E-42AD-86FF-0B6BA23E9990}");
public override bool Write(GH_IWriter writer)
{
var result = base.Write(writer);
writer.SetInt32(ParamAccessKey, (int)Access);
return result;
}
}
And this is my class that implements the IGH_VariableParameterComponent
public class CreateCustomData : GH_Component, IGH_VariableParameterComponent
{
public bool CanInsertParameter(GH_ParameterSide side, int index)
{
return side == GH_ParameterSide.Input;
}
public bool CanRemoveParameter(GH_ParameterSide side, int index)
{
return side == GH_ParameterSide.Input;
}
public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
base.AppendAdditionalMenuItems(menu);
var item = Menu_AppendItem(menu, "");
}
public IGH_Param CreateParameter(GH_ParameterSide side, int index)
{
var param = new Param_GenericAccess();
//var param = new Param_GenericObject();
//var param = new Param_ScriptVariable();
param.Name = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
param.NickName = param.Name;
param.Description = "Property Name";
param.Optional = true;
param.Access = GH_ParamAccess.item;
return param;
}
public bool DestroyParameter(GH_ParameterSide side, int index)
{
return true;
}
public void VariableParameterMaintenance()
{
}
public override bool Write(GH_IWriter writer)
{
return base.Write(writer);
}
public override bool Read(GH_IReader reader)
{
return base.Read(reader);
}
public override Guid ComponentGuid
{
get { return new Guid("1ae2d4ad-96ca-4fcc-970a-37373684e62b"); }
}
}