Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4159

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

$
0
0

@grasshoppertrainer wrote:

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 
                self.data = data
                
        b = Myclass(x)
        return b
        # want to make this 'MyComponent' draw self.geo on rhino viewport

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4159

Latest Images

Trending Articles



Latest Images