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
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