CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   Advanced post-processing (to Excel) (https://www.cfd-online.com/Forums/cfx/25755-advanced-post-processing-excel.html)

Felix April 30, 2008 15:28

Advanced post-processing (to Excel)
 
Hello,

I'm looking to do some very efficient automatic post-processing but I don't even know if it's feasible so any advice is welcome. What I would like to do is to export data directly from CFX-Post to MS Excel by launching a .cse file and without having to write intermediate files.

The thing is I often have to export data from CFX-Post to Excel for post-processing and presentation of CFD results. So far, I used to export results to a .dat file and then copy-paste the raw data in an Excel sheet. However, the number of files I have to deal with is quite important and the whole copy-paste/convert thing is time-consuming (and also very boring).

I know that it is possible to write an Excel Macro to read many files but I would then have to specify the File.dat names in my spreadsheet and I would like to avoid that as much as possible (and also get rid of the .dat step).

I don't know if this is even possible but I've seen very interesting interaction between Excel and softwares like Pro/Engineer and Catia and it would be amazing to do similar things with CFX.

Thanks for your help and time,

Felix


SpaceDude May 1, 2008 04:45

Re: Advanced post-processing (to Excel)
 
You might consider using a high-level interpreted programming language like python (instead of Excel Macro's), it is ideally suited for these kinds of batch processing tasks. See below:

http://www.python.org/

Though you will need to spend some time learning the language it is well worth it in the long run.

Andrew May 1, 2008 08:32

Re: Advanced post-processing (to Excel)
 
You do not need to explicitly state the names of every "DAT" file before importing into Excel.

Hit Alt+F11 to open the VB editor. In the editor go to tools->references. Add the Microsoft Scripting Runtime reference. This makes the "FileSystemObject" available.

Put all your dat files in the same folder and run this macro. Be sure to replace "c:\location_of_dat_files" with the correct folder.

Sub ImportStuff()

Dim fso As New Scripting.FileSystemObject

Dim f As Scripting.File

Dim w As Worksheet

For Each f In fso.GetFolder("c:\location_of_dat_files").Files

If LCase(f.Name) Like "*.dat" Then

Set w = ActiveWorkbook.Worksheets.Add

w.Name = f.Name

With w.QueryTables.Add("TEXT;" & f.ShortPath, Range("A1"))

.SaveData = True

.TextFileParseType = xlDelimited

.TextFileCommaDelimiter = True

.Refresh False

End With

End If

Next

Set w = Nothing

Set fso = Nothing

End Sub

Felix May 2, 2008 09:49

Re: Advanced post-processing (to Excel)
 
Thank you very much for your macro Andrew. It does a great part of the long, boring job and it does it fast ! I should be able to adapt it so it fits perfectly in the actual sheet I have. I don't have a lot of experience with Excel macros but I'm sure I can specify where to paste the data instead of creating new sheets.

SpaceDude, Python looks like a great software but it would mean that many people here would have to learn it so I'll stick with simple macros as long as possible.

Thanks again,

Felix

Andrew May 2, 2008 13:30

Re: Advanced post-processing (to Excel)
 
To change where it outputs the data, look at the code:

Set w = ActiveWorkbook.Worksheets.Add

w.Name = f.Name

With w.QueryTables.Add("TEXT;" & f.ShortPath, Range("A1"))

Instead of creating a new workbook, you can set w to an existing worksheet:

Set w = ActiveWorkbook.WorkSheets("NAME_OF_WORKSHEET")

You can remove the w.Name line, that just renames the sheet. Then when adding the querytable change the Range("A1") to the appropriate location by putting the origin cell's location within the quotes.


All times are GMT -4. The time now is 05:44.