Jump to content
guilrod

How can I use a cf variable in a pf environment?

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...