import os 
# Variables 
path = os.getcwd()
filename = "Start.scdocx"
filepath = os.path.join(path, filename)

try: 
    print("Process Started...")
   
    # Import project
    importOptions = ImportOptions.Create()
    print("Importing project...")
    DocumentOpen.Execute(filepath, importOptions)
    print("Project imported.")

    # Update Reflector
    print("Finding reflector...")
    Reflector = SpeosDes.RectangularSurface.Find("Optical Surface Rectangular.1")
    print("Reflector Status = " + str(Reflector.StatusInfo))
    print("Parameters before modifications:")
    print("XRadius = " + str(Reflector.Groups[0].XRadius))
    print("YRadius = " + str(Reflector.Groups[0].YRadius))
    Reflector.Groups[0].XRadius = 5
    Reflector.Groups[0].YRadius = 5
    Reflector.Compute()
    print("Reflector's Status after compute = " + str(Reflector.StatusInfo))
    print("Parameters after modifications:")
    print("XRadius = " + str(Reflector.Groups[0].XRadius))
    print("YRadius = " + str(Reflector.Groups[0].YRadius))
    
    # Update Simulation 
    print("Finding Simulation...")
    dummySimu = SpeosSim.SimulationDirect.Find("Dummy_Simulation")
    print("Object = " + str(dummySimu))
    print("Simulation Status before compute = " + str(dummySimu.StatusInfo))
    dummySimu.Compute()
    print("Simulation Status after compute = " + str(dummySimu.StatusInfo))
    
    # Save File
    options = ExportOptions.Create()
    DocumentSave.Execute(os.path.join(path, "End.scdocx"), options)
    
except Exception as err:
    print("Unexpected error: \n"+str(err)+", "+str(type(err)))
finally:
    print("Process finished.")