I really like this project, curious about more information on how you intend to use this. Is the goal to be able to write any text, run it through this procedure which may involve this or other "background shapes" files, and create typographic designs? Well, anyway - the issue is due to the amount of paths. The way Mr GPT did it, is quite basic, so it thinks you have a typical document with just a text-frame and one square and one circle, etc. But, what you have is a rich background with many many shapes, after a while it catastrophically slows down the scripting when it tries to go through them. To fix this, you could: Consolidate the shapes into distinct groups, so in your Layer on the layers panel, it shows a minimal amount of top-level items. Ensure that these groups have ONE clear boundary shape (this can be a pain, but use Actions to go through the shapes and duplicate + add them to form the contour), and label it some certain name, so that this contour can be used for the hit tests. Explain to ChatGPT the situation and what you are doing, so it re-makes the script taking into account that you now only have top-level groups in some layer, and inside each of the top-level groups you have one path-item called something, which is your hit-test contour. Try the new code to see if it doesn't crash your application and does your action as you want. UPD: I just looked at some of the code and it appears that ChatGPT had misled you in a case of classic hallucinatory well-meaning advice. No optimization would fix this code, as I do not believe any such thing as .hitTest() exists. So, next what to do: well, you can: Still consolidate the shapes into some groups that have a contour that could be used by a potential true hit test. Get it to spew out the proper math function that does the hit test, whether using mathematics or using Pathfinder. If none of this is going well, maybe you could try this: Pre-make all your letters, slice them up into cubes like they are chopped potatoes. Make such a script that will place your letter groups, then go through the 'cubes' in the sliced-up letters, convert each one at a time, to a small artboard. then have your script use a tried & true hit-test using artboards and selecting objects on active artboard. Now, you can have this script isolate the selected items to copy to a final layer and remove any duplicates which may have been used for utility in this operation.
... View more