Hi,
I want to search in the rh o gh forum from the canvas search box by typing:
forum gh textToSearch
or
forum rh textToSearch
but my code doesn’t work and I can’t figure out why.
public class SearchOnForumComponent : GH_Component , IGH_InitCodeAware{
string initcode;
public SearchOnForumComponent() : base("Forum Search", "Forum", "Search on gh or rh forum", ComponentsUtil.Category, ComponentsUtil.Subcategory) { }
public override Guid ComponentGuid => new Guid("faa8fe19-51d8-4617-8e4b-2cfabf84dbf4");
public void SetInitCode(string code) {
try
{
initcode = code;
Rhino.RhinoApp.WriteLine("code is: " + code); //Not shown in rhino
if (code.StartsWith("forum", StringComparison.OrdinalIgnoreCase))
{
code = code.Remove(0, 5).Replace(" ", "");
Rhino.RhinoApp.WriteLine(code);
if (code.StartsWith("gh", StringComparison.OrdinalIgnoreCase))
{
code = code.Remove(0, 2);
Rhino.RhinoApp.WriteLine(code);
System.Diagnostics.Process.Start(
string.Format("http://www.grasshopper3d.com/page/search-results?site=&q={0}+site%3Agrasshopper3d.com", code)
);
Rhino.RhinoApp.WriteLine("GH ");
}
else if (code.StartsWith("rh", StringComparison.OrdinalIgnoreCase))
{
code = code.Remove(0, 2);
Rhino.RhinoApp.WriteLine(code);
System.Diagnostics.Process.Start(
string.Format("https://discourse.mcneel.com/search?q={0}", code)
);
}
else {
Rhino.RhinoApp.WriteLine("NO");
}
}
}
catch (Exception e)
{
Rhino.RhinoApp.WriteLine(e.ToString());
}
}
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
}
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Rhino.RhinoApp.WriteLine("solveinstance code: " + initcode);
}
}
The only thing the rhino history shows is:
solveinstance code:
But the component appears in the search as the first option. It’s also instantiated.
What am I doing wrong?
Another thing is that I want to remove the component when the search is performed. In what context should I do this? In SetInitCode()? in AddedToDocument()? in SolveInstance()?
Thank you.