Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

[FEMAP API] How to halt VBA code until Nastran has finished calculating?

Status
Not open for further replies.

Zembla

Aerospace
Aug 14, 2012
1
Hi,

I'm developing a macro in Excel which generates an analysis case, and then subsequently reads out certain areas of the f06 output file. In order to properly implement such a function I would need to be able to halt my code once it runs Nastran so that the proceeding steps are only executed after the output file has been successfully created.

I have been looking through the documentation on VBA and the FEMAP API help file, but so far I haven't really found anything that seemed like an appropriate way to implement this. While I'm continuing my search, I'm wondering, maybe somebody who frequents this forum has encountered a similar situation where they needed something similar?

Any help would be appreciated!

kind regards,
Z
 
Replies continue below

Recommended for you

Z,

Perhaps something similar to the following.

Call it from your routine by:
RunNastran("C:\mypath\myfile.bdf")

Code:
Sub RunNastran(FilenameAndPath As String)
' Send a file with full path to this subroutine
' The command will be run in a shell window

Dim WshShell As Object
Dim ShellCmd As String

Dim FilePath As String
Dim FileName As String      'executable file name

FileName = Dir(FilenameAndPath)	'Dir returns the name of the file
FilePath = Left(FilenameAndPath, Len(FilenameAndPath) - Len(FileName) - 1)

Set WshShell = CreateObject("WScript.Shell")

' Setting the window directory to the incoming file location
WshShell.CurrentDirectory = FilePath

' chr(34) is a double quote (used if spaces in the path)
' add additional arguments to the end of the ShellCmd variable as needed.
ShellCmd = chr(34) & "C:\MSC.Software\MD_Nastran\20101\bin\mdnastran.exe" & chr(34) _
	& " " _
	& chr(34) & FileName & chr(34)

' Run options: See [URL unfurl="true"]http://ss64.com/vb/run.html[/URL] for more options.
' 1 displays the shell window
' True waits for the command to complete

WshShell.Run ShellCmd, 1, True

Set WshShell = Nothing

End Sub

Danny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor