How to use the CustomPreview and CreateMaterial in ghpythonlib?

I am confused about the inputs for those components
any suggestions?

Thanks in advance

any ideas? T.T

Hu @raylee14,

As far as I know, you can use “CreateMaterial” from ghpythonlib but you can’t use it afterwards to feed the “CustomPreview”.
All these preview components (“CustomPreview”, “TextTag”, “Text Tag 3D”…) can not be used in ghpythonlib.

so how to change color and material with python?
it is quite messy to use the preview components all the time

You can use the CustomDisplay class (example here) for rendering non-shaded stuff (e.g. curves and vectors). Or override DrawViewportMeshes and DrawViewportWires (with the GHPython component set to SDK mode) for rendering all sorts of things, like so:


200401_GHPython_DrawViewportWires_02.gh (16.6 KB)

This is just my first stab at implementing the latter method. As far as I call tell, one probably ought set the bounding box as well (Edit: For frustum culling, as explained here by Giulio).

8 Likes

Thank you so much.
I am new to rhino python.
it seems the class is created automatically, right?

I think this is a self-defined component like the built-in preview component in grasshopper.
what about changing the color of brep objects in different lines of a python script?
I want to handle it insides the script so that i don’t have to use the preview component all the time

This is just a minimal working example of how to implement/override these methods. You can do this within the component you want to.

You can implement DrawBrepShaded in DrawViewportMeshes:

All that said, if you’re just starting out. Perhaps this is all a bit complicated, and stick to just outputting your geometry and using CustomDisplay for now.

i see the point. is it possible to write this as a class and call out when needed like the ghpythonlib components?

thanks again

i will try to make it with what you provide
thank you so much dude <3

I don’t think so. Since it’s how a compiled Grasshopper component (and the C# scripting component) works (i.e. overriding DrawViewportMeshes and DrawMeshWires is the simplest method of using implement a DisplayPipeline). It would indeed be great if one could call these draw methods in the procedural GHPython mode directly without having to wrap everything in class.

Thanks again. i’ve got some ideas :smiling_face_with_three_hearts:

have you got any ways to do it in a class

hi thanks for the awesome plugin. Is it possible to display the Mesh in order to see the Grasshopper mesh inside the Rhino objects?

Hi @AndersDeleuran,

i’m not able to make the original example work in Rhino 8 (windows), it still works in RH6 and RH7. Do you know why ?

thanks,
c.

You probably need to include the clipping box method now, see this example:

1 Like

thank you @AndersDeleuran, get_ClippingBox solved it for me.

_
c.

1 Like