×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

saving Excel file in ABAQUS Python script?

saving Excel file in ABAQUS Python script?

saving Excel file in ABAQUS Python script?

(OP)
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!

RE: saving Excel file in ABAQUS Python script?

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()

RE: saving Excel file in ABAQUS Python script?

Rather than write to an excel workbook, you can write the data to a plain text file using a comma delimiter. You can then read your data into excel easily. You can use the savetxt function from numpy for this (http://docs.scipy.org/doc/numpy/reference/generate...)

RE: saving Excel file in ABAQUS Python script?

(OP)
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)

RE: saving Excel file in ABAQUS Python script?

Include these and try again.

import win32com.client
from win32com.client import constants

RE: saving Excel file in ABAQUS Python script?

(OP)
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!

RE: saving Excel file in ABAQUS Python script?

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources