Grasshopper

algorithmic modeling for Rhino

How to read a txt file after an external program ran (How to check if a process is running?)?

Hi all,

     I need to read a txt file only after a process that I started previously (a FEM software), do you have any idea on how to do this?

I found on the net that with VB.NET there is the possibility to check if a process is running but in grasshopper it seems that there is non Process Class so I am a bit stuck.

I wrote the component for reading the txt file but it does not read the file after it has been written.

Some more infos

I am connecting GH to Sofistik for Structural Optimization, I can do the analysis but I need to read the result after the calculation process has been shut down.

Thank you in advance

Mauro

Views: 604

Replies to This Discussion

The Grasshopper File parameter allows you to expire the solution after a file has changed:

However this won't work if the FEM application is writing data slowly to the file. To detect when a file has been released by whatever application had a lock on it, I think you'll need to use a timer and check.

The System.Diagnostics.Process class is available from within the VB component. What example code did you find that doesn't work?

SOLVED

Here is the Sub in case anyone needs it

Private Sub RunScript(ByVal Filebat As Object, ByVal Avvia As Object, ByVal x As Object, ByRef LST As Object, ByRef B As Object, ByRef A As Object) 

    Dim bret As Boolean = False

    Dim parti As Boolean

    Dim listproc() As system.Diagnostics.Process

    Dim objProcess As System.Diagnostics.Process

 

    parti = CBool(Avvia)

 

    ''''''''''''''''''''''''''''''''''''''''fa partire sofistik'''''''''''''''''''''''''''''''

    If parti Then

 

      objProcess = New System.Diagnostics.Process()

      objProcess.StartInfo.FileName = Cstr(Filebat)

      'objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal

      objProcess.Start()

 

      'Wait until the process passes back an exit code

      objProcess.WaitForExit()

 

      'Free resources associated with this process

      objProcess.Close()

 

    End If

 

    ''''''''''''''''''''''''''''''''''''''''legge il file di sofistik'''''''''''''''''''''''''

 

    ' We need to read into this List.

    Dim list As New List(Of String)

    ' Open file.txt with the Using statement.

    Using r As StreamReader = New StreamReader(CStr(x))

      ' Store contents in this String.

      Dim line As String

      ' Read first line.

      line = r.ReadLine

      ' Loop over each line in file, While list is Not Nothing.

      Do While (Not line Is Nothing)

        ' Add this line to list.

        list.Add(line)

        ' Read in the next line.

        line = r.ReadLine

      Loop

    End Using

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    LST = list

 

 

  End Sub

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service