Hi I’m trying to programatically show/preview GH geometry from an ETO UI.
Code is working as expected if executed from ghPython component.
If code is trigered from an ETO UI, Code is working as expected BUT for views in Rendered/Arctic/Raytraced AND those geometries that had custom renderMaterial preview applied.
I might be failing to call some gh method that forces the redraw of custom material preview in mentioned viewModes, because grasshopper’s own preview on/off is working ok. Those anyone knows what method from gh/rhincommon sdk I need to call to make this work? Or maybe is related to ETO somehow. I don’t get it…
Your video is too high resolution to be readable on my phone, but if it is about custom preview component and rendered/arctic/raytraced be advised there is an extra check option on the custom preview component that you need to uncheck to hide geometry. Right-click on a custom preview component, it is the entry above Preview.
I don’t know if there is an easy API for that, though.
Thank @nathanletwory, it would be nice if you can see the video. It shows that code works if triggered directly from ghPython, but fails (only for renderd/arctic/raytraced + renderMaterials) if its trigered from a ETO UI.
There is maybe some method called behind the scenes by grasshopper that i’m not aware off, wich for some reason is not called when my code is trigered from ETO. My code is quite simple, just switching GH_Document.ExpirePreview On and Off. @DavidRutten, can you see if I’m missing something here? In short, I need to programatically mimic GH preview mode functionalities. For some reason, i’m not able to hide geometry with custom material if viewMode is arctic/rendered/raytraced. Gh handles it perfectly, but my code can’t IF executed from ETO (please, watch gh file & video attached above)
well As shown in the video this is not exactly true. If my code is run directly from a GHpython component, it works perfectly. The problem is when I try to run it called by ETO event (button click in my sample). What Am I missing? I suspect that my problem is more related with some Grasshopper redrawing/solving method than to ETO by itself. Maybe ETO is here an “external execution environment” so when my preview on/off method is called from within GH, some method is called behind the scenes, wich is not executed when called from ETO… I’m guessing…
Without ETO executed directly from GhPython component (working):
import Grasshopper as gh
import Eto.Forms as forms
import Eto.Drawing as drawing
class GhHelpers():
def previewGh(self,boolPreview):
try:
activeGhDoc = gh.Instances.ActiveCanvas.Document
if boolPreview:
activeGhDoc.PreviewMode = gh.Kernel.GH_PreviewMode.Shaded
else:
activeGhDoc.PreviewMode = gh.Kernel.GH_PreviewMode.Disabled
activeGhDoc.ExpirePreview(True)
except Exception as e:
Rhino.RhinoApp.WriteLine(str(e))
ghHelper = GhHelpers()
ghHelper.previewGh(preview)
using ETO (not working for rendered/Artic/Raytraced views):
import Grasshopper as gh
import Eto.Forms as forms
import Eto.Drawing as drawing
class GhHelpers():
def previewGh(self,boolPreview):
try:
activeGhDoc = gh.Instances.ActiveCanvas.Document
if boolPreview:
activeGhDoc.PreviewMode = gh.Kernel.GH_PreviewMode.Shaded
else:
activeGhDoc.PreviewMode = gh.Kernel.GH_PreviewMode.Disabled
activeGhDoc.ExpirePreview(True)
except Exception as e:
Rhino.RhinoApp.WriteLine(str(e))
class MyDialog(forms.Form):
def __init__(self):
self.ghHelp = GhHelpers()
showButton = forms.Button(Text = 'show')
showButton.Click += self.onShowButtonClick
hideButton = forms.Button(Text = 'hide')
hideButton.Click += self.onHideButtonClick
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.Add(showButton)
layout.Add(hideButton)
self.Content= layout
def onShowButtonClick(self,sender,e):
self.ghHelp.previewGh(True)
def onHideButtonClick(self,sender,e):
self.ghHelp.previewGh(False)
if run:
myDlg = MyDialog()
myDlg.Topmost = True
myDlg.Show()
The Custom Preview component behaves in two different ways depending on the type of viewport. It will either draw previews like all other components using the display pipeline, or, in viewports that are considered to be “rendered”, it will add meshes and materials to the Rhino custom render mesh pipeline. Rhino then deals with the display of these meshes internally. This feature exists so you can add shapes to any RDK compliant render plugin.
You can find these extra options in the Custom Preview object menu, and you will have to modify them programmatically if you want to show or hide Custom render meshes.
Do note that once the meshes are handed over to Rhino, the Custom Preview component is out of the loop as far as display is concerned, so just changing the setting on the CP component is probably not sufficient to trigger a change. You may also have to expire that component and start a new solution to update the cached meshes in Rhino.
@DavidRutten the CP component isn’t being changed. Instead, the GH document preview settings are changed. Difference is how the code is run. (GH Python without Eto, GH Python with Eto)