As an exercise, I am trying to code a flat rectangular plate that is uni-directionally loaded from start to finish using API. I was able to successfully create geometry, materials, properties, and elements but I am currently stuck when trying to apply a load to one of my curves. I am able to create a load set and a load definition, but when trying to load the geometry nothing seems to happen. The load portion of my code is below:
'Create Load Set
Dim ls As Object
Set ls = App.feLoadSet
ls.setID = 1
ls.title = "Fy"
'Create Load Definition for Fy_bot Dim loadDef As femap.LoadDefinition Set loadDef = App.feLoadDefinition loadDef.title = "Fy_bot" loadDef.loadType = FLT_CNFORCE 'FEMAP Constant loadDef.dataType = FT_GEOM_LOAD 'Entity Type loadDef.setID = 1 loadDef.Put(1)
'Create Load in Fy_bot Dim load As femap.LoadGeom Set load = App.feLoadGeom 'Int geom ID - ID of the point, curve, or surface that is loaded load.geomID = 5 'I want to load Curve 5 'Variant vdof - flags indicating which components are enabled for vector loads Dim v3 As Variant Set v3 = load.vdof v3(0) = 1 'I am declaring all 3 XYZ DOF active v3(1) = 1 ' " " v3(2) = 1 ' " " load.vdof = v3 'Variant vload - The load values. . .X,Y,Z components are located in load(0),load(1),load(2) Dim v4 As Variant Set v4 = load.vload v4(0) = 0 v4(1) = 1 v4(2) = 0 load.vload = v4 'Int LoadDefinitionID - The ID of the load definition that contains this load (0 = None) load.LoadDefinitionID = 1 'Int dirmode - The direction setting for the load: 1 = vector load.dirmode = 1 'Int variation - The load variation mode: 0 = None/Constant load.variation = 0 'Bool midside - If True, then loads at midside nodes are adjusted during load expansion to provide uniform loading load.midside = True load.Put(1)
Does any of my code jump out to anyone? I am very new to programming and API, so I might be way off with my understanding of the LoadGeom Object.
Thanks in advance!
Solved! Go to Solution.
Loads and boundary conditions are some of the tricker things to get right in API world simply because there's a lot of options and it's sometimes easy to get one of them wrong. One of the things I usually recommend when creating them programmatically is to first create one in the UI, then use the watch window to inspect various properties to make sure you've got them set correctly. Additionally, if you try to either edit the load or where the load is applied in the UI and nothing happens (you don't get a select dialog or a load definition dialog), you'll know there's something awry.
In your case, you missed out on setting two properties on your load object - the set ID (it gets initialzied to whatever the active set ID is in your model, but it's normally best to set it manually; also it should match the set ID on the definition), as well as the load type (again, should match the definition
load.LoadDefinitionID = loadDef.ID load.setID = loadDef.setID load.type = loadDef.loadType
The way that you decided to define the load is okay if you're specifying loads by component, however if you specify via a vector, you need to specify the vector itself (vdirbase and vdirection). This is treated as a unit vector and the "load" you enter into the form is a multipler. That's specified on load(0). So...
load.vdirbase = Array( 0, 0, 0 ) load.vdirection = Array( 0, 1, 0 ) load.load( 0 ) = 5
You should be good with those changes.
It had turned out that a big mistake was that my loadset was not active, so it was not being displayed. Once active, I was able to assign properties and troubleshoot much easier. Thanks for your help and advice with debugging!
For anyone hoping to see the end result, here is the functional portion of the script. It loads the top and bottom curves of my rectangular plate with -1 and 1 respectively:
'Create Load Set Dim ls As Object Set ls = App.feLoadSet ls.Get(1) ls.setID = 1 ls.title = "Fy" ls.Put(1) Dim loadDef As Object Set loadDef = App.feLoadDefinition Dim load As Object Set load = App.feLoadGeom Dim loadTitles As Variant loadTitles = Array("Fy_bot","Fy_top") Dim loadValues As Variant loadValues = Array(1,-1) Dim loadCurves As Variant loadCurves = Array(5,7) Dim j As Integer For i = 1 To 2 j = i - 1 'Load Definition loadDef.Get(i) loadDef.title = loadTitles(j) loadDef.loadType = 121 'Femap Constant loadDef.dataType = 14 'Entity Type loadDef.setID = 1 loadDef.Put(i) 'Load Geometry load.Get(i) loadDef.Get(i) load.LoadDefinitionID = loadDef.ID load.setID = loadDef.setID load.type = loadDef.loadType load.geomID = loadCurves(j) load.vdof = Array(1,1,1) 'I am declaring all 3 XYZ DOF active load.vdirbase = Array(0,0,0) load.vdirection = Array(0,1,0) load.load(1) = loadValues(j) load.variation = 0 load.midside = True load.Put(i) Next ls.Active = 1