cancel
Showing results for 
Search instead for 
Did you mean: 

Load input - FEMAP API

Creator
Creator

Hi all,

 

I have created a code to allow me to put loads into femap using input from excel. It seems to work a bit, however there a two things bothering me about it and I cant seem to fix them.

 

The first thing is I cannot edit the loads in Femap. I can see the loads but cannot use Edit Load Definition or Edit where applied. 

.

The second thing, it creates vectors by combining load (e.g. Fx+Fy -> Fxy), which I find annoying. I'd rather see an Fx and an Fy for instance seperately.

 

Can anyone help me sort this out? As I am still pretty new to programming any general improvements, comments or tips are appreciated as well. The code is provided below.

 

Thanks and regards,

Marcel

 

'Sub for creating the load input from block input in excel - WORKS Partially
Sub LoadInput()

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

'Femap object to make load set
Dim ls As Object
Set ls = femap.feLoadSet

'Dim general input
Dim start_column As Integer
Dim start_row As Integer
Dim iRow As Integer
Dim N_loads As Integer

'If block input is moved, below needs to be changed
start_row = Range("C2")
start_column = Range("C3")
N_loads = Range("C4")
'--------------------------------------------------

'Dim input
Dim title As String
Dim ID, color, layer As Integer
Dim Ltype As String
Dim NTP As String

Dim Ax#, Ay#, Az#, Arx#, Ary#, Arz#

'Loop though all definitions
iRow = start_row
For i = 1 To N_loads

    'Define a BC set
    Dim LSID As Long
    Dim Fx, Fy, Fz, Mx, My, Mz As Double

    LSID = Cells(iRow, start_column + 1)
    ls.ID = LSID
    ls.title = Cells(iRow, start_column + 2)
        'Add bodyloads
        ls.BodyAccelOn = True
        Ax = Cells(iRow, start_column + 16)
        Ay = Cells(iRow, start_column + 17)
        Az = Cells(iRow, start_column + 18)
        Arx = Cells(iRow, start_column + 19)
        Ary = Cells(iRow, start_column + 20)
        Arz = Cells(iRow, start_column + 21)
        ls.vBodyAccel = Array(Ax, Ay, Az, Arx, Ary, Arz)
        
    ls.Put (LSID)
    ls.Active = LSID
    
    Ltype = Cells(iRow, start_column + 8)
    
    If Ltype = 0 Then
        Exit Sub
    Else
    End If
    
    'Specify the input for creation of each constraint defintion
    title = Cells(iRow, start_column + 3)
    
    ID = Cells(iRow, start_column + 5)
    color = Cells(iRow, start_column + 6)
    layer = Cells(iRow, start_column + 7)
    
    NTP = Cells(iRow, start_column + 9)
    Fx = Cells(iRow, start_column + 10)
    Fy = Cells(iRow, start_column + 11)
    Fz = Cells(iRow, start_column + 12)
    Mx = Cells(iRow, start_column + 13)
    My = Cells(iRow, start_column + 14)
    Mz = Cells(iRow, start_column + 15)
        
    Load1 = Array(Fx, Fy, Fz)
    Load2 = Array(Mx, My, Mz)
    
    'If load type <=4, then nodal loads are selected
    If Ltype <= 4 Then
    Call NodeLoads(LSID, title, ID, color, layer, Ltype, Load1, Load2, iRow, start_column)
    Else
    'If load type >4 <=8, then point loads are selected
    If Ltype <= 8 Then
    Call PointLoads(LSID, title, ID, color, layer, Ltype, Load1, Load2, iRow, start_column)
    Else
    'If load type >8 <=16, then curve loads are selected
    If Ltype < 16 Then
    Call CurveLoads(LSID, title, ID, color, layer, Ltype, NTP, Load1, Load2, iRow, start_column)
    Else
    'If load type >16 <=21, then surfaces loads are selected
    If Ltype < 21 Then
    Call SurfaceLoads(LSID, title, ID, color, layer, Ltype, NTP, Load1, Load2, iRow, start_column)
    
    Else
        Exit Sub
    End If
    End If
    End If
    End If
    
iRow = iRow + 1
    
Next i

femap.feViewRegenerate (0)
End Sub

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


'Define load conditions on Nodes, Forces and moments, Works (partially)
Private Sub NodeLoads(LSID, title, ID, color, layer, Ltype, Load1, Load2, iRow, start_column)

'Connect to Femap
Dim femap As Object
Set femap = GetObject(, "femap.model")

Dim LDef As Object
Set LDef = femap.feLoadDefinition

Dim Lm As Object
Set Lm = femap.feLoadMesh
    
    'Select type for chosen loadtype(Force, Translation, velocity or acceleration)
    Select Case Ltype
    Case Is = 1
        Lm.Type = 1
        LDef.Loadtype = FMLT_NFORCE
    Case Is = 2
        Lm.Type = 3
        LDef.Loadtype = FMLT_NDISPLACEMENT
    Case Is = 3
        Lm.Type = 5
        LDef.Loadtype = FMLT_NVELOCITY
    Case Is = 4
        Lm.Type = 7
        LDef.Loadtype = FMLT_NACCELERATION
    Case Else
        Exit Sub
    End Select
         
    'Set definition for the BC's in the set defined above
    LdefID = LDef.NextEmptyID
    LDef.SetID = LSID
    LDef.title = title & " " & "F,T"
    LDef.DataType = FT_SURF_LOAD
    LDef.Put (LdefID)
    LDef.Active = LdefID
    
    'Define the individual load conditions, Forces, translations
    Lm.meshID = ID
    Lm.csys = 0
         
    LMID = Lm.NextEmptyID
    Lm.LoadDefinitionID = LdefID
    Lm.layer = layer
    Lm.color = color
    Lm.Load(0) = Load1(0)
    Lm.Load(1) = Load1(1)
    Lm.Load(2) = Load1(2)
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID)
        
'Repeat the above for moments or rotations
    
    'Select type for chosen loadtype(Force, Translation, velocity or acceleration)
    Select Case Ltype
    Case Is = 1
        Lm.Type = 2
        LDef.Loadtype = FMLT_NMOMENT
    Case Is = 2
        Lm.Type = 4
        LDef.Loadtype = FMLT_NROTDISPLACEMENT
    Case Is = 3
        Lm.Type = 6
        LDef.Loadtype = FMLT_NROTVELOCITY
    Case Is = 4
        Lm.Type = 8
        LDef.Loadtype = FMLT_NROTACCELERATION
    Case Else
        Exit Sub
    End Select
    
    'Set definition for the BC's in the set defined above
    LdefID2 = LdefID + 1
    LDef.SetID = LSID
    LDef.title = title & " " & "M,R"
    LDef.DataType = FT_SURF_LOAD
    LDef.Put (LdefID2)
    LDef.Active = LdefID2
    
    'Define the individual load conditions, Moments
    Lm.meshID = ID
    Lm.csys = 0
    LMID2 = LMID + 1
    Lm.LoadDefinitionID = LdefID2
    Lm.layer = layer
    Lm.color = color
    Lm.Load(0) = Load2(0)
    Lm.Load(1) = Load2(1)
    Lm.Load(2) = Load2(2)
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID2)
    
End Sub

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'Define load conditions on Points, Forces and moments, Works (Partially)
Private Sub PointLoads(LSID, title, ID, color, layer, Ltype, Load1, Load2, iRow, start_column)

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

Dim LDef As Object
Set LDef = femap.feLoadDefinition

Dim Lm As Object
Set Lm = femap.feLoadGeom

    'Select type for chosen loadtype(Force, Translation, velocity or acceleration)
    Select Case Ltype
    Case Is = 5
        Lm.Type = 81
        LDef.Loadtype = FLT_PNFORCE
    Case Is = 6
        Lm.Type = 83
        LDef.Loadtype = FLT_PNDISPLACEMENT
    Case Is = 7
        Lm.Type = 85
        LDef.Loadtype = FLT_PNVELOCITY
    Case Is = 8
        Lm.Type = 87
        LDef.Loadtype = FLT_PNACCELERATION
    Case Else
        Exit Sub
    End Select
         
    'Set definition for the BC's in the set defined above
    LdefID = LDef.NextEmptyID
    LDef.SetID = LSID
    LDef.title = title & " " & "F,T"
    LDef.Put (LdefID)
    LDef.Active = LdefID

    'Define the individual load conditions, Forces, translations
    Lm.geomID = ID
    Lm.csys = 0
    LMID = Lm.NextEmptyID
    Lm.LoadDefinitionID = LdefID
    Lm.geomtype = 3
    Lm.layer = layer
    Lm.color = color
    Lm.expanded = True
    Lm.Load(0) = Load1(0)
    Lm.Load(1) = Load1(1)
    Lm.Load(2) = Load1(2)
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID)
        
'Repeat above for moments or rotations

    'Set definition for the BC's in the set defined above
    LdefID2 = LdefID + 1
    LDef.SetID = LSID
    LDef.title = title & " " & "M,R"
    LDef.Put (LdefID2)
    LDef.Active = LdefID2
    
    'Define the individual load conditions, Moments
    Lm.geomID = ID
    Lm.csys = 0
    
    'Select type for chosen loadtype(Force, Translation, velocity or acceleration)
    Select Case Ltype
    Case Is = 5
        Lm.Type = 82
        LDef.Loadtype = FLT_PNMOMENT
    Case Is = 6
        Lm.Type = 84
        LDef.Loadtype = FLT_PNROTDISPLACEMENT
    Case Is = 7
        Lm.Type = 86
        LDef.Loadtype = FLT_PNROTVELOCITY
    Case Is = 8
        Lm.Type = 88
        LDef.Loadtype = FLT_PNROTACCELERATION
    Case Else
        Exit Sub
    End Select
    
    LMID2 = LMID + 1
    Lm.LoadDefinitionID = LdefID2
    Lm.geomtype = 3
    Lm.layer = layer
    Lm.color = color
    Lm.expanded = True
    Lm.Load(0) = Load2(0)
    Lm.Load(1) = Load2(1)
    Lm.Load(2) = Load2(2)
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID2)
    
End Sub

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'Define load conditions on Curves, Forces and pressure, Works (Partially)
Private Sub CurveLoads(LSID, title, ID, color, layer, Ltype, NTP, Load1, Load2, iRow, start_column)

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

Dim LDef As Object
Set LDef = femap.feLoadDefinition

Dim Lm As Object
Set Lm = femap.feLoadGeom

    'Select type for chosen loadtype(Force, Translation, velocity or acceleration)
    Select Case Ltype
    Case Is = 9
        Lm.Type = 121
        LDef.Loadtype = FLT_CNFORCE
        Lm.geomtype = 4
    Case Is = 10
        Lm.Type = 122
        LDef.Loadtype = FLT_CNFORCEPERLEN
        Lm.geomtype = 4

    Case Else
        Exit Sub
    End Select
         
    'Set definition for the BC's in the set defined above
    LdefID = LDef.NextEmptyID
    LDef.SetID = LSID
    LDef.title = title & " " & "F,T"
    LDef.Put (LdefID)
    LDef.Active = LdefID

    'Define the individual load conditions, Forces, translations

    Lm.geomID = ID
    Lm.csys = 0
        
    LMID = Lm.NextEmptyID
    Lm.LoadDefinitionID = LdefID
    
    Lm.layer = layer
    Lm.color = color
    Lm.expanded = True
    Lm.Load(0) = Load1(0)
    Lm.Load(1) = Load1(1)
    Lm.Load(2) = Load1(2)
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID)
          
End Sub

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'Define load conditions on Surfaces, Forces and pressure, Works (Partially)
Private Sub SurfaceLoads(LSID, title, ID, color, layer, Ltype, NTP, Load1, Load2, iRow, start_column)

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

Dim LDef As Object
Set LDef = femap.feLoadDefinition

Dim Lm As Object
Set Lm = femap.feLoadGeom

    'Select type for chosen loadtype(Force, Translation, velocity or acceleration)
    Select Case Ltype
    Case Is = 16
        Lm.Type = 161
        LDef.Loadtype = FLT_SNFORCE
        Lm.geomtype = 5
    Case Is = 17
        Lm.Type = 162
        LDef.Loadtype = FLT_SNFORCEPERAREA
        Lm.geomtype = 5
    Case Is = 18
        Lm.Type = 163
        LDef.Loadtype = FLT_SNFORCEATNODE
        Lm.geomtype = 5
    Case Is = 19
        Lm.Type = 178
        LDef.Loadtype = FLT_SEPRESSURE
        Lm.geomtype = 8
    Case Is = 20
        Lm.Type = 184
        LDef.Loadtype = FLT_SNPRESSURE
        Lm.geomtype = 5
    Case Is = 21
        Lm.Type = 185
        LDef.Loadtype = FLT_SNTOTALPRESSURE
        Lm.geomtype = 5
    Case Else
        Exit Sub
    End Select
         
    'Set definition for the BC's in the set defined above
    LdefID = LDef.NextEmptyID
    LDef.SetID = LSID
    LDef.title = title & " " & "F,T"
    LDef.Put (LdefID)
    LDef.Active = LdefID

    'Define the individual load conditions, Forces, translations
    If NTP = "Yes" Then
        Lm.dirmode = 4
        Lm.dirID = ID
    Else
    End If
    
    Lm.geomID = ID
    Lm.csys = 0
        
    LMID = Lm.NextEmptyID
    Lm.LoadDefinitionID = LdefID
    
    Lm.layer = layer
    Lm.color = color
    Lm.expanded = True
    Lm.Load(0) = Load1(0)
    Lm.Load(1) = Load1(1)
    Lm.Load(2) = Load1(2)
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID)
          
End Sub
10 REPLIES

Re: Load input - FEMAP API

Siemens Experimenter Siemens Experimenter
Siemens Experimenter
Hey Marcel,

The issue with not being able to edit your loads, only seems to appear on your geometric loads not mesh. This seems to be due to the fat that you are not seeing the DataType for those loads. Just include LDef.DataType = FT_GEOM_LOAD in Point, Curve and Surface Loads. With this you should be able to see the vectored components for each force.

-Andrew

Re: Load input - FEMAP API

Creator
Creator

Hi Andrew,

 

Thanks for you reply. It does not work for me unfortunately. With the addtion you suggested I still cannot modify point loads. Also Node load cannot be modified in my model..

 

Do have any other ideas?

 

Regards,

Marcel

Re: Load input - FEMAP API

Siemens Genius Siemens Genius
Siemens Genius

Followon to what Andrew said...

 

I didn't go through all of the code but just focused on the nodal forces. This is basically your code, but with one omission fixed up:


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

    Dim ls As Object
    Set ls = App.feLoadSet

    Dim LDef As Object
    Set LDef = App.feLoadDefinition

    Dim Lm As Object
    Set Lm = App.feLoadMesh

    ' Additional data type declarations
    Dim LSID As Long
    Dim Ax As Double
    Dim Ay As Double
    Dim Az As Double
    Dim Arx As Double
    Dim Ary As Double
    Dim Arz As Double
    Dim LDefid As Long
    Dim LMID As Long


    ' Create the load set
    'LSID = Cells(iRow, start_column + 1)
    LSID = App.Info_NextID( FT_LOAD_DIR )
    ls.ID = LSID
    'ls.title = Cells(iRow, start_column + 2)
    'ls.title = "test"
    'Add bodyloads
    ls.BodyAccelOn = True
    'Ax = Cells(iRow, start_column + 16)
    'Ay = Cells(iRow, start_column + 17)
    'Az = Cells(iRow, start_column + 18)
    'Arx = Cells(iRow, start_column + 19)
    'Ary = Cells(iRow, start_column + 20)
    'Arz = Cells(iRow, start_column + 21)
    Ax = 10
    Ay = 20
    Az = 30
    Arx = 10
    Ary = 20
    Arz = 30
    ls.vBodyAccel = Array(Ax, Ay, Az, Arx, Ary, Arz)
    ls.BodyAccelOn = True


    ls.Put (LSID)


    ' Create the load definition
    'Lm.type = 1
    'LDef.loadType = FMLT_NFORCE

    LDef.loadType = FLT_NFORCE
    Lm.type = LDef.loadType

    LDef.setID = LSID
    LDefid = LDef.NextEmptyID
    'LDef.title = title & " " & "F,T"
    LDef.title = "test load definition"
    LDef.dataType = FT_SURF_LOAD
    LDef.Put (LDefid)
    LDef.Active = LDefid


    ' Create mesh load
    Lm.meshID = 1
    Lm.CSys = 0

    Lm.setID = LSID



    LMID = Lm.NextEmptyID
    Lm.LoadDefinitionID = LDefid
    Lm.load(0) = 70
    Lm.load(1) = 80
    Lm.load(2) = 90
    Lm.XOn = 1
    Lm.YOn = 1
    Lm.ZOn = 1
    Lm.Put (LMID)

    
End Sub

 

The biggest omission was that you didn't set a setID for the LoadMesh object. Without it, it doesn't go into the correct location.

 

Now, for some general tips that will make your life easier

  • Variable declaration
    • You declared your FEMAP objects as the "object" data type. This works, but there's two issues.
      • First is late binding (not necessarily a bad thing if that's what you want), but there is a performance penalty for it. Basically, when your code is being run, the interpreter doesn't know anything about the data type beforehand so there's an extra overhead to figure it out at runtime
      • Secondly, when you're writing the code, you get no code completion. There isn't any performance penalty associated with this, it just makes things harder unless you're really familiar with the API and its calls
      • It's much better to declare something as say "Dim lm as femap.loadmesh" instead
    • The object name for your FEMAP object was "femap"
      • I'm actually a little surprised that VBA even allowed this (I suspect you didn't reference the tlb?) but even though it "works" I'm going to discourage it because your variable name is basically the same as the data type now. It's no different than declaring something like "Dim Long as Long". Even if VBA were to allow it, it's pretty confusing. On top of that, if you were to ever port your code over to a strongly typed language, there would be a fair amount of cleanup that you'd have to do
      • While VBA doesn't require that you declare most variables prior to their use, it's something I do recommend. This is purely a personal thing for me, so you don't really have to do it, but I find that it makes debugging a lot easier when you combine it with "Option Explicit" at the beginning of your program. That forces VBA to require that everything be declared prior to use. The benefit is that you'll get runtime errors when you have typos in your variable names, rather than the program just running on fat dumb and happy with some unknown default value (usually zero but you never know)
  • Load Set object
    • Not much to comment on here, except that if you define a body load, you need to turn it on. You'll see the line "ls.BodyAccelOn = True" that was added to your code to turn on the body accelerations
  • Load Definition object
    • There was a mistake when the loadtype was set
      • You used FMLT_NFORCE which is from the zMapOutput enum and is technically the wrong one to use
      • The correct one is from zLoadType and is FLT_NFORCE
      • Enums are just lists that evaluate to integers and in this case, FMLT_NFORCE = FLT_NFORCE = 1, so there was no side effect, but that certainly won't always be the case
  • Load Mesh object
    • This is where the main problem came in... no setID was set
      • You used variables for various IDs (such as LSID for the load set id), which is a good thing. Avoid hard coding these wherever possible. Another approach that's a little shorter is to just reference the ID property of the object you need. In this case:
        • lm.setID = ls.ID
          lm.LoadDefintionID = LDef.ID
          lm.type = LDef.loadType
        • Whenever you create loads, its best that the type matches the definition, so I always just set it equal to the loadType from the definition to make sure they're always in sync
  • By default, loads in FEMAP are displayed as resultants. If you want to change that
    • F6-> Options (Load - Force and Bearing) -> Color Mode (3..Entity, Components)
  • Some more miscellaneous stuff
    • Common properties, such as setID, LoadDefinitionID and loadType for the loadMesh object don't have to be set more than once. If you're looping on something, the fewer times you set these values (each one requires a COM call and has a transactional overhead), the faster your program will run
    • Generally speaking, when you're creating LBC's in FEMAP if you can't either edit the LBC value or where it's applied, that's a good indication that something was done incorrectly. All LBC's created in the API should be editable via the GUI
      • If you run into problems, my recommendation is create one by hand first, then inspect the properties in the API for the definition as well as the LBC object to help figure out what has to be set

Re: Load input - FEMAP API

Creator
Creator

Hi,

 

First of all, thank you for your extensive reply. I will go though the points and improve my code.

 

One main thing I have been wondering about, your code, like all I have seen with the first two lines, do not run from VBA directly if I try it on my PC. That's the reason I used the femap "object" and code in VBA directly, which indeed does not have code completion.

 

Your code does run from the Femap API window. Do I need to turn something on to be able to run such code from VBA directly? Then I could code in the API window in femap and just copy the code to my excel-VBA tool.

 

Thanks again!

 

Regards,

Marcel

Re: Load input - FEMAP API

Siemens Genius Siemens Genius
Siemens Genius

I can't tell for sure without seeing what's happening on your machine, but I suspect the difference has to do with what I mentioned in my original reply regardin late binding and referencing the type library. 

 

When you don't add a reference to the FEMAP type library in external code (it's essentially done for you in the API programming window), the development environment and the compiler just treat FEMAP as a generic "object." You don't get things such as syntax highlighting or code completion in the IDE and from a program execution standpoint, the interpreter doesn't know anything about the FEMAP object until runtime, and at that point it figures out what to do with all the objects. Additionally, if you don't reference the type library, you can't use FEMAP types, as you've seen (ie having to declare something as an Object type instead of femap.feLoadMesh type). 

 

To add the reference in Excel, in the macro window, go to Tools->References and look for something along the lines for "FEMAP vX.YY.Z Type Library". If you don't see one, click Browse, and then navigate to the root directory for your FEMAP installation and look for the file "femap.tlb".

 

Our type libraries are generally backwards compatible so best practice is to reference the oldest version that you may encounter during deployment. Hopefully that's the current version you have installed, but not always.

 

Once you do that, you can then access the FEMAP objects natively from within Excel.

 

Let's look at an example from Excel with and without the tlb referenced, because I think it sheds light on other issues you're probably seeing

 

Without tlb referenced:

loads_01_code.png

 

Message window result:

loads_02_mw.png

 

As you can see... it "worked," however I'm going to use that term very loosely because it really didn't and it's somewhat of a tricky bug. Now, adding in the TLB, the only difference in the code is in the string printed out:

loads_03_updated_code.png

 

Message window result:

loads_04_mw.png

 

The only difference in the code was the string written out, however the change on the FEMAP side is pretty apparent - the original message came out the wrong color. The reason for this is when you don't reference the type library, you also don't have access to the FEMAP enums, such as FLT_NFORCE or FCM_WARNING. As I mentioned earlier, those are lists that evaluate to integers. Without the type library, those are declared as variants at runtime and likely evaluates to a value of zero.

 

What this means is that everywhere you referenced something like FLT_NFORCE or FLT_NMOMENT.... those are all the same values. This is very likely to cause issues when creating the objects as the properties haven't been set up correctly. You either need to use the actual integer value or reference the type library.

 

A couple of parting throughts...

 

The above example still uses "object" instead of "femap.model" in the example with the type library referenced. The end result is the same now, however it's still late-bound. I try to avoid doing this whenever possible as it's more difficult to program for and there's performance implications, however deployment scenarios are easier because you don't have to make sure references exist. 

 

Lastly, this is one of the big reasons I'm a big proponent of "option explicit" for more complicated programs like this. There are so many places where you could accidentally make a typo and VB trying to be helpful in declaring variables in real-time for you actually ends up biting you because it effectively hides a bug. With that added to the top of your code (works in Excel as well as the API window), you'd get a runtime error at executiion, giving you a good indiction that things won't go as planned.

 

Run this example either in Excel or in FEMAP and it'll help highlight why this is important


Sub Main
    Dim aValue As Long
    Dim bValue As Long
    Dim cValue As Long

    aValue = 2
    bValue = 3
    cValue = aValeu + bValue

    MsgBox (Str$(cValue))

End Sub

Re: Load input - FEMAP API

Creator
Creator

Hi,

 

Thanks for your reply. I think I understand better now. I have referenced the TLB file (it was not referenced before). 

 

However, I think there's something else wrong with the settings on my machine as even the simple example you provided (sub Runfemap()) does not work when I type over the code. It says, "this property or method is not supported by this object", applicable on the line with RC. 

 

Also the modified code regarding the load still does not work. It provides an error at the second line at Set app: "Compiling error, Sub or function is undefined"

 

 

When I turn off the type library again, the error on the modified code regaring the load changes to "Compiling error, a by the user defined data type is not defined". The other error does not change.

 

Any ideas what could cause these errors? I did have femap on during the tests above.

 

Regards,

Marcel

 

Re: Load input - FEMAP API

Siemens Genius Siemens Genius
Siemens Genius

Most likely either a typo or you didn't actually reference the tlb. I think the dialog in Excel is kind of confusing. If you browse for the tlb and select it, all that does is add it to the list. You then need to scroll down the list and click the checkbox to turn it on.

 

Beyond that, can't really tell anything more without seeing the code.

Re: Load input - FEMAP API

Creator
Creator

I dont think its a typo or an error in the referencing. See attached pictures. Any other ideas?

Re: Load input - FEMAP API

Siemens Genius Siemens Genius
Siemens Genius

1 - The feFemap() call is something we added back around v10 to allow API programs within the API programming window to access the session they're being run from. It's similar to GetObject(), however is only available within the API Programming Window. If you're porting programs over to other environments, you need to replace with either CreateObject("femap.model") or GetObject(, "femap.model"), depending on your requirements

 

2 - The feMessageClear() method was not added to FEMAP until v11.2... Looks like you have the v11.1.2 tlb referenced. TLBs are backwards compatible but not forwards compatible in the sense that you can't make a call from a version newer than the one you have referenced. Since you can only make calls that are defined in the TLB you'll either need to avoid that call, reference a newer version of the TLB, or install a newer version of FEMAP