cancel
Showing results for 
Search instead for 
Did you mean: 

Api: copy combination loadset

Creator
Creator

Dear All,

Using below prog, am trying to copy a combination from one file to another. It throws an error  at the get combination command saying type mismatch.

Can some one help me out

 

 

Sub copy_combination()

 

Dim app As Object

Set app = GetObject(, "femap.model")

Dim ls1 As Object

Set ls1 = app.feLoadSet

 

Dim scl As Integer

Dim nols As Integer

Dim sclcol() As Long

Dim lscol() As Long

'Set lscol = app.feSet

Dim lsno As Integer

lsno = 151

tmp = ls1.Get(lsno)

MsgBox (ls1.Title)

tmp = ls1.GetCombination(scl, nols, sclcol, lscol)

 

tmp = app.feFileOpen(False, "D:\Devlopment\reclaimer\link-model.modfem")

Dim ls2 As Object

Set ls2 = app.feLoadSet

ls2.Get (lsno)

tmp = ls2.PutCombination(scl, nols, sclcol, lscol)

 

 

End Sub

10 REPLIES

Re: Api: copy combination loadset

Siemens Phenom Siemens Phenom
Siemens Phenom

I made a couple of changes to your code in order to get it to work - a couple of the variables did not match what the API is looking for, the final thing is putting ls2 back into the database, the PutCombination, stores the combination in the ls2 object that's loaded in the API, but not back to the FEMAP database, you need to call a Put on that to get the database updated.

 

The HTML Clipboard

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

    Dim ls1 As Object
    Set ls1 = App.feLoadSet

    Dim scl As Double 'scl is a double
    Dim nols As Long

    Dim sclcol As Variant 'Changed to Variant
    Dim lscol As Variant 'Changed to Variant

    'Set lscol = app.feSet
    Dim lsno As Integer

    lsno = 151
    tmp = ls1.Get(lsno)

    MsgBox (ls1.title)

    tmp = ls1.GetCombination(scl, nols, sclcol, lscol)
    tmp = App.feFileOpen(False, "C:\mastemp\t1.modfem")

    Dim ls2 As Object
    Set ls2 = App.feLoadSet

    ls2.Get (lsno)

    tmp = ls2.PutCombination(scl, nols, sclcol, lscol)
    ls2.Put(lsno) 'Put the LoadSet back to the database
End Sub

Re: Api: copy combination loadset

Creator
Creator

Dear Masherman,

Thank you for the updated version.

Well the error in the getcombination got rectified, but it is not putting the values back into the model.

I am unable to ustand why.

It actually worked once. but never again. 

what mistake am i doing, i dont ustand. 

I tried clossing all files and reopening again. the ls2 loadset no 151 just gets blank.

i copy pasted ur prog, and only changed the directory according to my requirement.

But it dint work. The reference sets are empty.

what else could be the problem. can you help me out.

 

 

 

Re: Api: copy combination loadset

Siemens Phenom Siemens Phenom
Siemens Phenom

The load sets called out in the combination have to exist in the target model.  If they do not, PutCombination will fail.  Do they exist in the target model?

Re: Api: copy combination loadset

Creator
Creator

Yaah, the load nos exist. I also checked if it really points to the right load set by putting loads in the target load set. After i run the prog, the target load set combination becomes blank. 

I also tried the following, i.e., i create a new loadset in the other file.

here the strange problem i face is, loadset no 151 alone gets coppied properly, but any other load set does not get copied properly, copied loadset combination is blank.

So now am really confused as to what is happening with this load combination. why the load set get created but combinations are empty.

all r truely strange.

 

 

 

Sub copy_combination()

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

Dim scl As Double
Dim nols As Long
Dim sclcol As Variant
Dim lscol As Variant
'Set lscol = app.feSet
Dim lsno As Integer
lsno = 151
tmp = ls1.Get(lsno)
MsgBox (ls1.Title)
tmp = ls1.GetCombination(scl, nols, sclcol, lscol)

tmp = app.feFileOpen(False, "D:\Devlopment\reclaimer\link-model.modfem")
Dim ls2 As Object
Set ls2 = app.feLoadSet
'ls2.Get (ls2.NextEmptyID)
ls2.Title = ls1.Title
ls2.IsCombination = True
tmp = ls2.PutCombination(scl, nols, sclcol, lscol)

ls2.Put (ls2.NextEmptyID)

End Sub

Re: Api: copy combination loadset

Siemens Phenom Siemens Phenom
Siemens Phenom

Please send me the two .modfem files so that we can debug this, if you cannot post them to the forum, please send to 

 

sherman dot mark at siemens dot com

 

Mark.

Re: Api: copy combination loadset

Creator
Creator

Was this issue solved? I am also struggling to make the PutCombination method work.

Re: Api: copy combination loadset

Siemens Genius Siemens Genius
Siemens Genius

PBarabas wrote:

Was this issue solved? I am also struggling to make the PutCombination method work.


Can you please be more specific about the problems you're having?

Re: Api: copy combination loadset

Creator
Creator

Hello,

 

this is a simplified script of what I have been doing (in Excel):

 

Sub Test2()

' *** Variable declaration ***

'var. type : Femap
Dim App As Object
Set App = GetObject(, "femap.model")

Dim LC As Object
Set LC = App.feLoadSet

Dim rc As Variant


Dim dOverallScale As Double
Dim nCombo As Integer 'change to long if needed above 32767
Dim dscale() As Double
Dim nSetID() As Integer 'change to long if needed above 32767

ReDim dscale(4)
ReDim nSetID(4)

dOverallScale = 1
nCombo = 4

dscale(0) = 1
dscale(1) = 1.2
dscale(2) = 2.2
dscale(3) = 3.2

nSetID(0) = 1
nSetID(1) = 2
nSetID(2) = 3
nSetID(3) = 4

LC.Title = "Test"
LC.ID = 101
LC.IsCombination = True

rc = LC.Put(101)

'PutCombination( dOverallScale, nCombo, dScale, nSetID )

' REAL8 dOverallScale
' Overall Scale Factor for Nastran LOAD Combination.
'
'INT4 nCombo
' Number of entries in the LOAD Combination.
'
'REAL8 dScale[0..count-1]
' The Scale Factor for the load sets in the Combination.
'
'INT4 nSetID[0..count-1]
' The IDs of the load sets in the Nastran LOAD Combination.
MsgBox ("dOverallScale: " & dOverallScale & vbNewLine _
& "nCombo: " & nCombo & vbNewLine _
& dscale(0) & " x LC_" & nSetID(0) & vbNewLine _
& dscale(1) & " x LC_" & nSetID(1) & vbNewLine _
& dscale(2) & " x LC_" & nSetID(2) & vbNewLine _
& dscale(3) & " x LC_" & nSetID(3))

rc = LC.PutCombination(dOverallScale, nCombo, dscale, nSetID)

End Sub

 

 

The Load Cases 1 to 4 is existing in Femap already. What I can see that this script was creating the Nastran Load Combination 101 as expected, but the referenced sets are none. (I have seen that the previous commenter had the same problem, but the solution was not posted.)

 

LC_femap.jpg

 

 

 

 

Re: Api: copy combination loadset

Siemens Genius Siemens Genius
Siemens Genius

Two things need correction in your code - 

 

1. An array of integers is not the same as an array of longs. Usually for scalar variables, you can get away with mixing and matching (although it's still not a good idea) and real-time casting by the interperter will just take care of things. With arrays, however, that's not possible due to the differences in memory required. The return code from the PutCombination method returns 0 (FE_FAIL) in your code, which indicates that there was an error.

 

In the API documentation, you'll se references to INT2, INT4 and INT8 (16, 32 and 64 bit integers). The vast majority of the time, INT4s (long in VB world) are used. INT2s are only used when wanting to store shorts into UserData objects and INT8s are only used for handling model IDs. It's best to always use the data type specified in the manual for variables that will interface with API calls as this will help avoid problems like this.

 

2. The PutCombination method only sets OLOAD data to the load set object in memory - it doesn't get commited to the database. This needs to be called prior to calling Put to commit the object to the database. We should probably update the documentation for this specific method so it's a little clearer, however a good rule of thumb is that unless the method specifically says you no longer need to call Put, you still need to do so. Off the top of my head, that really only applies to the PutAllArray methods you'll find on various objects.

 

Make those two changes and you should be good to go.