I have updated my Rhino from 6.0 to 6.34 and part of VB code stopped working

Hello, my code has stopped working (it used to work just few days ago), can someone point me what to change?

lines:


The script still takes screenshots but with wrong dimensions and the ZBuffer is not working anymore

The code:

Option Strict Off
Option Explicit On

'Import SDK and Framework namespaces
Imports RMA.OpenNURBS
Imports RMA.Rhino

Imports Grasshopper
Imports Grasshopper.Kernel
Imports Grasshopper.Kernel.Data

Imports System
Imports System.IO
Imports System.Xml
Imports System.Data
Imports System.Drawing
Imports System.Reflection
Imports System.Collections
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Runtime.InteropServices



'Code generated by Grasshopper(R) (except for RunScript() content and Additional content)
'Copyright (C) 2021 - Robert McNeel & Associates
<System.Runtime.CompilerServices.CompilerGenerated()> _
Public Class Script_Instance
  Implements IGH_ScriptInstance

#Region "Members"
  ''' <summary>List of error messages. Do not modify this list directly.</summary>
  Private __err As New List(Of String)

  ''' <summary>List of print messages. Do not modify this list directly, use the Print() and Reflect() functions instead.</summary>
  Private __out As New List(Of String)

  ''' <summary>Represents the current Rhino document.</summary>
  Private doc As MRhinoDoc = RMA.Rhino.RhUtil.RhinoApp().ActiveDoc()

  ''' <summary>Represents the current Rhino application.</summary>
  Private app As MRhinoApp = RMA.Rhino.RhUtil.RhinoApp()

  ''' <summary>Represents the Script component which maintains this script.</summary>
  Public owner As Grasshopper.Kernel.IGH_ActiveObject
#End Region

#Region "Utility functions"
  ''' <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  ''' <param name="text">String to print.</param>
  Private Sub Print(ByVal text As String)
    __out.Add(text)
  End Sub

  ''' <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
  ''' <param name="format">String format.</param>
  ''' <param name="args">Formatting parameters.</param>
  Private Sub Print(ByVal format As String, ByVal ParamArray args As Object())
    __out.Add(String.Format(format, args))
  End Sub

  ''' <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
  ''' <param name="obj">Object instance to parse.</param>
  Private Sub Reflect(ByVal obj As Object)
    __out.Add(GH_ScriptComponentUtilities.ReflectType_VB(obj))
  End Sub

  ''' <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
  ''' <param name="obj">Object instance to parse.</param>
  Private Sub Reflect(ByVal obj As Object, ByVal method_name As String)
    __out.Add(GH_ScriptComponentUtilities.ReflectType_VB(obj, method_name))
  End Sub
#End Region

  ''' <summary>
  ''' This procedure contains the user code. Input parameters are provided as ByVal arguments,
  ''' Output parameter are ByRef arguments. You don't have to assign output parameters,
  ''' they will be null by default.
  ''' </summary>
  Private Sub RunScript(ByVal FileName As String, ByVal blnSave As Object, ByVal Resolution_width As Integer, ByVal Resolution_height As Integer, ByVal DisplayMode As Integer, ByVal ViewName As Object, ByVal CustomView As Object, ByRef A As Object) 
    '////// Marc Hoppermann ///////////tweaked by Damien Almor ///////rewritten for curves by to]///////adapted by u]...www.utos.blogspot.com
    '///readapted to Batch ViewCapture by Victor Leung @ www.dreamationworks.com

    ' Note1: The script is actually calling Rhino commands.
    ' Note2: Remember you have to draw something and is selectable for the script to function. The script uses _SelAll then _Zoom _Selected
    ' Note3: After you toggle blnSave to True, a new viewport will popup, be patient while Rhino work, and wait for that viewport to disappear befor clicking on anything.
    ' Note4: The component is not stable if you try to mouse click on anywhere while the saving process is running. Some stupid move may crash your programme, save RH and GH files before using this component.

    ' FileName :  String Input    = Supply with the path and file name without ".jpg" extension : e.g.: "C:\Temp\001" (Without the quotes)
    ' blnSave :   Boolean Input   = Saves when toggles to True (Remember to toggle back to False after use, otherwise the script will re-run itself during next update)
    ' Resolution_width :    Integer Input = Resolution for the captured image
    ' Resolution_height :   Integer Input = well...
    ' TopYea :    Boolean Input =   Toggles if the Top View is captured (Default is False if not connected)
    ' FrontYea :  Boolean Input =   Toggles if the Front View is captured (Default is False if not connected)
    ' ...Yea :    Boolean Input =   Toggles if the corresponding View is captured (Default is False if not connected)
    ' DisplayMode : Integer Input(0-4) = Sets the display Mode 0:Shaded 1:Wireframe 2:Rendered 3:Ghosted 4:XRay Default:Shaded

    If blnSave Then

      'For i As Int32 = 0 To arrcrv.Count - 1
      app.RunScript("_NewFloatingViewport Projection=Top")
      app.RunScript("-ViewportProperties _Size " & Resolution_width * 500 / Resolution_height & " " & 500 & " _Display _Shaded _Enter")

      Select Case DisplayMode  '(If you know what you are doing and have other Custom Display Mode, you are welcomed to add it down here)
        Case 0
          app.RunScript(" _-SetDisplayMode _Mode _Shaded")
        Case 1
          app.RunScript(" _-SetDisplayMode _Mode _Wireframe")
        Case 2
          app.RunScript(" _-SetDisplayMode _Mode _Rendered")
        Case 3
          app.RunScript(" _-SetDisplayMode _Mode _Ghosted")
        Case 4
          app.RunScript(" _-SetDisplayMode _Mode _XRay")
        Case 5
          app.RunScript(" _-SetDisplayMode _Mode _Shaded")
          app.RunScript(" _-ShowZBuffer _Enter _Enter")

        Case Else
          app.RunScript(" _-SetDisplayMode _Mode _Shaded")
      End Select
      'app.RunScript(Resolution_width & "_Enter")
      'app.RunScript(Resolution_height & "_Enter")
      'app.RunScript("_Enter")

      doc.UnselectAll





      If CustomView Then
        MRhinoView.EnableDrawing(False)
        'app.RunScript("'_SelAll")
        app.RunScript("'_SetView " & ViewName & " _Enter")
        app.RunScript("'_SelNone _Enter")
        app.RunScript("'_-SelLayer Area _Enter")

        app.RunScript("'_Zoom _Selected")
        app.RunScript("'_SelNone _Enter")
        'app.RunScript(Chr(34) & "Exporting Custom View ...")
        MRhinoView.EnableDrawing(True)
        app.RunScript("_-viewcapturetofile " & FileName & ViewName & " _DrawGrid=No Width=" & Resolution_width & " Height=" & Resolution_height & "NumberOfPasses=1000" & "_Enter")

      End If

      app.RunScript("_CloseViewport")
      print("Done! Jpgs exported to " & FileName & ViewName)
      A = FileName & ViewName & ".jpg"
    Else print("inactive")

    End If
  End Sub 

  '<Custom additional code> 

  '</Custom additional code> 

End Class

Can you please share the GH file?

1 Like

Here: vbscript.gh (7.8 KB)

There are few discontinued methods.
I did not test, but I think it should work now. See attached
vbscript_RI.gh (8.9 KB)

1 Like

Thank You! the errors have dissappeared -
test3.gh (20.8 KB)
testco222b.3dm (4.7 MB)
but now the script is taking empty black screen screenshots, and I need to go back to Rhino from Grasshopper to click enter… do You know how to change that?

(edited) as this one was caused by changing my Rhino language to polish, reverting to english solved that. but I still get black screenshot - although with proper proportions

Are you missing the boolean toggle and set to “True” in the bInSave?

That is not the case unfortunately :slight_smile:
However sometimes it takes a proper screenshot, sometimes not - I am not sure why

I’m seeing the screenshot at my end, so I’m not sure how to debug it for you, but as far as the errors caused by the update to the latest service release, I think they are probably covered with the changes.

1 Like

So I figured out the script takes screenshots now at 1500x1500px and not 500x500 as previously. I do not see a way to change it… Do You have any idea?

Is this still a problem.
If so, can you please post a full solution definition, and perhaps a video or captured image to show the result you are getting?

1 Like

Thank You for inquiring.
I have solved it another way: I made a plane that has exact dimensions of my screenshot and this script somehow captures view extents - so it works how I intended. However I could not make it work by specifying the numerical dimensions.

1 Like