Scripting error: attempt to index global 'pf' (a nil value)

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi,

 

I am trying to run a POSTFEKO script from my CADFEKO script. But when I want to run a function from my POSTFEKO script in my CADFEKO script it gives the following error: 'attempt to index global 'pf' (a nil value)'

The code looks still messy, but I want to know why I cannot do a pf.GetApplication() when running from a CADFEKO project.

 

Unable to find an attachment - read this blog

Tagged:

Answers

  • Madelé
    Madelé
    Altair Employee
    edited October 2018

    Hi Meerten

     

    As far as I know, you cannot call a function that uses POSTFEKO commands directly from within a CADFEKO script like in your example. The commands will be executed in CADFEKO at that point and 'pf', the POSTFEKO namespace would not be available (see the User Manual chapter 'Scripts and Application Programming Interface (API)' or Example Guide I1 'Introduction to Application Automation' for more information). You would have to use a command in the CADFEKO script that opens POSTFEKO with the post-processing script that you wish to execute. You could try something like the following:

     

    cf.Launcher.Run('postfeko', {'modelname.fek', '--run-script', 'createAndExportGraph.lua', '--non-interactive'})

     

    You can run POSTFEKO in non-interactive mode, or you can leave out the last command if you wish to see the execution of commands or interact with POSTFEKO as the commands are being executed. You can close POSTFEKO in the post-processing script by using app:Close().

     

    Here is a very simple example where CADFEKO is only used to run POSTFEKO to export a graph image:

    •  (main CADFEKO script)
    •  (script that gets executed in POSTFEKO when running the main CADFEKO script)

    As to sending parameters from CADFEKO to POSTFEKO, I'm not sure about the most elegant way to do this. One option would be to write/read the parameters to/from a (text) file using standard Lua commands.

     

    Hope this helps.

     

    Kind regards

    Madelé

    Unable to find an attachment - read this blog

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited October 2018

    Hi Madelé, thanks for your response! I will try that.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited October 2018

    I have implemented what you told me and it is working! I've got what I wanted, thanks

     

     

  • Madelé
    Madelé
    Altair Employee
    edited October 2018

    That's great! Thanks for letting us know.