Announcement

Collapse
No announcement yet.

Grasshopper C# VRay.GetState

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grasshopper C# VRay.GetState

    Is there a way to get the current state of a VRay Next rendering, from a C# component in Grasshopper? (IDLE, FINISHED etc.)
    (The rendering is triggered in Rhino)

    Using the .Net SDK I can do this, which will print "IDLE_DONE":

    VRay.VRayRenderer renderer = new VRay.VRayRenderer();
    renderer.StartSync();
    renderer.WaitForRenderEnd();
    Print(renderer.GetState().ToString());

    Here obviously I set up a new VRay object and it renders an empty scene.
    So another way to ask my first question:
    Is there a way to reference the VRayRenderer object that was created when setting up the rendering in Rhino?

    I hope the question makes sense...

    All the best,
    Joakim

  • #2
    Hi Joakim,

    If understand correctly, the short answer is: yes.
    There is a C export from the plugin binary that can be called from C#. Since they live in the same process, importing a method from the .rhp to C# will access the correct memory segment (since the .rhp is already loaded)

    Click image for larger version  Name:	getrenderstate.png Views:	1 Size:	277.9 KB ID:	1045620

    The C# code here is very simple:

    Code:
      private void RunScript(object x, object y, ref object A)
      {
        RendererState state = (RendererState) ImportInterface.GetRendererState();
        Print(state.ToString());
      }
    
      // <Custom additional code>
      enum RendererState {
        FatalError = -1,
        IdleInitialized,
        IdleStopped,
        IdleError,
        IdleFrameDone,
        IdleDone,
        Preparing,
        Rendering,
        Paused,
        AwaitngChanges
      };
    
      public static class ImportInterface
      {
        [System.Runtime.InteropServices.DllImport("VRayForRhino.rhp")]
        public static extern int GetRendererState();
      }
      // </Custom additional code>

    Comment


    • #3
      Thank you so much! As long as I don't check too frequently and do a few extra checks if the value has changed this works as well as VRayRenderer.WaitForRenderEnd()

      Comment

      Working...
      X