# Calling project specific code from an Ignition module

**URL:** <https://forum.inductiveautomation.com/t/calling-project-specific-code-from-an-ignition-module/106143>\
**Category:** Module Development\
**Tags:** ignition81, scripting\
**Created:** [May 12, 2025, 1:52pm UTC](https://forum.inductiveautomation.com/t/calling-project-specific-code-from-an-ignition-module/106143 "2025-05-12T13:52:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuel.gupta](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@samuel.gupta](https://forum.inductiveautomation.com/u/samuel.gupta)\
**Post date:** [May 12, 2025, 1:52pm UTC](https://forum.inductiveautomation.com/t/calling-project-specific-code-from-an-ignition-module/106143/1 "2025-05-12T13:52:02Z")

</div>

Hello!

I am trying to make an Ignition module for MQTT where the projects are in charge of subscribing to the topics they need and set a callback on message reception. Im looking for a way to call those callbacks from the module.

I think im in the right direction using this line but I might be wrong (It seems its still attempting to use my global scripts but I want to use any project script) :  
gatewayContext.getProjectManager().getProjectScriptManager("ProjectNameHere").runCode();

Has anyone attempted to do this? What worked for you?

Thanks!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 12, 2025, 2:06pm UTC](https://forum.inductiveautomation.com/t/calling-project-specific-code-from-an-ignition-module/106143/2 "2025-05-12T14:06:02Z")

</div>

It is extremely dangerous to allow callers to supply a callback function that is going to be retained for more than one single, short-term, use. Any project edit/save will restart gateway scripts and make the function obsolete. Your module holding the function object will block garbage collection and you will leak gobs of memory.

Instead, have the user supply a function name, and look that name up in a script manager's `locals()`. (Split on dots and use `.findattr()` on following parts.) You can cache that lookup in between project restarts (using a project listener to signal the need to discard). Use the script manager's `.runFunction()` method to execute function objects.

---

<div class="post-metadata">

**Author:** ![samuel.gupta](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@samuel.gupta](https://forum.inductiveautomation.com/u/samuel.gupta)\
**Post date:** [May 12, 2025, 2:16pm UTC](https://forum.inductiveautomation.com/t/calling-project-specific-code-from-an-ignition-module/106143/3 "2025-05-12T14:16:57Z")

</div>

Thanks for the quick reply!

The concerns for project save were indeed something I had in mind.

Script managers only have a .createLocalsMap() function available. Is that what you are refering to? So i have to lookup the name of the function I want to use in that map, retrieve the PyFunction object and call it with runFunction()?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 12, 2025, 2:21pm UTC](https://forum.inductiveautomation.com/t/calling-project-specific-code-from-an-ignition-module/106143/4 "2025-05-12T14:21:13Z")

</div>

Yes.
