Copy link to clipboard
Copied
I have this script I wrote called MatchObjects.jsx that I use almost every day via the JSX Launcher panel and it works just fine, but today I wanted to clean up some of the code and when I tried to run the script from the VS Code debugger, I got an Illegal Argument Error: 1242 – Numeric value expected. It had worked fine via the VS Code bugger in October of 2021 when I last worked on the script.
Since I had yet to change anything in the code this seemed weird to me. So, I placed the script in the Illustrator scripts folder, ran it, and got the same error. And when I checked the variable types in the array the error is complaining about, they are all numbers (numeric values).
Like I said above, if I run the script from JSX Launcher it works just fine, so I'm not sure when this behavior started. I'm testing on Illustrator 26.0.3. Any ideas?
You've redefined the built-in function getScaleMatrix(), but it appears that the original built-in function is being called. This expects two numbers, not arrays. Just call the function in question something else.
Copy link to clipboard
Copied
You've redefined the built-in function getScaleMatrix(), but it appears that the original built-in function is being called. This expects two numbers, not arrays. Just call the function in question something else.
Copy link to clipboard
Copied
Thanks for your suggestion but I'm not following... getScaleMatrix() is a script specific function that I wrote that takes object bounds (as an array) for the first two arguments, and then a setting from my dialog for the third argument. I use those bounds to calculate the scaling I need to apply to my target objects. And, that still wouldn't explain why it previously worked fine, and still works fine through the JSX Launcher panel.
Copy link to clipboard
Copied
Hi @jduncan, @femkeblanco is right. There is a native global getScaleMatrix function already. (Try doing $.writeln(getScaleMatrix).) Illustrator is notorious for polluting the global scope with "shortcuts", eg. you can just ask for "selection" which is the same as "app.selection".
First thing to do it change the name of the function and see if it works. Maybe using JSX Launcher also starts and targets a different engine?
- Mark
Copy link to clipboard
Copied
Awesome! That was it! This is actually the first thing I thought when I read your first comment, and I even did a quick search of the API for getScaleMatrix and didn't find anything so I moved on. I guess this is something they added/enabled in the last few versions... Either way, it's working just fine now, so THANKS FOR YOUR HELP 👍!
Copy link to clipboard
Copied
Another approach is to wrap your (currently globally scoped) code in an IIFE.
(function () {
// your code here
})()
I tried it with your code and it worked.
- Mark
Copy link to clipboard
Copied
I'm a dummy 🤦:male_sign:! I even call app.getScaleMatrix() in the return statement of my getScaleMatrix() function. Forest for the trees I guess... Thanks again!
Copy link to clipboard
Copied
I even did a quick search of the API for getScaleMatrix and didn't find anything so I moved on. I guess this is something they added/enabled in the last few versions...
By @jduncan
that's strange, getScaleMatrix() function has been there since the time of the dinosaurs
Copy link to clipboard
Copied
Yeah, at the time I was on my phone searching the Illustrator Scripting Guide and if you search for "getScaleMatrix()" no results are returned. I had to search explicitly for "Application.getScaleMatrix()" to find it which I figured out after I commented. The funniest part is I was actually using getScaleMatrix() in my return statement of the offending function. I don't script for Illustrator that often so I just forgot about it 🤦:male_sign:.