Hi @paul.gutierrezZNHGQ. Glad to see that your project is advancing as planned. When you only plan to use an event listener for a limited duration, the same source code that creates the event listener, must also include some code to remove it at some specific point, or when some other event happens. Otherwise you generally have to exit the Inventor application entirely to get rid of it, not just close all documents. Depending on your specific needs, there are different ways to plan for and write the removal portion of the code. Basically, that code that created the listener is being held in Inventor's session memory, and is still 'running' or 'active' in the background, and it still has the pointer/handle on that listener it created, and only it can remove it. No other rule will be able to access it to get rid of it. And changing the contents of the code, in the same session, after you have ran it, is not a good idea either, because the original version of the code is what is still being held in memory while it runs in the background.
I (and others) used SharedVariables for this purpose, because they are a way to store data temporarily (just in Inventor's session memory), while you do other things. When your code creates the listener, it can also create one of these SharedVariables, with a name and value that make sense to you. Your code can also check if this SharedVariable already exists, and what its value is before creating the listener. You can use that to make sure you are not duplicating the listener (other one can not be removed then). You can also use that, with the help of another rule which would change its value, to manually initiate getting rid of the listener, because if its value is a certain way, you can use that as a clue to get rid of an already existing listener. When you run the other rule, it will change SharedVariable's value, then run the rule that created the listener again, which will check its value right at the start, and if its is a certain value, it will remove the existing listener, instead of creating a new one.
Another process is to create two listeners, one for the event you are really after, and another for when a specific document closes. Then when that specific document closes, it will remove both listeners. It can get as complicated as you want it. And if you search around within this forum long enough, you will most likely find some examples of both of these ways, and maybe even other ways.
Below is a link to one of my contribution posts about creating event handlers within iLogic rules that may help.
https://knowledge.autodesk.com/community/article/348361
Wesley Crihfield

(Not an Autodesk Employee)