The NextFEM Application Programming Interface (API) allows all the programs with COM interface (Microsoft Office, Autodesk AutoCAD, etc.) to use APIs of NextFEM Designer. In this short guide, we will see how to use results of a model calculated in Designer into an Excel® spreadsheet.

 

Since version 1.5, the NextFEM installer auto-registers the API library into the system. APIs are a group of known functions to be used in programs that allow COM components. In particular, all programs using Visual Basic for Applications (VBA) allows for that. In this tutorial, our aim to use some results in an Excel spreadsheet.

We take as reference the model One.nxf, included in the subfolder “Testcases” of NextFEM Designer installation directory. In the same folder, an Excel sample named “APIsample.xlsm” can be found.

 

 

Designer is processor architecture-dependent, i.e. can be installed in 32 or 64bit flavour. APIs are too, hence you must check for the version of Excel in use. To check it, from inside Excel go to File / Account and click on About button. There you can read the version in use, like in the following figure.

 

If you have 64bit Excel, you need 64bit version of the APIs included in the 64bit version of NextFEM Designer. The same for 32bit APIs.

Open the file  “APIsample.xlsm”, and allows for executions of macro in Excel. You can allow always for macro by change default settings in File / Options / Protection center, Protection center settings button and the Macro settings in the new window that appears.

In the worksheet, you can find 2 buttons. The first one is associated to the model you set into the green cell, and retrieve results from beams.

 

 

To watch how the code has been made, press ALT+F11. The VBA Editor will open, showing the code associated to the spreadsheet. Let’s analyse in detail how to use NextFEM APIs in VBA code.

All the instructions used in the following are documented in nextfem.it/api .

 

Before to start, press the button “Load model and get results”. If no errors are shown, APIs were correctly registered in your system. Otherwise, you can get “Interface not registered” – in this case, go to Tools /References into the VBA editor and check if “NextFEMapi” is present and checked.

 

 

If it is not present, start cmd.exe as Administrator and run this line to register APIs:

 

path\Regasm NextFEMapi.dll /codebase

 

where path is C:\Windows\Microsoft.NET\Framework\v4.0.30319 for 32bit, and in C:\Windows\Microsoft.NET\Framework64\v4.0.30319 in 64bit systems.

 

If the registration fails, you will need to manually create the .tlb file by following these steps:

- remove the previous registration with the command line path\Regasm /u NextFEMapi.dll

- create the NextFEMAPI.tlb file through the command line path\Regasm NextFEMapi.dll /codebase /tlb:NextFEMAPI.tlb

- load the .tlb file just created in Excel from Visual Basic Editor, command Tools / References…

 

 

First of all, an instance of API class must be created. A simple and straightforward solution is to declare it at global level, allowing all functions and procedures to access it.

 

' declaration for all functions

Global nfAPI As New NextFEMapi.API

 

The procedure associated to the button “Load model and get results” is described in the following. First of all, we want to open the model One.nxf, in which results must be stored.

 

    ' open the model - if it is already opened, do nothing

    Call nfAPI.openModel(GetCurDir() & Range("A3"))

 

Then, we want to have the units of length and force in the model in cells B4 and C4:

 

    ' write units of the model

    Range("B4") = nfAPI.getLenUnit()

    Range("C4") = nfAPI.getForceUnit()

 

The same for nodes and elements in the model:

 

    ' number of nodes and elements

    Range("F7") = nfAPI.nodesNumber

    Range("F8") = nfAPI.elemsNumber

 

Now the interesting part. We can get results from a previously computed model and have them in our calculations. For beams, the following functions are available:

 

    ' get beam moment Mz for element no. 1, case "Qk1", station 5 (end of the beam). Last parameter type: 1=N, 2=Vy, 3=Vz, 4=Mt, 5=My, 6=Mz

    Range("B7") = nfAPI.getBeamForce(1, "Qk1", 1, 6, 5)

 

    ' get beam deflection for element no. 2 in the middle of the span, case "Qk1", station 3 (middle of the span). Last parameter type: 1=local x, 2=loca y, 3=local z, 4=local rx, 5=local ry, 6=local rz

    Range("B11") = nfAPI.getBeamDeflection(1, "Qk1", 1, 5, 3)

 

    ' get nodal displacement in global Z from node 2. Global direction: 1=X, 2=Y, 3=Z, 4=RX, 5=RY, 6=RZ

    Range("B14") = nfAPI.getNodalDisp(2, "Qk1", 1, 3)

 

    ' get nodal reaction in global Z from node 1. Global direction: 1=X, 2=Y, 3=Z, 4=RX, 5=RY, 6=RZ

    Range("B17") = nfAPI.getNodalReact(1, "Qk1", 1, 3)

 

In the near future, APIs will be enlarged to see any kind of result and even to input model (nodes, elements, sections and so on).