I have written the following API to creat load from output (Model->Load->from output...). Since it has to run after the fist analysis is done I created a separate Macro rather than having the codes in the same (main) macro. However, it seems that some of the object created in the first macro is not recognized by the second one. It is obviously my lack of programming skills but I hope I could get some help with the following:
1. Is there a way to paus the code untill an analysis is done? something that says "check if results are availible before continuing".
2. Do you have a better idea of how to create Load from output or would you do the same?
3. How to make objects created in another Macro accessible?
Thank you in advance!
Sub Main Dim App As femap.model Set App = feFemap() Dim Thermal As femap.LoadSet Set Thermal = App.feLoadSet Thermal.title = "Thermal analysis" Thermal.Put(Thermal.NextEmptyID) Dim LoadDef_NodeTemp As femap.LoadDefinition Set LoadDef_NodeTemp = App.feLoadDefinition LoadDef_NodeTemp.title = "Temperature from output" LoadDef_NodeTemp.loadType = FLT_NTEMPERATURE LoadDef_NodeTemp.dataType = FT_NTHERM_LOAD LoadDef_NodeTemp.setID = Thermal.ID LoadDef_NodeTemp.Put(LoadDef_NodeTemp.NextEmptyID ) Dim nArray2 As Variant Dim vArray2 As Variant Dim fArray2 As Variant Dim NumbOfNodes As Long Dim NodeID As femap.Set Set NodeID = App.feSet NodeID.AddAll(FT_NODE) NodeID.GetArray( NumbOfNodes, nArray2 ) Dim NodeTempOut As femap.Output Set NodeTempOut = App.feOutput NodeTempOut.setID = 1 ' output set 1 NodeTempOut.Get( 31 ) ' Temperature NodeTempOut.GetOutputListAtSet(NodeID.ID,Null,vArray2) Dim LoadNodeTemp As femap.LoadNTemp Set LoadNodeTemp =App.feLoadNTemp LoadNodeTemp.setID=Thermal.ID LoadNodeTemp.LoadDefinitionID=LoadDef_NodeTemp.ID LoadNodeTemp.AddArray(NumbOfNodes,True,False,nArray2,vArray2,fArray2) 'Thermal analysis Dim StatAnalys28 As femap.AnalysisMgr Set StatAnalys28 = App.feAnalysisMgr StatAnalys28.title="Thermal analysis" StatAnalys28.Solver=36 ' NX Nastran StatAnalys28.AnalysisType=1 'static StatAnalys28.BCSet(0)=BC.ID StatAnalys28.BCSet(2)=Thermal.ID StatAnalys28.Output(2)=-1 StatAnalys28.Output(16)=-1 StatAnalys28.Put(StatAnalys28.NextEmptyID) StatAnalys28.Analyze(StatAnalys28.ID) End Sub
Solved! Go to Solution.
I am not sure why you are trying to run a static analysis after creating a load set with Nodal Temperatures. Perhaps you could share more of your goals?
Anyway, to wait for an Analysis to finish you will want to use
We have an example under Custom Tools, Event Callback, Startloop.bas. Essentially, this method lets you use a variety of FEMAP "triggers" to kick off a program. The Custom Tools example shows how to change the plate thickness property and wait for a solve each time.
Below I have an example that might be closer to what you're looking for. This will use the same script and simply wait to solve until the number of Results Sets = 3. With a little more logic, you can probably use this framework to modify your loads between solves.
Sub Main Dim App As femap.model Set App = feFemap() Dim a As AnalysisMgr Set a = App.feAnalysisMgr a.Get( 1 ) a.Analyze(1) Dim oSet As femap.Set Set oSet = App.feSet oSet.Clear() oSet.AddAll( FT_OUT_CASE ) If oSet.Count > 3 Then 'This will produce 3 Results Sets App.feAppEventCallback( FEVENT_RESULTSEND, "" ) 'Turn event callback off Else path = "C:\temp\Event_Callback_2.BAS" 'Path to this script App.feAppEventCallback( FEVENT_RESULTSEND, path ) End If End Sub