Cancel
Showing results for 
Search instead for 
Did you mean: 

Help Obtaining Cbush Nodes and Coordinates- API

Creator
Creator

I was wondering if there is a way to output the nodes specifically connected to a Cbush. For example, Cbush 1 connected to Node ID 323 and Node ID 525 and their coordinates. I have code that loops through nodes and shows their coordinates and ID.  

 

Code that loops through all nodes:


The HTML Clipboard

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

    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

'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''

    vXYZ = xyz(0)
    rc=fSet.Select(7,True,"Select Nodes")
    nodeID=fSet.First


While nodeID> 0

    rc=fNode.Get(nodeID)
    rc=app.feCoordOnNode(nodeID, vXYZ)
ID=nodeID nodeID=fSet.Next x=vXYZ(0) y=vXYZ(1) z=vXYZ(2) nodeIDstr=ID xcoordinate=x ycoordinate=y zcoordinate=z app.feAppMessage(0,"The coordinate of Node "+nodeIDstr+" is ("+xcoordinate+", "+ycoordinate+", "+zcoordinate+").") Wend End Sub

 Sample output when code is run:

The coordinate of Node 667 is (2, 6, 0).
The coordinate of Node 668 is (14, 4, 0).
The coordinate of Node 669 is (12, 4, 0).
The coordinate of Node 670 is (10, 4, 0) 

 

 

Thank you!

4 REPLIES

Re: Help Obtaining Cbush Nodes and Coordinates- API

Siemens Phenom Siemens Phenom
Siemens Phenom

You are pretty close. To finish this, you can benefit from the ".AddRule" and ".AddSetRule" methods on Set Objects. This will first add all elements of type "CBUSH" (aka a Spring/Damper Femap element type) then grab the nodes from that set in a new set.

In addition, you are using "... As Object" when you create your objects. This is fine, except you lose the IntelliSense that can help steer some programming. Below I have the completed API plus some commented lines that show how you can create Femap-style objects instead.

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

Dim fNode As Object
'Dim fNode As Node


Dim fSet As Object
'Dim fSet As femap.Set

Dim eSet As Object
'Dim eSet as femap.Set

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

Set eSet=app.feSet

Dim e As Elem
Set e = app.feElem

'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''
'Use .type method on element object to make it CBUSH
' *TIP* with your curser somewhere on ".type", hit F1 to jump to the defintion in the FEMAP Help
e.type = FET_L_SPRING

vXYZ = xyz(0)
'rc=fSet.Select(7,True,"Select Nodes")

'Use versatile ".AddRule" method on Set object to add all nodes on CBUSH type elements
eSet.AddRule(e.type,FGD_ELEM_BYTYPE)

'Use versatile ".AddSetRule" method to add all nodes on Elems from eSet
fSet.AddSetRule(eSet.ID,FGD_NODE_ONELEM)
nodeID=fSet.First


While nodeID> 0

rc=fNode.Get(nodeID)
rc=app.feCoordOnNode(nodeID, vXYZ)
ID=nodeID
nodeID=fSet.Next
x=vXYZ(0)
y=vXYZ(1)
z=vXYZ(2)
nodeIDstr=ID
xcoordinate=x
ycoordinate=y
zcoordinate=z


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

Wend


End Sub

Re: Help Obtaining Cbush Nodes and Coordinates- API

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter

Consider using the data table as well.  Enable the data table, then the selector, setting it to "nodes".  You can use the standard dialog selection to select by element and pick your cbush elements.  The info you want will be in the data table.

deleteme1.png

 

Eric Gustafson

Author, Learning Femap

Re: Help Obtaining Cbush Nodes and Coordinates- API

Creator
Creator

Hey guys, thank you for the help. Your posts gave me multiple ideas that I ended up implementing. I went ahead and also integrated more code sourced from the api pdf and older projects.

 

The code now finds the coordinates, cbush Id, property id, elem type, nodes A and B, and lists them accordingly. I will mark this as a solution for anyone who might need the api.

 

A sample output:

The coordinate of Node 229 is (6, 16, 0).
The coordinate of Node 111 is (2, 16, 0).
Load ID 42, Propety ID 7, Elem Type 6, Nodes 229, Nodes 111

 

 

 

code below: 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

Re: Help Obtaining Cbush Nodes and Coordinates- API

Creator
Creator

Hey guys, thank you for the help. Your posts gave me multiple ideas that I ended up implementing. I went ahead and also integrated more code sourced from the api pdf and older projects.

 

The code now finds the coordinates, cbush Id, property id, elem type, nodes A and B, and lists them accordingly. I will mark this as a solution for anyone who might need the api.

 

A sample output:

The coordinate of Node 229 is (6, 16, 0).
The coordinate of Node 111 is (2, 16, 0).
Load ID 42, Propety ID 7, Elem Type 6, Nodes 229, Nodes 111

 

 

 

code below: 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