Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Update load value using API

Creator
Creator

Hello,

 

I'm writing a piece of code which applies windloads to a structure.

In a previous code a allready defined the loadsets containing te default values.

(mainly the location (which nodes) are defined in this initial script)

Based on the user input I want to correct these default values of selected loadsets.

 

Can anyone provide me with the code where I am able to retrieve the current loadmesh (nodal) of each loaddefinition within a loadset

 

I am not able to redefine the loadvalue without losing the information about the location (single node).

(original feLoadMesh.MeshID= (x) required?)

 

Any help would be appreciated.

Thanks in advance

 

 

5 REPLIES 5

Re: Update load value using API

Siemens Phenom Siemens Phenom
Siemens Phenom

Here is an example that expands upon Help Section "5.41.2.4 NextLoad"

 

Uncomment Line 18: 'Call ... to see how to update LoadMesh values.  Looping through is not the only way to update values; you could do a Lm.Get(...) and Lm.Put(...) for each LoadMesh you want to update.

 

Dim App As femap.model
Dim Ls As femap.LoadSet
Dim Lm As femap.LoadMesh

Sub Main

    Set App = feFemap()
    Set Ls = App.feLoadSet

    While Ls.Next()
        Ls.ResetNextLoad( FT_SURF_LOAD, True, 0, False, False )
        While Ls.NextLoad( Lm )
            'List LoadMesh Node IDs to Message  Pane
            App.feAppMessage(FCM_NORMAL,"Set ID:"+Str$( Lm.setID )+", "+"Node ID: "+Str$( Lm.meshID) )
        Wend
    Wend

    'Call UpdateLoads() '-<-Uncomment to update loads

End Sub
Sub UpdateLoads()

        Ls.Reset()
        While Ls.Next()
            Ls.ResetNextLoad( FT_SURF_LOAD, True, 0, False, False )
            While Ls.NextLoad( Lm )
                'App.feAppMessage(FCM_NORMAL,"Set ID:"+Str$( Lm.setID )+", "+"Node ID: "+Str$( Lm.meshID) )
                Lm.LoadValue = 17.0
                Lm.Put( Lm.ID )
            Wend
        Wend

End Sub

 

 

 

 

Re: Update load value using API

Creator
Creator

Thanks for your reply, This helped me a lot!

I updated the code and it now works great in resetting the loadvalue of two loadmeshes in a single loadset.

However I still tink I do not use the code entirely correct.

Here is my modified version of your code:

feLoadSet.Get(6)
feLoadSet.title =  "Load on a node [" + Str$(0.7*Val(dlg.Pressure_Text)) + " N] (x)"
feLoadSet.ResetNextLoad( FT_SURF_LOAD, True, 0, False, False )
While feLoadSet.NextLoad( feLoadMesh )
	feLoadMesh.get(100001)
	feLoadMesh.x = 0.7*Val(dlg.Pressure_Text)
	feLoadMesh.y = 0
	feLoadMesh.Put(100001)
	feLoadMesh.get(100002)
	feLoadMesh.x = 0
	feLoadMesh.y = 0.7*Val(dlg.Pressure_Text)*1040
	feLoadMesh.Put(100002)
Wend
feLoadSet.Put(6)

Loadset 6 contains two loaddefinitions. (first is a force on a node and second is a moment on the node)

 

In a previous script I hard-code defined the loadmesh-ID's in order to call these ID's again within this script.

 

I have one more question about cleaning up my code as given:

I am not able to remove the while loop with this piece of code, than my femap crashes. With this piece of code it seems to me that I am defining the two loaddefinionts twice.. Based on the help section I know I need the nextload() command. but I can't seem to get it working right.

 

Addionally can you recomment a method which does not require hard-code loadmesh ID's. Because the first definition should always be updated fot the x-direction and the second definition should always be updated iny-direction. I hoped to manage this with the 'first()' and 'next()' commands but this also failed.

 

Again thanks for your time and help!

Re: Update load value using API

Siemens Phenom Siemens Phenom
Siemens Phenom

This line in your API -

 

While feLoadSet.NextLoad( feLoadMesh )

already loads the feLoadMesh object for all the loads in the feLoadSet Load Definition, you don't then need to "Get" it from the database.

 

While feLoadSet.NextLoad( feLoadMesh ) ' The while loop gets each feLoadMesh in feLoadSet first to last
	feLoadMesh.x = 0.7*Val(dlg.Pressure_Text) ' edit the load
	feLoadMesh.y = 0
	feLoadMesh.Put(feLoadMesh.ID) ' put it back
Wend

 

Re: Update load value using API

Creator
Creator

This would be true if I wanted to correct all the loadmeshes to an x-value and y-zero state.

However each of my loadmeshes is corrected slightly different:

First has a value in x-direction and y=0

Second has a different value in y-direction and x=0.

 

Therefore I don't think I can create this with a single command.

Instead of the while loop I think my code should look like this

feLoadSet.Get(6)
feLoadSet.title =  "Load on a node [" + Str$(0.7*Val(dlg.Pressure_Text)) + " N] (x)"
feLoadSet.ResetNextLoad( FT_SURF_LOAD, True, 0, False, False )
	feLoadMesh.get(100001)
	feLoadMesh.x = 0.7*Val(dlg.Pressure_Text)
	feLoadMesh.y = 0
	feLoadMesh.Put(100001)
	feLoadMesh.get(100002)
	feLoadMesh.x = 0
	feLoadMesh.y = 0.7*Val(dlg.Pressure_Text)*1040
	feLoadMesh.Put(100002)
feLoadSet.Put(6)

But this does nog work. Which makes sense when reading the help section because it requires Nextload.(feLoadMesh). Any help here?

 

 

I would be able to work around the Get-command with a counter. Combine it with an IF-statement to determinte wether it's the first or the second feLoadMesh. Like this.

 

Counter=0
While feLoadSet.NextLoad( feLoadMesh ) If Counter = 0 Then feLoadMesh.x = 0.7*Val(dlg.Pressure_Text) feLoadMesh.y = 0 feLoadMesh.Put(feLoadMesh.ID) ElseIf Counter = 1 Then feLoadMesh.x = 0 feLoadMesh.y = 0.7*Val(dlg.Pressure_Text)*1040 feLoadMesh.Put(feLoadMesh.ID) End If Counter = Counter+1 Wend

It works, but it's not clean coding I think because usually a while-loop is used for larger sets (possibly with unknown size). Because my loop-size always is 2, I would rather avaoid the entire While-statement.

 

Re: Update load value using API

Siemens Phenom Siemens Phenom
Siemens Phenom

If you know they are the 1st in 2nd in each load set, you can - you should probably put some Else code in case a load is not there with an error message.

 

If feLoadmesh.First() = FE_OK Then
  feLoadmesh.x = 0.7*Val(dlg.Pressure_Text)
  feLoadmesh.y = 0
  feLoadmesh.Put(feLoadmesh.ID)
  If feLoadmesh.Next() = FE_OK Then
    feLoadmesh.x = 0
    feLoadmesh.y = 0.7*Val(dlg.Pressure_Text)*1040
    feLoadmesh.Put(feLoadmesh.ID)
  End If
End If