Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Excel VBA code to generate loadcases

Status
Not open for further replies.

KeesKits2

Mechanical
Apr 16, 2010
2
Hi there,

Via Excel it should be possible to write VBA code to generate loadcases automatically. However, it is difficult to find out with the FEMAP help file how to do this. I tried some code but unfortunately I did something wrong. It generates the load definition cases but doesn't include the actual loads. Can somebody see what I do wrong?
The code looks like this:
Dim App As Object
Set App = GetObject(, "femap.model")

Dim ls As Object
Set ls = App.feLoadSet
Dim fs As Object
Set fs = App.feLoadMesh
Dim ld As Object
Set ld = App.feLoadDefinition


Dim ID As Integer
Dim rc As Integer
Dim Name As String
Dim File As String

Worksheets("Input").Activate
Range("F3").Select
ID = 1


Name = ActiveCell.Offset(ID, -5)


rc = ls.Get(ID)

ls.Title = Name & ID
ls.setID = 1
ls.Active = ID
ls.NLOn = 1
ls.NLIncrements = 10
ls.NLMaxIterPerStep = 25
ls.NLStiffnessMethod = 1
ls.NLStiffnessIter = 5

rc = ls.Put(ID)


rc = ld.Get(ID)

ld.Title = "Pin Loading" & ID
'ld.DataType=7
ld.loadTYPE = FLT_NFORCE
ld.setID = ID

rc = ld.Put(ID)


rc = fs.Get(1)

fs.setID = ID
fs.LoadDefinitionID = ID
fs.meshID = 1274
fs.CSys = 0
fs.Type = 1
fs.dof(0) = 1
fs.dof(1) = 1
fs.Load(0) = 200
fs.Load(1) = 10

rc = fs.Put(1)

rc = fs.Get(2)

fs.setID = ID
fs.LoadDefinitionID = ID
fs.meshID = 2635
fs.CSys = 0
fs.Type = 1
fs.dof(0) = 1
fs.dof(1) = 1
fs.Load(0) = 200
fs.Load(1) = 20

rc = fs.Put(2)

End Sub

Something goes wrong in the "loadmesh" property. Anyone who likes to puzzle?

Grtz,
Kees
 
Replies continue below

Recommended for you

Hey!
I also have the same issue. My code is almost the same.
If you remove the line fs.LoadDefinitionID = ID, you will se the loads in the section "Other Loads/on mesh".

But I do not manage to put the nodal force into the load definition.

Can someone help us?

Thanks!!

Ben
 
Hi jokerbenj,

Finally I figured out the problem myself.
See the enclosed procedure code below which works! I figured this out some time ago (can't remember what was missing at that time), but comparing the codes, I think it had to do with the "active" set.
This code works OK! Try it. The "activeoffset" command refer to a table made in excel. I hope you can read it.


Sub Create_Loads()
'Attach to the model in a FEMAP session that is already running.
Dim femap As Object
Set femap = GetObject(, "femap.model")

Dim LS As Object
Set LS = femap.feLoadSet

Dim LM As Object
Set LM = femap.feLoadMesh

Dim LD As Object
Set LD = femap.feLoadDefinition

Dim Col As Integer
Dim Count_RC As Integer
Dim ID As Long
Dim RC As Long
Dim Row As Long
Dim S_ID As Long
Row = 2
ID = 1
Count_RC = 0

While Worksheets(1).Cells(Row, 1).Value <> 0

'ID = Worksheets(1).Cells(Row, 1).Value

S_ID = Worksheets(1).Cells(Row, 1).Value
RC = LS.Get(S_ID)
LS.Title = Worksheets(1).Cells(Row, 2)
LS.Active = S_ID
LS.SetID = 1
RC = LS.Put(S_ID)

While Worksheets(1).Cells(Row, 3).Value > 0
'ID = 1
'Apply node loads
If Worksheets(1).Cells(Row, 6).Value <> 0 Or _
Worksheets(1).Cells(Row, 7).Value <> 0 Or _
Worksheets(1).Cells(Row, 8).Value <> 0 Then

RC = LD.Get(ID)
LD.Title = Worksheets(1).Cells(Row, 4) & " Force"
LD.loadTYPE = 1 '(FLT_NFORCE)
LD.DataType = 13
LD.SetID = S_ID
RC = LD.Put(ID)
If RC <> -1 Then Count_RC = Count_RC + 1


RC = LM.Get(ID)
LM.meshID = Worksheets(1).Cells(Row, 5) + 10
LM.dof(0) = 1
LM.dof(1) = 1
LM.dof(2) = 1
LM.Load(0) = Worksheets(1).Cells(Row, 6)
LM.Load(1) = Worksheets(1).Cells(Row, 7)
LM.Load(2) = Worksheets(1).Cells(Row, 8)
LM.Type = 1 '(nForce)
LM.LoadDefinitionID = ID
LM.SetID = S_ID
'LM.layer = 1
'LM.Color = 1
'LM.SetID = 1
RC = LM.Put(ID)
If RC <> -1 Then Count_RC = Count_RC + 1
End If

'Apply node moments
If Worksheets(1).Cells(Row, 9).Value <> 0 Or _
Worksheets(1).Cells(Row, 10).Value <> 0 Or _
Worksheets(1).Cells(Row, 11).Value <> 0 Then
ID = ID + 1
RC = LD.Get(ID)
LD.Title = Worksheets(1).Cells(Row, 4) & " Moment"
LD.loadTYPE = 2 '(FLT_NMOMENT)
LD.DataType = 13
LD.SetID = S_ID
RC = LD.Put(ID)
If RC <> -1 Then Count_RC = Count_RC + 1


RC = LM.Get(ID)
LM.meshID = Worksheets(1).Cells(Row, 5)
LM.dof(0) = 1
LM.dof(1) = 1
LM.dof(2) = 1
LM.Load(0) = Worksheets(1).Cells(Row, 9)
LM.Load(1) = Worksheets(1).Cells(Row, 10)
LM.Load(2) = Worksheets(1).Cells(Row, 111)
LM.Type = 2 '(nMoment)
LM.LoadDefinitionID = ID
LM.SetID = S_ID
'LM.layer = 1
'LM.Color = 1
'LM.SetID = 1
RC = LM.Put(ID)
If RC <> -1 Then Count_RC = Count_RC + 1
End If
ID = ID + 1
Row = Row + 1


Wend
Row = Row + 1

Wend

'Combine the loadcases
Worksheets("Overview").Activate
For Col = 3 To 23

S_ID = Cells(1, Col).Value
RC = LS.Get(S_ID)
LS.Title = Cells(2, Col)
LS.Active = S_ID
LS.SetID = 1
RC = LS.Put(S_ID)

For Row = 7 To 30
If Cells(Row, Col) = "x" Then
RC = femap.feLoadCombine(Cells(Row, 1), S_ID, 1)
End If
Next Row
Next Col




MsgBox ("Amount of error codes is " & Count_RC)



End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor