Custom Preview not working from Rhino Plugin

We are trying to create a plugin that can send and receive data from rhino to gh and vice versa.

I have attached a sample program that takes a Boolean input and change the colour of the surface.

This works pretty well when we run it inside gh as C# component (refer snapshot) but its not working when we run the same in Rhino plugin. Can someone please advice on how to resolve it?

Many thanks

How are you sending data from the Rhino plug-in to Grasshopper? And how are you previewing that data from the Rhino plug-in?

We do something like this. Usually this works when the output is a panel but here its custom preview so we were unable to figure it out.

var ghDoc = new GH_DocumentIO();
ghDoc.Open(FilePath);
var  DocumentIO = ghDoc.Document;

List<IGH_ActiveObject> activeObjects = DocumentIO.ActiveObjects();
 foreach (IGH_ActiveObject battery in activeObjects)
      {
        if (battery is Grasshopper.Kernel.Special.GH_BooleanToggle)
        {
          Grasshopper.Kernel.Special.GH_BooleanToggle btn = battery as Grasshopper.Kernel.Special.GH_BooleanToggle;
          if (btn.NickName == "input")
          {
            btn.Value = true;
            btn.ExpireSolution(true);
          }
        }
      }

      foreach (var battery in activeObjects)
      {
        if(battery is Grasshopper.Kernel.Components.GH_CustomPreviewComponent)
        {
          var previewComponent = battery as Grasshopper.Kernel.Components.GH_CustomPreviewComponent;

          if (previewComponent.NickName == "output")
          {
            previewComponent.CollectData();
            previewComponent.ExpireSolution(true);
          }
        }
      }

@nathanletwory @Mahdiyar @maje90
any input would be very helpful

Not sure how that is supposed to work when doing that from a Rhino plug-in.

I’m not sure if I fully understand what you’re trying to do.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    if (!(RhinoApp.GetPlugInObject(_ghId) is GH_RhinoScriptInterface gh)) return Result.Failure;
    gh.LoadEditor();
    var filePath = RhinoGet.GetFileName(GetFileNameMode.Open, "*.gh", "Select file", null);
    if (string.IsNullOrEmpty(filePath) || !System.IO.File.Exists(filePath)) return Result.Cancel;
    var ghDoc = Instances.DocumentServer.AddDocument(filePath, true);
    foreach (var obj in ghDoc.ActiveObjects())
    {
        if (obj is GH_BooleanToggle b && b.NickName == "input")
        {
            b.Value = true;
            b.ExpireSolution(true);
        }
        else if (obj is GH_ColourSwatch s && s.NickName == "color")
        {
            s.SwatchColour = Color.FromKnownColor(_colors[_rnd.Next(_colors.Length)]);
            s.ExpireSolution(true);
        }
    }
    return Result.Success;
}

Saket.gh (6.0 KB)
Saket.zip (102.4 KB)

2 Likes

@dale would you have any suggestion?

ot: how did you manage to get your interface changed like that? (statusbar and rounded corner checkboxes)

I’m using windows 11.

1 Like

@Mahdiyar It works! thanks for the help :slight_smile: