Preview custom data type within GH_PeristentGeometryParam

Hello :smiley:

I’m working on a C# plugin which contains custom data types some being displayed in the viewport.

For example, there’s a custom data type called GH_Support which implements GH_GeometrcGoo. When created with a component GH_Supports are displayed like this:

I created a custom floating parameter which implements GH_PersistentGeometryParam<GH_Support>. This floating parameter seems to work well except for the preview … The data inside is not displayed in the Rhino viewport.

I suspect this is linked to the lack of Display button in the menu but I can’t add it …

Does anyone have an idea on how to display data within the parameter ?

Thank you !

PS: here are the files containing the C# definition ;
MyPlugin.zip (360.7 KB)

You will have to implement the IGH_PreviewObject interface in your parameter to enable previews on it.

Hello @DavidRutten, thank you for your quick answer !

I tried to implement IGH_PreviewObject but I’m struggling a bit to be honnest. Here’s my try :

public void DrawViewportWires(IGH_PreviewArgs args)
{
    foreach (GH_Support data in VolatileData.AllData(true) )
    {
        data.DrawViewportWires((GH_PreviewWireArgs)args );
    }
    foreach (GH_Support data in PersistentData.AllData(true))
    {
        data.DrawViewportWires((GH_PreviewWireArgs) args);
    }
}

public void DrawViewportMeshes(IGH_PreviewArgs args)
{
    foreach (GH_Support data in VolatileData.AllData(true))
    {
        data.DrawViewportMeshes((GH_PreviewMeshArgs) args);
    }
    foreach (GH_Support data in PersistentData.AllData(true))
    {
        data.DrawViewportMeshes((GH_PreviewMeshArgs) args);
    }
}

public bool Hidden { get; set; }

public bool IsPreviewCapable { get { return true; } }

Firstly, I suppose that I can create auto-property for Hidden.

Then, as GH_Support can be previewed, IsPreviewCapable is always true ?

Eventually, I tried to implement DrawViewportWires(IGH_PreviewArgs args) and DrawViewportMeshes(IGH_PreviewArgs args) using GH_Support methods as I suppose that its GH_PreviewWireArgs(GH_PreviewWireArgs args) and GH_PreviewMeshArgs(GH_PreviewMeshArgs args) methods work as intended.

In the end, the preview button is present but nothing is displayed in the viewport … Do you have any clue of what’s wrong ?