How can I make my python type visible in rhino viewport?

Hello y’all fellow trainers.
I’ve been craving for the answer and got into the point where the only thing left is to ask directly.
What I’m trying to do is to make grasshopper display preview geometry for my(written inside a ‘Pyton script’ component) python type(class).
So, Inside the component, I’ll produce an instance which includes a grasshopper geometry(ex. mesh) as an parameter with bunch of other class-specific parameters(ex. self.the_mesh = x, self.index = 0…).
I can return this instance and use it inside another custom component.
But the thing it doesn’t do is to draw preview on rhino viewport like returning simple grasshopper mesh object would do.

I’ve read various topics about custom previewing regarding GH_Goo or IGH_PreviewObject, IGH_PreviewData but still can’t understand it. Most of them where about VB and I think that’s why.

Thinking of render pipeline I can imagine of two aproaches;

  1. Grasshopper reads components property to render preview so I need to pass Myclass().geo to MyComponent.some_assigned_parameter.
  2. Grasshopper reads every output of a component so Myclass need to inherit grasshopper built-in class as a protocol and some of its parameter or method has to be overriden to coop with Myclass().geo.

I do understand intermediate python syntax like inheritence, overriding parent’s method etc.
Please give me an insite.

Thank you.

—following is my script—

from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino
import rhinoscriptsyntax as rs

class MyComponent(component):     
    def RunScript(self, x):
        # input x is as list including a grasshopper geometry object
        class Myclass:
            def __init__(self, data):
                # 'geo' is a representative parameter of an instance
                self.geo = None
                for i,d in enumerate(data):
                    if isinstance(d, System.Guid):
                        self.geo = rs.coercegeometry(d)
                        data[i] = self.geo 
       = data
        b = Myclass(x)
        return b
        # want to make this 'MyComponent' draw self.geo on rhino viewport

I assume this is only part of the code right? If you post the .gh file you have more chance that people can spot the issue.

Oh yes. Here is the simple python file. Please HELP!
zipping (6.1 KB)

@grasshoppertrainer this might be a bit beyond my gh knowledge, but what I see is that you are returning b, which is not a mesh object. If you return both the class as well as the mesh data ([0]), it will display the mesh, see attached. Is this what you want?
zipping (7.9 KB)

Unfortunately, not really.
I want to return Myclass instance and mesh in it be drawn.
As grasshopper main loop automatically draws preview when its builtin geometry object is returned, I assume there is a protocol letting grasshopper main loop check whether returned is previewable and therefore informing it what to draw.
But I can’t figure out what that protocol is.
Are you aware of C#? I think this topic is related to my problem but in C#.

Sorry @grasshoppertrainer it’s only now that I understand what you want to accomplish. I’ve searched a bit but couldn’t find any python examples. Maybe @DavidRutten or @piac can help

Well, I have to dig in more then. Thank you for the kindness concerning my question.