How can I use a cf variable in a pf environment?
Hello: I´m triyng to create a png graph from PostFeko script and I wish to use a variable defined in a father script (in CadFeko) for the name of the model. The program give to me the next message:
attempt to index global 'Iteration' (a nil value).
Here are the lines i the programs
In the main program:
...
for Iteration = 1,#f do
pf.Variable
modelName = baseModelName .. '_Iteration_' ..Iteration..'_Polarization_'..Polarization
app:SaveAs(modelName)
...
-- Define the model to open in POSTFEKO
runOutput = cf.Launcher.Run('postfeko', {modelName, '--run-script', 'createAndExportGraph.lua', '--non-interactive'})
...
--------------------------------------------------------------------------------
In the subscript 'createAndExportGraph.lua'
app = pf.GetApplication()
graph = app.CartesianGraphs:Add()
farFieldTrace = graph.Traces:Add(app.Models[1].Configurations[1].FarFields[1])
graph:ExportImage('FarFieldGraph'..Iteration, 'png', 180, 260)
app:Close()
thank´s
Answers
-
Hi guilrod
Unfortunately, accessing CADFEKO variables from POSTFEKO is not directly supported yet. In the workflow where a CADFEKO script is followed by a POSTFEKO one, the parameters are often accepted as input for the post-processing script (defining them at the top of the script or adding a GUI prompting to enter the value). When sharing a single value (for example, iterating over the number of frequencies), it might be the simplest to transfer the value manually and adding another loop on the POSTFEKO side. If you want to automate this step, one option would be to write/read the parameters to/from a file using standard Lua commands (I/O library).
On the CADFEKO side you could, for example, do something like the following (oversimplified but shows the idea):
numFreq = #f file = io.open('vars.txt', 'w') file:write(tostring(numFreq)) file:close()
Then, in the POSTFEKO script you could access the same variable (again, oversimplified):
file = io.open('vars.txt', 'r') readLine = file:read('*line') file:close() numFreq = tonumber(readLine)
There are a lot of resources generally available on the internet to help with these Lua commands.
Perhaps someone else has a better suggestion for an improved workflow or can share a more elegant solution for transferring variables between CADFEKO and POSTFEKO.
0 -
If the number of iterations matches the number of frequency points, you could query the axis of the result in POSTFEKO to obtain this information. It all depends on what value(s) you are trying to share between CADFEKO and POSTFEKO.
0 -
Thank you MvdM. Is working!
0