Cancel
Showing results for 
Search instead for 
Did you mean: 

Reg:Executing Recorded Macro from Femap API using Excel VBA:

Creator
Creator
Spoiler

Hello to One and All,

 

   I am trying to automate an analysis using the macro recorded in femap api. Presently iam trying to run the recorded macro (Femap API - Program File) using Excel VBA.

 

 Iam relatively new to programming and It would be of great help if i can get an input on why my recorded macro program file is not running even after i select the macro manually to run. The code is as follows,

 

Sub Main()

 

    Dim fm As femap.Model
    Set fm = CreateObject("femap.Model")
    rc = fm.feAppVisible(True)

    Dim appExcel As Excel.Application
    Set appExcel = GetObject(, "Excel.Application")

    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet

    Set wb = appExcel.ActiveWorkbook
    Set ws = wb.ActiveSheet

    Dim excelArray As Variant

    Row = 2
    lastRow = 76
    Col = 1

    excelArray = ws.Range(ws.Cells(Row, Col), ws.Cells(lastRow, Col + 3)).Value2

    Dim n As femap.Point
    Set n = fm.fePoint


    For i = 1 To lastRow - 1
        n.ID = excelArray(i, 1)
        n.x = excelArray(i, 2)
        n.y = excelArray(i, 3)
        n.Z = excelArray(i, 4)
        n.Put (n.ID)
    Next i

    rc = fm.feViewRegenerate(0)

    Set appExcel = Nothing
 
    rc = fm.feFileProgramRun(False, True, True, "6640_Test_Model Automisation Demo.pro")

 

End Sub

 

Hoping for a positive reply.

 

Thanks in advance.

 

Best Regards,

Sanjay Gopi.

5 REPLIES 5

Re: Reg:Executing Recorded Macro from Femap API using Excel VBA:

Siemens Phenom Siemens Phenom
Siemens Phenom

Hello,

 

I believe you always need to use the full path to your program file when working in Excel:


rc = fm.feFileProgramRun(False, True, True, "C:\[DIRECTORY]\6640_Test_Model Automisation Demo.pro")

Also, is your intention to keep FEMAP open? You can do that by dimensioning your FEMAP object as Public:


Public fm As femap.model

Sub Main()

    'Dim fm As femap.Model
    Set fm = CreateObject("femap.Model")
    rc = fm.feAppVisible(True)
    '...

 

Just as a final note, please be careful with program files - each click and action must be carefully recorded to ensure the correct behavior. Default settings in dialog boxes that are initalized in the FEMAP user interface will not be captured by the program file unless explicitly "clicked".

Re: Reg:Executing Recorded Macro from Femap API using Excel VBA:

Creator
Creator

(view in My Videos)
Hello,

 

   Thanks a lot for your valuable solution. But to explain my issue a bit clearer, I have attached a video, please feel free to have a small look over it.

 

It would be very helpful if you could provide some inputs w.r.t the following questions,

 

1. As in the video, I want Femap to run the automation without displaying the model created in the window. I tried to use the command feAppVisible(False) but the whole window closes without running the analysis.

 

2. Mainly I want to learn a way So that I can tell Femap to wait until the program file ends and collects the output after the analysis is completed and then save the model (Last 30 sec of the video). Here in the video, you can observe that the running analysis closes before Femap cold attach the generated results.

 

I would be really thankful if you could help me with a way to overcome these two issues as I am not able to go ahead with my Automization which is the main part of my thesis study.

 

Hoping for a positive reply.

 

Thanks in advance.

 

Best Regards,

Sanjay Gopi.

 

Re: Reg:Executing Recorded Macro from Femap API using Excel VBA:

Creator
Creator

Hello,

 

    The code that i am using is as follows,

 

Thánks in advance.

 

Public App1 As femap.model

Sub
Main Dim App1 As femap.model Set App1 = feFemap() Dim App As Object Dim rc As Long Set App = CreateObject("femap.model") rc = App.feAppVisible(True) Dim appExcel As Excel.Application Set appExcel = GetObject(,"Excel.Application") Dim wb As Excel.Workbook Dim ws As Excel.Worksheet Set wb = appExcel.ActiveWorkbook Set ws = wb.ActiveSheet Dim excelArray As Variant Row = 2 lastRow = 77 Col = 1 excelArray = ws.Range( ws.Cells(Row,Col) , ws.Cells(lastRow,Col+3) ).Value2 Dim n As femap.Point Set n = App.fePoint For i = 1 To lastRow-1 n.ID = excelArray(i, 1) n.x = excelArray(i, 2) n.y = excelArray(i, 3) n.z = excelArray(i, 4) n.Put( n.ID ) Next i rc = App.feViewRegenerate( 0 ) Set appExcel = Nothing rc = App.feFileProgramRun( False, True, True, "C:\\Users\\sgopi\\Desktop\\6640_Automation\\6640_Model without Hole.pro" ) End Sub

 

Highlighted

Re: Reg:Executing Recorded Macro from Femap API using Excel VBA:

Gears Legend Gears Legend
Gears Legend

Hello,

 

I think your code is wrong because of two things:

 

1. You should use the following code to waiting your program termination (your macro closing before end of your PRO file):

While App.feFileProgramRunning = FE_OK
Wend

2. If you would like to running an analisys, your analisys will run paralel with your macro in other thread. I doesn't know API method to check the termination of the Analysis running. But I think you can do the following:

  - the Analyze command should be the last command in your PRO file

  - you should check the LOG file in your macro (BAS file) for text "NX Nastran finished" (last line) in a cycle

  - after that you can use other commands in your macro (f.e. Regenerate View, Save), or run an another PRO file (with waiting to program termination too)

 

Best regards

 

Peter Kaderasz

 

 

 

Re: Reg:Executing Recorded Macro from Femap API using Excel VBA:

Creator
Creator

Hello Peter Kaderasz,

 

       Thanks a lot for your valuable reply. Will try it out.

 

Also it would be of great help if you could give your insight on the following issue,

 

While running the femap api i.e during the recorded macro run (Program file), if i start using other window of the femap the Api program run terminates. It shows the following error,

 

Unable to set focus to control 11151. Try slowing down the program file.

 

I have used #Delay() command to considerably slow down my Program file.

 

The program file (recorded macro) runs when i leave my Computer idle without working on other application. But as i told earlier, if i start working on any other application, the API program(Program file) fails to complete.

 

Is there a way to lock the API program to the perticular active window of femap..??

 

Any sugessions will be welcomed greatly.

 

Hoping for a positive reply.

 

Best Regards,

Sanjay Gopi.