Cancel
Showing results for 
Search instead for 
Did you mean: 

directly define output sets by API code

Experimenter
Experimenter

Hi all,

 

actually I start working with FEMAP API, and have a first question:

 

I want to select several output sets (s) and output vectors (v).

 

How can I directly specify s,v in API code - in contrast to visual pick them like shown in the feSelectOutput below?

 

thanks a lot,

 

der Rechenschieber

 

The HTML Clipboard

'Select Output Set and Output Vectors of interest

If App.feSelectOutput( "Select Output Vectors", 0,  3, FOC_ANY, FT_ELEM, False, s, v ) = FE_OK  Then

8 REPLIES

Re: directly define output sets by API code

Siemens Genius Siemens Genius
Siemens Genius

You could add them just like you would with anything else you would in a set object. Remember that sets are only mutually exclusive lists of numbers; they don't have any knowledge about what data type the IDs may be in reference to or if those entities actually exist. 

 

Say the user picks output sets 1, 3 and 5 and vectors 7206, 7207 and 7208 (membrane X, Y and Z)'

 

    Dim s As femap.Set
    Dim v As femap.Set

    Set fs = App.feSet
    Set fs = App.feSet

    s.Add( 1 )
    s.Add( 3 )
    s.Add( 5 )

    v.AddRange( 7206, 7208, 1 )

 

Those aren't the only ways to programmatically add IDs to a set. If you look at the Add* methods for sets in the API reference manual, you can see the rest, such as AddSet, AddRule, AddAll, etc, etc.

 

Re: directly define output sets by API code

Legend
Legend

Hello Pkrien,

 

would you like to write the following:

 

Dim s As femap.Set
Dim v As femap.Set

Set s = App.feSet
Set v = App.feSet

s.Add( 1 )
s.Add( 3 )
s.Add( 5 )

v.AddRange( 7206, 7208, 1 )

 Best regard

 

Peter Kaderasz

Re: directly define output sets by API code

Experimenter
Experimenter

Hi guys & thanks,

 

since I am a total beginner at API programming i really got problems getting into it.

 

basically I got a running API that opens the "SelectOutputVectors" Dialogue Box which lets me manually choose the output sets and output vectors.

 

What I want instead is to choose the output sets (basically all) and a couple of output vectors (let's say 3014 and 3015) within the API program code without displaying the "SelectOutputVectors" Dialogue Box.

...The same with the elements selection....

 

Would appreciate any help, regards,

 

der Rechenschieber

 

 

The HTML Clipboard

'Select Output Set and Output Vectors of interest

If App.feSelectOutput( "Select Output Vectors", 0,  FOT_ANY, FOC_ANY, FT_ELEM, False, s, v ) = FE_OK  Then

'Select Elements of interest

    If e.Select( FT_ELEM, True, "Select Elements" ) = FE_OK Then

Re: directly define output sets by API code

Legend
Legend

Dear Rechenschieber,

 

 

Here is small API example according to your request. There are some comments that can help you understand Femap API. 

 

 

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

    'select all output sets
    Dim outputSets As femap.Set
    Set outputSets = App.feSet
    outputSets.AddAll(FT_OUT_CASE)

     'add vectors 3014, 3015 to set
    Dim vectorSet As femap.Set
    Set vectorSet = App.feSet
	vectorSet.Add(3014)
	vectorSet.Add(3015)

   'select elements using dialog box
	Dim elementSet As femap.Set
	Set elementSet = App.feSet
	elementSet.Select(FT_ELEM, True, "Select Elements")

	'get selected ids set into array ids
	Dim count As Long
	Dim ids As Variant
	elementSet.GetArray(count, ids)

	'display message into femap message box
	App.feAppMessage(FCM_NORMAL, "Number of elements in selection: " & count)

End Sub

Can you share what is the goal of your API program? Maybe we can give few more tips.

Re: directly define output sets by API code

Experimenter
Experimenter

Hi yarko,

 

thanks for help & yes sure I can share my goal with you.

In fact I want to export results to excel. Therefore I took the following API from appliedcax.com

(in fact very helpfull set of APIs you can get there):

 

http://appliedcax.com/femap-apis-importing-and-exporting-data/159-export-results-to-excel 

 

It works fine but since I have to process numerous loadcases I do want to skip the "SelectOutputVectors" Dialogue Box and directly define the output sets (basically all) and a couple of output vectors (let's say 3014 and 3015) within the API program code without displaying the "SelectOutputVectors" Dialogue Box.

 

...The same with the elements selection....

 

 

PS: the data export directly to excel seems to be very slow... maybe i should better export them as .csv or something. But this will be my next tasks.

 

thanks & regards,

 

Philipp

 

 

Re: directly define output sets by API code

Siemens Phenom Siemens Phenom
Siemens Phenom

You can speed up sending results to Excel by (1) using the clipboard or (2) sending values in an array.  The API below will take vectors 3014 and 3015 from all output sets, send them to the Data Table, copy, and paste the values all at once into Excel.  These will be pasted to Sheet 1.  Following that, a quick example of a 2D array is created and sent in bulk to Excel Sheet 2.  Hopefully this helps!

 

Sub Main()

Dim App As femap.model
Set App = feFemap

Dim appExcel As Excel.Application
Set appExcel =  New Excel.Application

Dim wb As Excel.Workbook
Set wb = appExcel.Workbooks.Add

Dim ws As Excel.Worksheet
Set ws = wb.ActiveSheet

appExcel.Visible = True

Dim eSet As femap.Set
Set eSet = App.feSet

Dim ouSetID As Long
Dim minID As Long
Dim maxID As Long
Dim Count As Long
Dim IDen As Long
Dim Row As Long
Dim Col As Long
Dim nCols As Long

Dim minVAL As Double
Dim maxVAL As Double
Dim CurrentData As Double

Dim ID As Variant
Dim Title As Variant
Dim nInd As Variant
Dim dVal As Variant

'ws.Cells( 1, 1 ) ="Output Set ID"'
'ws.Cells( 1, 2 ) ="Element ID"

'****** Revisions ******
Dim oSet As femap.Set
Set oSet = App.feSet

Dim cRes As femap.Results
Set cRes = App.feResults

Dim dTable As femap.DataTable
Set dTable = App.feDataTable

'Add all Output Sets
oSet.AddAll(FT_OUT_CASE)

'Add all Elements
eSet.AddAll(FT_ELEM)


dTable.Lock(False)
While oSet.Next()

    cRes.AddColumn(oSet.CurrentID,3014,False,nCols,nInd)
    cRes.AddColumn(oSet.CurrentID,3015,False,nCols,nInd)

Wend

cRes.Populate()
cRes.SendToDataTable()

'Use the clipboard to quickly copy and paste
dTable.Copy(True )
ws.Range("A2").PasteSpecial(xlPasteAll)

'Make Headers Bold
ws.Rows(2).Font.Bold = True

'Uncomment below for Column Autofit
'ws.Range("A1:ZZ1").Columns.AutoFit


' *************** Alternative Example *********************************
'**************** Send Values as Array ************************
Set ws = wb.Sheets.Add
Dim myArr As Variant
ReDim myArr(eSet.Count,eSet.Count) As Double

a = 100
For i = 0 To 100
    For j = 0 To 100
        myArr(i,j) = a
        a += 1
    Next
Next
ws.Range("A1:B135").Value2 = myArr
'****************************************************************


Set appExcel = Nothing

End Sub

Re: directly define output sets by API code

Experimenter
Experimenter

HiRCatania,

 

worked perfect - thank u alot!

 

Now, my question is, how can I skip excel and directly save the FEMAP data table to a .csv file?

 

thanks again,

 

der Rechenschieber

 

The HTML Clipboard

Sub Main

'Attach To the model In a femap session that Is already running
Dim App As femap.model
Set App = feFemap()
Dim appExcel As Excel.Application
Set appExcel =  New Excel.Application

Dim wb As Excel.Workbook
Set wb = appExcel.Workbooks.Add

Dim ws As Excel.Worksheet
Set ws = wb.ActiveSheet

appExcel.Visible = True

Dim nCols As Long
Dim nInd As Variant
Dim oSet As femap.Set
Set oSet = App.feSet

Dim cRes As femap.Results
Set cRes = App.feResults

Dim dTable As femap.DataTable
Set dTable = App.feDataTable

'Add all Output Sets
oSet.AddAll(FT_OUT_CASE)

dTable.Lock(False)
While oSet.Next()
    cRes.AddColumn(oSet.CurrentID,1,False,nCols,nInd)
    cRes.AddColumn(oSet.CurrentID,2,False,nCols,nInd)
Wend

cRes.Populate()
cRes.SendToDataTable()

'Use the clipboard to quickly copy and paste
dTable.Copy(True )
ws.Cells(2,1).PasteSpecial xlPasteAll

'Make Headers Bold
ws.Rows(2).Font.Bold = True

Set appExcel = Nothing

End Sub

 

 

 

Re: directly define output sets by API code

Siemens Phenom Siemens Phenom
Siemens Phenom

The Data Table has a built-in method ".Save" that can write to a CSV.  In the API below, you are prompted to choose an existing CSV file which returns "fname" as a path.  You could also make use of the WinWrap function "Open" for more customized writing to CSVs.

 

Sub Main

'Attach To the model In a femap session that Is already running
Dim App As femap.model
Set App = feFemap()
'Dim appExcel As Excel.Application
'Set appExcel =  New Excel.Application

'Dim wb As Excel.Workbook
'Set wb = appExcel.Workbooks.Add

'Dim ws As Excel.Worksheet
'Set ws = wb.ActiveSheet

'appExcel.Visible = True

Dim nCols As Long
Dim nInd As Variant
Dim oSet As femap.Set
Set oSet = App.feSet

Dim cRes As femap.Results
Set cRes = App.feResults

Dim dTable As femap.DataTable
Set dTable = App.feDataTable

'Add all Output Sets
oSet.AddAll(FT_OUT_CASE)

'Unlock Data Table
dTable.Lock(False)
While oSet.Next()
    cRes.AddColumn(oSet.CurrentID,1,False,nCols,nInd)
    cRes.AddColumn(oSet.CurrentID,2,False,nCols,nInd)
Wend

cRes.Populate()
cRes.SendToDataTable()

'Use the clipboard to quickly copy and paste
dTable.Copy(True )

'Get file name of csv
Dim fname As String
App.feFileGetName ("Export To CSV", "Comma Seperated File", "*.csv",True,fname)

dTable.Save(True,fname,FSF_CSV)

'ws.Range("A2").PasteSpecial(xlPasteAll)

'Make Headers Bold
'ws.Rows(2).Font.Bold = True

'Set appExcel = Nothing

End Sub