import rhinoscriptsyntax as rs
import time
import Rhino
import sys

path = "C:\\Users\\vidal\\Documents\\optimization\\script_FD3D_grasshopper\\run.del"

file = open(path, 'r')

data = file.readlines()

file.close()

runValue = int(data[1])
geomPath = data[2]

print 'first path is : ' + geomPath
print 'first value is : ' + str(runValue)

GH = Rhino.RhinoApp.GetPlugInObject("Grasshopper")

n = 0

while runValue == 0 or runValue == 1 :
    
    n = n + 1
    
    if runValue == 1 :
		#GH.RunSolver(True)
		GH.OpenDocument("C:\\Users\\vidal\\Documents\\optimization\\script_FD3D_grasshopper\\hull_Parametric_clean.gh")
		GH.RunSolver(True)
		GH.CloseDocument()
		#GH.SetUserText("4a811e44-0ba8-4061-884e-ca7a6ec84e1b",geomPath)
		
		file = open(path, 'r')
		data = file.readlines()
		file.close()
		runValue = int(data[1])
		geomPath = data[2]
        
	
    time.sleep(4)
    file = open(path, 'r')
    data = file.readlines()
    file.close()
    runValue = int(data[1])
    geomPath = data[2]
    print data
    print 'in loop value= ' + str(runValue)
	
    if n == 15000 :
        print n
        print "iter finished"
        break
		

