#
# Copyright © 2020 MSC.Software Corporation
#  
# Permission to use Scripts
#  
# Permission is granted to MSC.Software customers with valid licenses of the MSC Apex™ software 
# to use script files posted on this page (collectively “Scripts”) solely for customers’ own authorized 
# internal use in conjunction with licensed use of the MSC Apex software.  
# No other use is permitted.  No license to MSC Apex or other software is granted under this Permission.
#  
# SCRIPTS ARE PROVIDED ON AN "AS-IS" BASIS, WITH NO WARRANTIES OF ANY KIND.  USE OF THE SCRIPTS IS AT CUSTOMER'S SOLE RISK.
#  
# IN NO EVENT SHALL MSC.SOFTWARE CORPORATION, ITS AFFILIATES, SUBSIDIARIES, SUPPLIERS, AGENTS, REPRESENTATIVES OR EMPLOYEES BE LIABLE FOR ANY 
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, 
# STRICT LIABILITY, OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION USE OF THE SCRIPTS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
#  
# Customer shall indemnify, defend and hold MSC.Software Corporation, its affiliates, subsidiaries, suppliers, agents, 
# employees or representatives (collectively, “Indemnified Parties”) harmless from and against any third-party claims 
# brought against Indemnified Parties rising out of or in connection with Customer’s use of the Scripts.
#
import os
import time
import datetime
import sys
import traceback
import importlib

# This py script is either called from a macro StartIberianLynxFP2Utils, or using the new event Trigger mechanism
# Using the (old) macro method, the exported bdf is digged up from the log file
# Using the new event trigger, the exported bdf is passed as a command line argument sys.argv[1]
from aux_functions_v106b import *
importlib.reload(sys.modules['aux_functions_v106b'])
from aux_functions_v106b import *

def ProcessSettingsFileOptions(bdf_path,SettingsD,exportOptionFlag,OptionsD={}):

	#==========================RunNastran SOL112==========================================================

	# export and optionally run sol112 job
	if exportOptionFlag == "sol112":
		write_sol112_bdf_stuff(bdf_path, SettingsD)
		if SettingsD['NASTRAN_JOB_SETUP']['RunNastran'].upper() == "TRUE":
			print("Trying to run Nastran...")
			try:
				run_nastran(bdf_path, SettingsD)
				print("Nastran executed successfully")
			except:
				print("Could not run Nastran")
		else:
			print("Nastran execution is not choosen")


if __name__ == "__main__":


	settings_file = "C:\\Users\\e11352\\Documents\\GitHub\\APEX-Utilities-Test\\Utilities\\Export\\Export112\\res\\UtilityUserSettings.xml"

	SettingsD=read_settings(settings_file)
	exportOptionFlag = "sol112"
	bdf_path = "C:\\Users\\e11352\\Documents\\GitHub\\APEX-Utilities-Test\\Utilities\\Export\\Export112\\res\\DynamicScenario_preLoad.bdf"


	ProcessSettingsFileOptions(bdf_path,SettingsD,exportOptionFlag)
