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 ?

Sorry to Necro this post. But I have come across the exact same problem, and rather then repost something, I and am wondering if this has been resolved? Or if Rutten could perhaps give more direction?

I’ve tried implementing IGH_PreviewData and IGH_PreviewObject and neither of them seem to actually get the component to draw

Any help would be really helpful.
public class TestPoint3dParameter : GH_PersistentGeometryParam<GH_TestPoint3d>, IGH_PreviewObject, IGH_PreviewData
{
public bool Hidden { get; set; }
public bool IsPreviewCapable { get; }

    public void DrawViewportMeshes(GH_PreviewMeshArgs args)
    {

    }

    public RG.BoundingBox ClippingBox
    {
        get
        {
            List<RG.Point3d> points = new List<RG.Point3d>();
            foreach (GH_TestPoint3d data in VolatileData.AllData(true))
                points.Add(data.Value.ToRhino());
            foreach (GH_TestPoint3d data in PersistentData.AllData(true))
                points.Add(data.Value.ToRhino());

            return new RG.BoundingBox(points.ToArray());
        }
    }

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


    public void DrawViewportWires(IGH_PreviewArgs args)
    {

        GH_PreviewWireArgs wireArgs = new GH_PreviewWireArgs(args.Display.Viewport, args.Display, args.WireColour, args.DefaultCurveThickness);

        foreach (GH_TestPoint3d data in VolatileData.AllData(true))
            data.DrawViewportWires(wireArgs);
        foreach (GH_TestPoint3d data in PersistentData.AllData(true))
            data.DrawViewportWires(wireArgs);
    }
    public void DrawViewportMeshes(IGH_PreviewArgs args) => throw new NotImplementedException();



    public override bool AppendMenuItems(ToolStripDropDown menu)
    {
        Menu_AppendPreviewItem(menu);
        return base.AppendMenuItems(menu);
    }
}

}