Need to add near-field script to existing POSTFEKO session using Lua

John Underwood
John Underwood Altair Community Member
edited December 2022 in Community Q&A

I am trying to add near-field scripts in POSTFEKO using Lua to dynamically generate them.

According to the API reference, I need to do the following:

nearFieldMathScript = app.MathScripts:Add(pf.Enums.MathScriptTypeEnum.NearField)

My problem is with "app".

When I try to use "app = pf.GetApplication()" to define the variable, I get the following error:

".. attempt to index global 'app' (a nil value)"

Any ideas?

Thanks in advance

Answers

  • Torben Voigt
    Torben Voigt Altair Community Member
    edited December 2022

    Hi @John Underwood ,

    What exactly is the goal of the script? Creating near field requests would only be possible in CADFEKO. Are you sure you mean POSTFEKO?

    Best regards,
    Torben Voigt

  • John Underwood
    John Underwood Altair Community Member
    edited December 2022

    I need to process existing displayed near-field data with math scripts and would like to create these math scripts with a single custom script since there are many of them.

    Correct me if I am wrong but I think the fact that "app = pf.GetApplication()" does not work when in POSTFEKO is a major issue. I have tried the script examples in the guide and none of them work because of this.

    Your help is appreciated in this matter.

    Thanks

  • Torben Voigt
    Torben Voigt Altair Community Member
    edited December 2022

    I just tested just these 2 lines in POSTFEKO:

    app = pf.GetApplication()
    nearFieldMathScript = app.MathScripts:Add(pf.Enums.MathScriptTypeEnum.NearField)

    No error, "NearfieldMath1" is created.

    image

    Could you maybe attach your script here?

    Best regards,
    Torben

  • John Underwood
    John Underwood Altair Community Member
    edited December 2022

    Hi Torben,

    I have figured out what the problem is.

    I was trying to perform the task using a "Custom" script under the "New Script" menu instead of running it as an external script.

    The script user document is not clear on this. I stumbled upon it when I clicked on "New" in the script editor.

    **** Just found in the script document (under "General Scripts") where the above is explained. ***

    Thanks for your help.

    Regards,

    John