Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

API Events handling

Status
Not open for further replies.

Marce2

Mechanical
Sep 10, 2013
2
Hey there guys!

I'm using Visual Basic code within the Visual Studio IDE to automate an analysis within Femap. Up until now, I've just told VS to wait for a time duration I specify while Femap is running an analysis, s.t. Femap has time to generate the data that VS will Get and then write it into an excel file for me.

I want to transition to using Femap Events. These allow us to generate and send messages that go into a message queue that can be accessed by other programs. The section there in the API reference gives sample code, though it isn't VB. I haven't been able to correctly modify it to run in VS, and so I've been researching message queues in VS (MSMQ) but it's byzantine and complicated and I haven't had any joy yet.

I was wondering if anyone had a similar experience, or perhaps even had some sample code out there that shows how to tell VS to listen for messages, tells Femap to generate them, and tells VS to act upon getting the message.

Thanks in advance for the help!
Marce
 
Replies continue below

Recommended for you

Hey you guys! I've managed to get a solution to this problem, and I wanted to share!

I spoke with Siemens' tech support, and they gave me the following, comments mine.

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim fam As femap.AnalysisMgr
fam = app.feAnalysisMgr
fam.Analyze(1)
CheckAnalysisState(app.Info_Count(femap.zDataType.FT_OUT_CASE))
'this line calls the private sub below. Place it immediately beneath the analyze command
End Sub

Private Sub CheckAnalysisState(OutputCount As Long)
Do While app.Info_Count(femap.zDataType.FT_OUT_CASE) = OutputCount
Threading.Thread.Sleep(100)
'the number here is time in milliseconds. Set it higher than 100, maybe 2000 or so
app.feAppMessage(femap.zMessageColor.FCM_COMMAND, "Waiting for analysis...")
'this line writes to the message box inside femap
Loop
MsgBox("Analysis imported... do something")
End Sub

This code watches the output count within femap and puts the thread to sleep until the output count has changed, which happens after automatic loading of results has been completed.

In order to use it, you must include a reference to the femap type library in your development environment. In Visual Studio, go to the Project menu, then hit add reference, then find femap.tlb in the femap directory.

Essentially, I stuck the private sub CheckAnalysisState at the top of my code, then called it (with CheckAnalysisState(app.info ... FT_Out_Case) right after the I issued the analysis command. Works like a charm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor