Cancel
Showing results for 
Search instead for 
Did you mean: 

api femap create constrained nodes

Experimenter
Experimenter

I want to create coinstrained nodes from my model , through api . I know the nodes  Id and i need to make them as pinned supports . Is there any way to achieve this ?

5 REPLIES

Re: api femap create constrained nodes

Siemens Phenom Siemens Phenom
Siemens Phenom

This should do it for you.

 

Pinned.png

 


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

    Dim n As Node
    Dim ly As layer
    Dim nSet As Set
    Dim constSet As BCSet
    Dim constDef As BCDefinition
    Dim pin As BCNode

    Set n = App.feNode
    Set ly = App.feLayer
    Set nSet = App.feSet
    Set constSet = App.feBCSet
    Set constDef = App.feBCDefinition
    Set pin = App.feBCNode

    If nSet.Select(FT_NODE,True,"Select Nodes to Pin..") <> FE_OK Then End

    Dim nodeArray() As Variant
    'Dim dofArray() As Boolean
    Dim i As Long, a As Long
    i = 0 : a = 0

    'Constraint Set
    cD_id = constSet.NextEmptyID()
    constSet.title = "API Created Constraints: Pinned"
    constSet.Put(cD_id)

    'Constraint Defintion
    constDef.setID = cD_id
    cD_id = constDef.NextEmptyID
    constDef.title = "Pinned On Nodes"
    constDef.OnType = FT_NODE
    constDef.dataType = FT_BCO 'Help Section 3.3.6 Entity Types
    constDef.Put(cD_id)

    'Populate array with NodeIDs
    While nSet.Next()
        ReDim Preserve nodeArray(i)
        nodeArray(i) = nSet.CurrentID
        i += 1
    Wend

    'Create Pinned Constraints
    With pin
        .setID = cD_id
        .BCDefinitionID = cD_id
        .layer = ly.Active
        .dof(0) = True  : .dof(3) = False
        .dof(1) = True  : .dof(4) = False
        .dof(2) = True  : .dof(5) = False
        .AddArray(nSet.Count,False,nodeArray,0)
        .Put( pin.NextEmptyID() )
    End With

End Sub

Re: api femap create constrained nodes

Experimenter
Experimenter

This works great in femap environment!!!

But i want the api to read the ID nodes from an excel and made them constrained-pinned in femap

Is this possible ?

Re: api femap create constrained nodes

Siemens Phenom Siemens Phenom
Siemens Phenom

I made an example using Excel vba.  You can use the spreadsheet to create the nodes and constraints you are looking for.  I can't post a macro-enabled workbook using this forum, but I've pasted the code below.

 

Nodes_Constraints.gif

 

Script below:

 

Private Sub export()

Dim femap As Object
Set femap = GetObject(, "femap.model")

Dim nd As femap.Node
Dim ly As femap.layer
Set nd = femap.feNode
Set ly = femap.feLayer

Dim nCount As Integer
Dim nodeArray() As Variant, nodeXYZArray() As Variant, layerArray() As Variant
Dim colorArray() As Variant, typeArray() As Variant, defCsysArray() As Variant
Dim outCsysArray() As Variant, permBCArray() As Variant, dofArray() As Variant

Dim i As Integer, a As Integer, b As Integer
i = 0: a = 0: b = 0

RC = femap.feAppMessage(0, "Attached")
'Read down the rows until blank. Fill arrays.
Do While Cells((i + 5), 2) <> ""

ReDim Preserve nodeArray(i)
ReDim Preserve nodeXYZArray(i + a + 2)
ReDim Preserve layerArray(i)
ReDim Preserve colorArray(i)
ReDim Preserve typeArray(i)
ReDim Preserve defCsysArray(i)
ReDim Preserve outCsysArray(i)
ReDim Preserve permBCArray(i + b + 5)
ReDim Preserve dofArray(i + b + 5)


'Node IDs
nodeArray(i) = Cells(i + 5, 2).Value
'Coordinates
nodeXYZArray(i + a) = Cells(i + 5, 3).Value
nodeXYZArray(i + a + 1) = Cells(i + 5, 4).Value
nodeXYZArray(i + a + 2) = Cells(i + 5, 5).Value
'Coordinate System
defCsysArray(i) = Cells(i + 5, 6).Value
typeArray(i) = 0
'Permanet Constraints
permBCArray(i + b) = 0
permBCArray(i + b + 1) = 0
permBCArray(i + b + 2) = 0
permBCArray(i + b + 3) = 0
permBCArray(i + b + 4) = 0
permBCArray(i + b + 5) = 0

'For use later
dofArray(i + b) = Cells(i + 5, 7)
dofArray(i + b + 1) = Cells(i + 5, 8)
dofArray(i + b + 2) = Cells(i + 5, 9)
dofArray(i + b + 3) = Cells(i + 5, 10)
dofArray(i + b + 4) = Cells(i + 5, 11)
dofArray(i + b + 5) = Cells(i + 5, 12)

layerArray(i) = ly.Active
colorArray(i) = 46 'Green Nodes

i = i + 1
a = a + 2
b = b + 5
Loop

'Put all nodes at once. Minimize OLE\COM overhead
nCount = i
RC = nd.PutAllArray(nCount, nodeArray, nodeXYZArray, layerArray, colorArray, typeArray, defCsysArray, outCsysArray, permBCArray)

'Print to Message Pane in FEMAP
If RC = -1 Then
RC = femap.feAppMessage(0, "Nodes Imported Successfully")
Else
RC = femap.feAppMessage(0, "Nodes Not Imported. Please Check Excel Columns.")
End If

'Autoscale and Regenerate
RC = femap.feViewAutoscaleVisible(0, False)
RC = femap.feViewRegenerate(0)

'************************************************************************************
' Create Constraints
'************************************************************************************
'Create Constraint Set and Pinned Constraints
Dim constSet As femap.BCSet
Dim constDef As femap.BCDefinition
Dim pin As femap.BCNode

Set constSet = femap.feBCSet
Set constDef = femap.feBCDefinition
Set pin = femap.feBCNode

'Constraint Set
cD_id = constSet.NextEmptyID()
constSet.Title = "API Constraints: Test"
constSet.Put (cD_id)

'Constraint Defintion
constDef.setID = cD_id
cD_id = constDef.NextEmptyID
constDef.Title = "API Constraint: Test"
constDef.OnType = FT_NODE
constDef.DataType = FT_BCO 'Help Section 3.3.6 Entity Types
constDef.Put (cD_id)

'Create Pinned Constraints
With pin
.setID = cD_id
.BCDefinitionID = cD_id
.layer = ly.Active
.color = 120
' .DOF(0) = True: .DOF(3) = False
' .DOF(1) = True: .DOF(4) = False
' .DOF(2) = True: .DOF(5) = False
RC = .AddArray(nCount, True, nodeArray, dofArray)
RC = .Put(pin.NextEmptyID())
End With

RC = femap.feViewRedraw(0)
RC = femap.feAppUpdatePanes(True)

End Sub

 

 

Re: api femap create constrained nodes

Experimenter
Experimenter

You are the best!!!

Thank you so much, it works perfectly!!

Re: api femap create constrained nodes

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter


To work in all cases, this macro should be corrected : in this version, the value cD_id is modified before the creation of the BCNode. Thus, the constraint is created in a constraints set that does not exist, and in the femap model, we can notice that it appears systematically in the first constraints set. So before correction, it works well if no Constraint Set is already defined.
The correction should be the following : line # 33 must be removed (see below).

 

 

Sub Main

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

    Dim n As Node
    Dim ly As layer
    Dim nSet As Set
    Dim constSet As BCSet
    Dim constDef As BCDefinition
    Dim pin As BCNode

    Set n = App.feNode
    Set ly = App.feLayer
    Set nSet = App.feSet
    Set constSet = App.feBCSet
    Set constDef = App.feBCDefinition
    Set pin = App.feBCNode

    If nSet.Select(FT_NODE,True,"Select Nodes to Pin..") <> FE_OK Then End

    Dim nodeArray() As Variant
    'Dim dofArray() As Boolean
    Dim i As Long, a As Long
    i = 0 : a = 0

    'Constraint Set
    'cD_id = constSet.NextEmptyID()
    cD_id = 2
    constSet.title = "API Created Constraints: Pinned"

    constSet.Put(cD_id)

    'Constraint Defintion
    constDef.setID = cD_id
    '§ 5.9.1  BCDefinition Object Properties BCDefinition objects are always stored with their SetID equal to the setID of the constraint set; however, their IDs simply go from 1 to N.
    ' To find a particular object, you must retrieve each object in the set and check the constraints it contains

    ' To Be Corrected :
    ' => the 'cD_id = constDef.NextEmptyID'  line should be removed from the first version.
    'With it, the pinned constraint can not be created in the right constraint set. cD_id must keep the same value.
    'cD_id = constDef.NextEmptyID
    constDef.title = "Pinned On Nodes"
    constDef.OnType = FT_NODE
    constDef.dataType = FT_BCO 'Help Section 3.3.6 Entity Types
    constDef.Put(cD_id)

    'Populate array with NodeIDs
    While nSet.Next()
        ReDim Preserve nodeArray(i)
        nodeArray(i) = nSet.CurrentID
        i += 1
    Wend

    'Create Pinned Constraints
    With pin
        .setID = cD_id
        .BCDefinitionID = cD_id
        .layer = ly.Active
        .dof(0) = True  : .dof(3) = False
        .dof(1) = True  : .dof(4) = False
        .dof(2) = True  : .dof(5) = False
        .AddArray(nSet.Count,False,nodeArray,0)
        .Put( pin.NextEmptyID() )
    End With

End Sub