Forgot password?

Create an account!

Forum

« back

RhinoScript – Rhino.Exit doesn't work in an IF statement

Messages

Please log in to write a message.

  • 1. jmineroff (Apr 19, 2015 23.19):

    Hi,

    I am trying to write a Rhinoscipt program to run from the command prompt that closes Rhino when it is complete. At the end of my code, I have been successfully using Rhino.Exit; however, it doesn't work when I try to use it to abort the script in case of an error.

    The script below attempts to create geometry using a parameter-driven Grasshopper file. It then checks if any geometry exists, writing the current state to a flag and exiting if necessary. I have tested the code and found that the flag is correctly written as "0" if there is no geometry; but then why doesn't Rhino.Exit run?

    Any help would be greatly appreciated.

    Thanks,
    Josh

    Call Main()
    Sub Main()
           
            ' Auto-bake a Grasshopper file that can fail to generate geometry under certain conditions
            ' (This is not an issue with the file and cannot always be determined in advance)

            ' Check that geometry was created
            Dim objects
            objects = Rhino.AllObjects(False,True)
           
            ' Get the file system object
            Dim objFSO, objStream
            Set objFSO = CreateObject("Scripting.FileSystemObject")
           
            ' Open a text file to write to
            Set objStream = objFSO.CreateTextFile("GHflag.txt", True)
            If Err Then
                    MsgBox Err.Description
                    Exit Sub
            End If
           
            ' Print flag file
            If IsArray(objects) Then        ' Print Success
                    objStream.WriteLine("1")
            Else                                            ' Print Fail
                    objStream.WriteLine("0")
                    Rhino.DocumentModified(False)
                    Rhino.Exit
            End If
            
            ' Close the file
            objStream.Close
            Set objStream = Nothing
            Set objFSO = Nothing
           
            ' Do other stuff
            ' ...
           
            ' Exit Rhino
            Rhino.DocumentModified(False)
            Rhino.Exit
    End Sub
Recommend

Why are these buttons gray?