Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving Excel file in ABAQUS Python script?

Status
Not open for further replies.

thinkvantagedu

Civil/Environmental
Jul 1, 2015
4
Hello,

I recorded a macro in ABAQUS, the last step is importing xy data from ABAQUS to Excel. If I run this python script in MATLAB, I can get an unsaved Excel file named 'Book1'.

The last few lines look like this:

import abq_ExcelUtilities.excelUtilities
abq_ExcelUtilities.excelUtilities.XYtoExcel(xyDataNames='From Current XY Plot',
trueName='From Current XY Plot')

My question is, is there any ABAQUS Python command which allows me to write in my macro Python file and save this Excel file? If I do not save it, I cannot do anything to these data apart from seeing it.

Thank you!
 
Replies continue below

Recommended for you

That would require sending commands to excel directly. I'm not sure what the built in utility does in order to open an excel workbook, but there are a few python modules that can handle this. The one I use is win32com, you should be able to find a bunch of information on it through google, but here's a summary of commands that should work.

xl = win32com.client.Dispatch("Excel.Application") #Fetch the application and assign it to a variable. You can now interact with excel using python/VBA.
xl.DisplayAlerts=False #Get rid of popup alerts that will prevent some scripts from running.
xl.Visible = 1 #Shows the excel app window, useful if you want to mess around issuing commands from the Abaqus GUI and observing what happens in the workbook.
xlBook = xl.Workbooks.Add() #Similar to what Abaqus does, creates a 'Book1'.
xlSheet = xlBook.Sheets(1) #Access a worksheet
xlSheet.Cells(1,1).Value = #Modify cell contents.
xlBook.SaveAs(Filename='Name', FileFormat='Format') #Here is the save command you were looking for.
xl.Application.Quit()

You can also use that to open an existing workbook, modify and save it.
xlBook = xl.Workbooks.Open('path\filename.xls')
xlBook.Save()
 
Hi cooken,

Shall I use this code in ABAQUS or MATLAB? I tried in ABAQUS but it seems that it cannot recognise this syntax (which means I have to follow some Python syntax rules in order to make it work in ABAQUS)
 
Include these and try again.

import win32com.client
from win32com.client import constants
 
hi cooken,

I tried and it gave me this error in MATLAB:

com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Excel', u'SaveAs method of Workbook class failed', u'xlmain11.chm', 0, -2146827284), None)

Abaqus Error: cae exited with an error.

ans =

1

But an empty new book did created, so my question is instead of creating a new book, how to save the existing unsaved book?

Thank you!
 
Seems that SaveAs() does not work with a "\" for the file path. Try "\\" instead ('C:\\Temp\\filename.xls' for example). How annoying.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor