Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

FEMAP API Woes - Element.GetGeomPropArray usage

Status
Not open for further replies.

J.D.

Mechanical
Jun 10, 2018
2
Hello Group.

I'm new to API usage/programming (and not much of a programmer in general), but have been trying to "Frankenstein" via examples a script that takes a selected group of elements, provides centroid coordinates and mass of each element, and essentially writes to a file a point cloud of element data that can be manipulated in Excel to generate distributed and cumulative axial and radial mass distributions for the selected element group. (Eventually I would like to perform the Excel operations in the script (sorting by coordinate bands, summing for each band, etc.), but first things first....).

Program is below. Note, for general information only, Z-direction is along FEM centerline, X and Y are transverse. I could make these variable, but for now plan to routinely set FEM up this way.

Things were going just fine until I added the "Dim mt" and "Set mt" definitions such that I could pull density for a named material and output that for the elements in a listing rather than just the material. (Actually, I later want to multiply that density by the element volume to produce an element mass value.) After that change, the Element.GetGeomPropArray operation seemed to product no meaningful information. Null (?) For example, after printing the numelem variable, the program returns "0". Program runs to completion without error messages in this case, but no output. And attempts to print other Element.GetGeomPropArray returned variables produces an error message regarding the variable.

Comment out the "Dim mt" and "Set mt" and respective operations, and remove rho from print request, and I get printed data for selected elements as expected.

I'm sure I am missing something very fundamental, but have spend hours trying to resolve. First resort is usually to do my best to work problem out for myself. Now becoming desperate.... winky smile

Any input would very much appreciated!

Thanks,
JD

=================

Sub Main

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

Dim mt As femap.Matl
Set mt = App.feMatl

Dim Element As femap.Elem
Set Element = App.feElem

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

Dim fName As String
Dim setID As Long
Dim numElem As Long
Dim entID As Variant
Dim propID As Variant
Dim matlID As Variant
Dim elemTYPE As Variant
Dim topology As Variant
Dim vCG As Variant
Dim vAXIAL As Double
Dim vRADIAL As Double
Dim length As Variant
Dim area As Variant
Dim volume As Variant
Dim rho As Double
Dim matNum As Variant

If App.feFileGetName( "Select File to Write Data To", "Text File (*.txt)", "*.txt", False, fName ) = FE_OK Then

Open fName For Output As #1

Print #1, "Element_ID " & " axial_distance " & " radial_distance " & " el_volume " & " material " & " density "

setID = 1

Element.setID=elSet.Select(FT_ELEM, True, "Select Elements to Include in Mass Distribution" )

Element.GetGeomPropArray(setID, numElem, entID, propID, matlID, elemTYPE, topology, vCG, length, area, volume)

REM Test Print
Print #1, numElem

For i = 0 To numElem - 1

vAXIAL=vCG(3*i+2)
vRADIAL=((vCG(3*i)^2)+(vCG(3*i+1)^2))^0.5
matNum = matlID(i)
mt.Get(matNum)
rho = mt.mval(49)

Print #1, entID(i) & " " & vAXIAL & " " & vRADIAL & " " & volume(i) & " " & matlID(i)& " " & rho
Next

Close #1

End If

End Sub
 
Replies continue below

Recommended for you

=====================================================

Fix from other forum
:

Try this. You aren't that far off, but there were a few issues. First, most API calls return a return code...that should be tested for FE_OK..or some failure code, but not set into an ID like you had for the elSet.Select call. Secondly, and more importantly when an API call asks for the ID of a Set, you should always use SetObject.ID... in your case elSet.ID. You were passing the variable "setID" which you hard-coded to 1. I think that it just happened to work in your case before adding the "Dim mt...." code because elSet.ID must have been equal to 1. After you added that, it must have been something else and you weren't checking the elements you thought you were. Hope this helps.



The HTML Clipboard
Sub Main

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

Dim mt As femap.Matl
Set mt = App.feMatl

Dim Element As femap.Elem
Set Element = App.feElem

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

Dim fName As String
Dim numElem As Long
Dim entID As Variant
Dim propID As Variant
Dim matlID As Variant
Dim elemTYPE As Variant
Dim topology As Variant
Dim vCG As Variant
Dim vAXIAL As Double
Dim vRADIAL As Double
Dim length As Variant
Dim area As Variant
Dim volume As Variant
Dim rho As Double
Dim matNum As Variant

If App.feFileGetName( "Select File to Write Data To", "Text File (*.txt)", "*.txt", False, fName ) = FE_OK Then

Open fName For Output As #1

Print #1, "Element_ID " & " axial_distance " & " radial_distance " & " el_volume " & " material " & " density "

If elSet.Select(FT_ELEM, True, "Select Elements to Include in Mass Distribution" ) = FE_OK Then

If Element.GetGeomPropArray( elSet.ID, numElem, entID, propID, matlID, elemTYPE, topology, vCG, length, area, volume) Then

Print #1, numElem

For i = 0 To numElem - 1

vAXIAL=vCG(3*i+2)
vRADIAL=((vCG(3*i)^2)+(vCG(3*i+1)^2))^0.5
matNum = matlID(i)
If mt.Get(matNum) = FE_OK Then
rho = mt.mval(49)
Else
rho = 0.0
End If

Print #1, entID(i) & " " & vAXIAL & " " & vRADIAL & " " & volume(i) & " " & matlID(i)& " " & rho

Next

End If
End If

Close #1

End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor