Showing results for 
Search instead for 
Do you mean 
Reply

Femap API: fetching current open file without saving

My first forum post! 

 

I am programming a Femap API.  Visual Studio 2012, Femap v11.2.2.  The user opens up a read-only Femap file.  In Femap API land, is there a way to fetch the name of this file without saving the Femap session?

 

T

4 REPLIES

Re: Femap API: fetching current open file without saving

Hi,

Depends which type of "femap file" you are referring to:

- if it's a modfem which already exists, then look at App.ModelName

- if it's a solver file, for example if you open a NASTRAN dat file and want to retrieve the file path, the only trick I've found is to use the "group by include" option (cf file > preferences > "create groups from include files"), then you can retrieve the path in the 1rst group's name

- if it's a result file you can use the references (lookfor App.feReference, can't find it in the help section though...)
AP

 

AP

Re: Femap API: fetching current open file without saving

Thanks for the ideas!

 

It's a .modfem which I'm opening from a read-only directory.  I tried the .feAppGetModelName method, and it's throwing me a type mismatch error.  I had originally figured it was due to the "file must be saved first" caveat for this method, but when I tried the code on a save-able .modfem, I was thrown the the same error.

 

I suspect this is a Visual Studio COM library issue, because I get these all the time with Femap API in VS.  I'm just trying to take stabs at what variable is offending VS now? 

 

Dim App As Object = GetObject(, "femap.model")

Dim rc As Boolean

Dim fName As String

Dim fID As long

rc = App.feAppGetModel(fID)

rc = App.feAppGetModelName(fID, fName)

 

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

Re: Femap API: fetching current open file without saving

Hello Taffy,

 

try this:

 

Dim App As femap.model
Set App = feFemap()

Dim fName As String
Dim fID As PortInt
rc = App.feAppGetModel(fID)
rc = App.feAppGetModelName(fID, fName)
MsgBox (fName)

Best regards

 

Peter Kaderasz

Re: Femap API: fetching current open file without saving

I figured it out.  kadpeter, you're recommendation was close!

 

Here is what Patrick K from Siemens suggested, it now works.  I repeat it here as it documents a difference between Basic Femap API and VS .NET API:

 

If you declare femap as an object instead of femap.model type (the latter being early binding), there seems to be issues if the string hasn’t been initialized before passing it in. Not exactly sure why but my guess is that when you’re using late binding, the compiler knows nothing of data types going in or out, they’re basically all objects. Even though it’s technically a string, because it’s NULL at the time, there’s probably some issues with that. Try putting

 

fName=””

 

before the code that pulls out the model name and see if that helps.