import System
import clr
import sys
from math import *

clr.AddReference("Ansys.ACT.Interfaces")
import Ansys

from Ansys.ACT.Interfaces.Common import *
from Ansys.ACT.Interfaces.UserInterface import *

import sys

def OpenMechanical(systemName, componentName):
    sys = GetSystem(systemName)
    comp = sys.GetContainer(componentName)
    comp.Refresh()
    comp.Edit()

def OpenDesignModeler(systemName, componentName):
    sys = GetSystem(systemName)
    comp = sys.GetContainer(componentName)
    comp.Edit(IsSpaceClaimGeometry=False)

def OpenFluent(systemName, componentName):
    sys = GetSystem(systemName)
    setup1 = sys.GetContainer(ComponentName="Setup")
    fluentLauncherSettings1 = setup1.GetFluentLauncherSettings()
    fluentLauncherSettings1.SetEntityProperties(Properties=Set(EnvPath={}))
    tGridData1 = GetDataEntity("/Mesh/TGridData:TGridData")
    tGridData1.SetEntityProperties(Properties=Set(RunParallel=False, NumberOfProcs=1))
    mesh1 = sys.GetContainer(ComponentName=componentName)
    Fluent.Edit(Container=mesh1)

def OpenSpaceClaim(systemName, componentName):
    sys = GetSystem(systemName)
    comp = sys.GetContainer(componentName)
    comp.Edit(IsSpaceClaimGeometry=True)

def OpenElectronicsDesktop(systemName, componentName):
    Ansoft.EditSystem(System=systemName)

def CloseMechanical(systemName, componentName):
    sys = Project.GetSystem(systemName)
    comp = sys.GetContainer(componentName)
    comp.Exit()

def CloseDesignModeler(systemName, componentName):
    sys = Project.GetSystem(systemName)
    comp = sys.GetContainer(componentName)
    comp.Exit()

def CloseSpaceClaim(systemName, componentName):
    sys = Project.GetSystem(systemName)
    comp = sys.GetContainer(componentName)
    comp.Exit()

def CloseFluent(systemName, componentName):
    sys = Project.GetSystem(systemName)
    cont = sys.GetContainer(componentName)
    Fluent.Exit(Container=cont)

def CloseElectronicsDesktop(systemName, componentName):
    sys = Project.GetSystem(systemName)
    Ansoft.CloseEditor(sys)