Hi,
This is my first post to this forum. I am just a beginner so I am not really sure what everything in my code does. Below is my python code. I would like to change the code to ask the user where the files are located and automatically update the various programs.
Compare1.asc and Compare 2.asc are almost identical so I will only refer to Compare1.asc. These programs are used with a program called MUST. I would like to ask the user some questions and have the answers automatically update the Compare1.asc and resave. One example: The Compare1.asc below uses the directory:C:\Temp\TestPy\.
I would like to ask the user where his files are located and have the answer change the program and resave.
I am not sure if I hit on all the main points or explained my problem well enough so if you have any questions please ask.
Thanks,
Joe
Question.py--------------------------------------------------------------------------------------
print "This test program requires:"
print " the use of Python2.5"
print " the use of Excel2003"
print " the directory C:\Temp\TestPy exist"
print " the file AnalysisX.asc exist and is present in directory where this is run"
print " the files Analysis1.bat & Analysis2.bat exist and is present in directory where this is run"
print " that PSS(r)MUST 9.1 by installed in the default dir C:\Program Files\Pti\MUST 9.1 "
print " "
cmd = "Analysis1.bat"
print "Executing Cmd:",cmd # convenient way to visually verify command to be run
status = os.system ( cmd ) # cmd contains command to run MUST with ASC file
print "Creating workbook for ANALYSIS1 run"
MUST_Rpt_File1 = 'C:\\Program Files\\PTI\\MUST 9.1\\Program\\systlist.lis'
xlsFile = 'C:\\temp\\testpy\\MyExcelFile1.xls'
xlApp = win32com.client.Dispatch( "Excel.Application" )
xlApp.Visible = False
ot_Origin = 437
ot_StartRow = 1
ot_DataType =1
ot_TextQualifier = 1
ot_ConsecutiveDelimiter = 1
ot_Tab = 1
ot_Semicolon = 0
ot_Comma = 0
ot_Space = 1
ot_Other = 0
xlApp.Workbooks.OpenText(MUST_Rpt_File1, ot_Origin,ot_StartRow,ot_DataType,ot_TextQualifier, ot_ConsecutiveDelimiter,ot_Tab, ot_Semicolon, ot_Comma, ot_Space)
xlApp.ActiveWorkbook.SaveAs(xlsFile)
xlApp.ActiveWorkbook.Close(False)
xlApp.Quit()
cmd = "Analysis2.bat"
status = os.system ( "Analysis2.bat" ) #using alternate way to run MUST script
print "Creating workbook for ANALYSIS2 run"
MUST_Rpt_File2 = 'C:\\Program Files\\PTI\\MUST 9.1\\Program\\systlist.lis'
xlsFile = 'C:\\temp\\testpy\\MyExcelFile2.xls'
xlApp = win32com.client.Dispatch( "Excel.Application" )
xlApp.Visible = False
ot_Origin = 437
ot_StartRow = 1
ot_DataType =1
ot_TextQualifier = 1
ot_ConsecutiveDelimiter = 1
ot_Tab = 1
ot_Semicolon = 0
ot_Comma = 0
ot_Space = 1
ot_Other = 0
xlApp.Workbooks.OpenText(MUST_Rpt_File2, ot_Origin,ot_StartRow,ot_DataType,ot_TextQualifier, ot_ConsecutiveDelimiter,ot_Tab, ot_Semicolon, ot_Comma, ot_Space)
xlApp.ActiveWorkbook.SaveAs(xlsFile)
xlApp.ActiveWorkbook.Close(False)
xlApp.Quit()
print "Finished!"
Analysis1.bat----------------------------------------------------------------------
MUST Compare1.asc
Analysis2.bat----------------------------------------------------------------------
MUST Compare2.asc
Compare1.asc---------------------------------------------------------------------
*C -
*C PSSĀ®MUST 9.1 Response File - Recorded: Thursday, Apr 16,2009 23:00:43
*C -
optn
2 9999999
3 1
*blank
y
pscase
'C:\Temp\TestPy\y08_09sR3.sav'
acsolv/opt/adj/1 1/2 0/3 1/4 0/5 1/
gen/1 1/3 0/
sol/1 30/2 0.6/3 0/4 0/5 0.9/7 0.7/8 15///
ACSOLV/LFN
*if *MUST_STATUS LE 2 then
subs/read
'C:\Temp\TestPy\ACCC-MUST.sub'
*blank
*endif
*if *MUST_STATUS LE 2 then
constr
1 2.00000
2 3
3 100
4 3
5 100
6 4
7 0
8 3
9 10000
/y
*endif
*if *MUST_STATUS LE 2 then
read
'C:\Temp\TestPy\OUC.mon'
'C:\Temp\TestPy\FL230-FMPP.con'
*blank
*endif
*if *MUST_STATUS LE 2 then
constr//excl/read/ 'C:\Temp\TestPy\NonFirmExclude.exc'//
*endif
*if *MUST_STATUS LE 2 then
must
1 0
2 1
3 50000
4 0.03000
5 3
6 1
7 1
8 0.00000
9 0.00000
10 0.00000
/y
*endif
*C AC MENU shifts indirectly recorded
*C >> REF TO DIRECT OUTPUT <<<<<<
tran/direct/f/Case_1_systlist.lis/print syst/direct/t/
*C >> MENU SHIFT <<<<<<
/3/
MUST
1 0
2 1
3 50000
4 0.02000
5 100
6 0
7 1
8 0.00000
9 0.00000
10 0.00000
/y
*C >> MENU SHIFT <<<<<<
/3/ACCONT
lfopt
adj/1 0/2 0/3 1/4 0/5 1/
gen/1 1/3 0
/sol/1 30/2 0.6/3 0/4 0/5 0.9/7 0.7/8 15//
opt/1 2/2 2
3 0
4 0/
exe
*C
*C Select all constraints
constra
bra/sel/all/
int/sel/all/
fgate/sel/all/
*blank
*C
*C
*C Select all contingencies
contin/sel/all/
*C
dir/f/'Case1_ContSum.lis'
*C >> MODIFIED REF TO EXCEL INTERFACE <<<<<<
constr/print sum/print bviol/
*C >> REF TO TERMINAL OUTPUT <<<<<<
dir/t
cont/sel
All
/constraints/Branch/sel/all
*C >> MODIFIED REF TO EXCEL INTERFACE <<<<<<
dir/f/Case1_MonElRep/ opt/1 100/2 100//pr viol/dir/t//
save/'C:\Temp\TestPy\Compare.acc'
/
/MUST
1 0
2 1
3 50000
4 0.03000
5 3
6 1
7 1
8 0.00000
9 0.00000
10 0.00000
/y
/3/
stop
Compare2.asc--------------------------------------------------------------------
*C -
*C PSSĀ®MUST 9.1 Response File - Recorded: Thursday, Apr 16,2009 23:00:43
*C -
optn
2 9999999
3 1
*blank
y
pscase
'C:\Temp\TestPy\y08_09sR3.sav'
acsolv/opt/adj/1 1/2 0/3 1/4 0/5 1/
gen/1 1/3 0/
sol/1 30/2 0.6/3 0/4 0/5 0.9/7 0.7/8 15///
ACSOLV/LFN
*if *MUST_STATUS LE 2 then
subs/read
'C:\Temp\TestPy\ACCC-MUST.sub'
*blank
*endif
*if *MUST_STATUS LE 2 then
constr
1 2.00000
2 3
3 100
4 3
5 100
6 4
7 0
8 3
9 10000
/y
*endif
*if *MUST_STATUS LE 2 then
read
'C:\Temp\TestPy\OUC.mon'
'C:\Temp\TestPy\FL230-FMPP.con'
*blank
*endif
*if *MUST_STATUS LE 2 then
constr//excl/read/ 'C:\Temp\TestPy\NonFirmExclude.exc'//
*endif
*if *MUST_STATUS LE 2 then
must
1 0
2 1
3 50000
4 0.03000
5 3
6 1
7 1
8 0.00000
9 0.00000
10 0.00000
/y
*endif
*C AC MENU shifts indirectly recorded
*C >> REF TO DIRECT OUTPUT <<<<<<
tran/direct/f/systlist.lis/print syst/direct/t/
*C >> MENU SHIFT <<<<<<
/3/
MUST
1 0
2 1
3 50000
4 0.02000
5 100
6 0
7 1
8 0.00000
9 0.00000
10 0.00000
/y
*C >> MENU SHIFT <<<<<<
/3/ACCONT
lfopt
adj/1 0/2 0/3 1/4 0/5 1/
gen/1 1/3 0
/sol/1 30/2 0.6/3 0/4 0/5 0.9/7 0.7/8 15//
opt/1 2/2 2
3 0
4 0/
exe
*C
*C Select all constraints
constra
bra/sel/all/
int/sel/all/
fgate/sel/all/
*blank
*C
*C
*C Select all contingencies
contin/sel/all/
*C
dir/f/'Case2_ContSum.lis'
*C >> MODIFIED REF TO EXCEL INTERFACE <<<<<<
constr/print sum/print bviol/
*C >> REF TO TERMINAL OUTPUT <<<<<<
dir/t
cont/sel
All
/constraints/Branch/sel/all
*C >> MODIFIED REF TO EXCEL INTERFACE <<<<<<
dir/f/Case2_MonElRep/ opt/1 100/2 100//pr viol/dir/t//
save/'C:\Temp\TestPy\Case2.acc'
/
/MUST
1 0
2 1
3 50000
4 0.03000
5 3
6 1
7 1
8 0.00000
9 0.00000
10 0.00000
/y
/3/
stop