Cancel
Showing results for 
Search instead for 
Did you mean: 

CSV file from GetAllArray Method

Creator
Creator

I have the following code that I want to output in CSV format.  I am struggling with the correct formatting.

A small sample output of the program is this:-

 

The coordinate of Node 325 is (16, 10, 0).
The coordinate of Node 215 is (16, 14, 0).
Load ID 48, Propety ID 7, Elem Type 6, Nodes 325, Nodes 215

 

I can produce a CSV file but can not populate it correctly. I am trying to setup a table that has a seperate column for each output above and loops through until no more data is left to display in a table.  

e.g.

Column 1 is Load ID

Column 2 Property ID

Column 3 Elem Type

Column 4 Node A

Column 5 Node B

Column 6 Coordinates A

Column 7 Coordinates B

 

My attempt was integrating Counts in a while loop

e.g. C0 = entID , C1 = propID, C2=elemType etc all representing columns.

Then using .Addcolumn, example:

 

The HTML Clipboard

data.AddColumn( False, False, FT_ELEM, 0, "Load ID",FCT_DOUBLE, numElem, C0, C1, newID )
data.AddColumn( False, False, FT_ELEM, 0, "Property ID", FCT_DOUBLE, numElem, C0, C2, newID )
data.AddColumn( False, False, FT_ELEM, 0, "Element Type", FCT_DOUBLE, numElem, C0, C3, newID )

 

Any help or tips for a better approach would be appreciated. 

 

 

 

 

Original code shown here:-

 

The HTML Clipboard

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




Const MAX_NODES_PER_ELEM = 20



Dim fNode As Object

Dim fSet As Object

Dim nodeID As Long

Dim xcoordinate As String

Dim ycoordinate As String

Dim zcoordinate As String

Dim nodeIDstr As String

Dim xyz(3) As Double

Dim vXYZ As Variant

Set fNode=App.feNode

Dim fnodeset As Object

Set fnodeset=App.feSet

Set fNode=App.feNode

Set fSet=App.feSet

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

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

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


Dim fstr As String
Dim elemmode As Long

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

Dim p As femap.Prop
Set p = App.feProp

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



Dim El As Object
Set El = App.feElem
Dim elSet As Object
Set elSet = App.feSet
Dim numElem As Long
Dim entID As Variant
Dim propID As Variant
Dim elemType As Variant
Dim topology As Variant
Dim Lyr As Variant
Dim color As Variant
Dim formulation As Variant
Dim orient As Variant
Dim offset As Variant
Dim release As Variant
Dim orientSET As Variant
Dim orientID As Variant
Dim nodes As Variant
Dim connectTYPE As Variant
Dim connectSEG As Variant

Dim Msg As String

Dim findElemType As Integer
findElemType = 6 'Linear Plate


rc = elSet.AddRule(findElemType, FGD_ELEM_BYTYPE)
rc = El.GetAllArray(elSet.ID, numElem, entID, propID, _
elemType, topology, Lyr, color, formulation,orient,offset, _
release, orientSET, orientID, nodes, connectTYPE, connectSEG )


vXYZ = xyz(0)
e.type = 6
eset.AddRule(e.type,FGD_ELEM_BYTYPE)
fSet.AddSetRule(eset.ID,FGD_NODE_ONELEM)
nodeID=fSet.First


App.feAppMessage(FCL_NORMAL, _
" Number of Cbush elements: " + Str$(numElem))
For i = 0 To numElem-1
' Load ID, property, type, and nodes into String for display
Msg = "Load ID" + Str$(entID(i)) + ","+ " Propety ID"+Str$(propID(i)) + ", "+ _
    "Elem Type" + Str$(elemType(i))


    For u = 0 To MAX_NODES_PER_ELEM-1
If nodes(i*MAX_NODES_PER_ELEM + u) <> 0 Then

    vc=fNode.Get(nodeID)
    vc=App.feCoordOnNode(nodeID, vXYZ)

    nodeID= nodes(i*MAX_NODES_PER_ELEM + u)
    ID = nodeID
    nodeID=fSet.Next
    x=vXYZ(0)
    y=vXYZ(1)
    z=vXYZ(2)
    nodeIDstr=ID
    xcoordinate=x
    ycoordinate=y
    zcoordinate=z




Msg = Msg + ", " +"Nodes" + Str$(nodes(i*MAX_NODES_PER_ELEM + u))

App.feAppMessage(0,"The coordinate of Node "+nodeIDstr+" is ("+xcoordinate+", "+ycoordinate+", "+zcoordinate+").")

End If


Next u

App.feAppMessage(FCM_NORMAL, Msg)

Next i



End Sub

2 REPLIES

Re: CSV file from GetAllArray Method

Legend
Legend

Hello oSam,

 

If you would like to create a CSV file, you can make it using WinWrap Basic language (from FEMAP API Programming Pane):

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

    Dim nodeID As Long
    Dim xcoordinate As String
    Dim ycoordinate As String
    Dim zcoordinate As String

    nodeID=325
    xcoordinate="16"
    ycoordinate="10"
    zcoordinate="0"

    Open "D:\Test_API.csv" For Output As #1
    'The following line write text "The coordinate of Node; 325;is (;16;,;10;,;0;)"
    Print #1, "The coordinate of Node;"+Str(nodeID)+";is (;"+xcoordinate+";,;"+ycoordinate+";,;"+zcoordinate+";)"
    'The following line write text "325;16;10;0"
    Print #1, Trim(Str(nodeID))+";"+xcoordinate+";"+ycoordinate+";"+zcoordinate
    Close #1

End Sub

 

If you use Visual Studio, you can use StreamWriter object:

 

objWriter = New System.IO.StreamWriter("D:\Test_API.csv")
objWriter.WriteLine("Text to CSV file")
objWriter.Close()

 

Best regard

 

Peter Kaderasz

Re: CSV file from GetAllArray Method

Creator
Creator

Hello Peter, I appreciate your response but the API I am trying to construct would go through all the produced outputs and sort them into a table in a CSV file. I have created csv files with no trouble before but can not seem to get it to populate correctly this time. I am trying to aim for an automatic population of the data tables as mentioned in my original post.