Copy link to clipboard
Copied
Hi All
I'm wanting to create a shape layer and am doing it via scripting. I've tested my script works in AE, however when I run it via AEGP_ExecuteScript, I get err 13 and AE crashes. I'm doing the script execution on a text layer, through a button param in UserChangedParam. Any ideas?
Here's my code (mostly stolen from these forums):
PF_Boolean canScript = false;
ERR(suites.UtilitySuite6()->AEGP_IsScriptingAvailable(&canScript));
if(canScript)
{
ERR(suites.UtilitySuite6()->AEGP_ExecuteScript(NULL, script.c_str(), true, NULL, NULL));
}
Thanks.
Copy link to clipboard
Copied
uh.... what experiments have you already done to narrow down the
possibilities?
have you tried:
1. replacing script.c_str() with "alert('it works!');"
2. replacing the "true" to "false" (i think it stands for "platform
encoding", which you probably don't want to use)
3. is it the AEGP_ExecuteScript that's crashing and not
AEGP_IsScriptingAvailable?
sorry for stating the obvious. just making sure it's none of these...
On Tue, Jan 8, 2019 at 9:05 AM JamesWhiffin <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Thanks for your reply Shachar.
I did try replacing the script with alert and that worked (no crash).
It crashes on both isScriptingAvailable and ExecuteScript which is puzzling. I did try both true and false for encoding with no luck.
Copy link to clipboard
Copied
that's very strange...
generally, i'd say you can skip AEGP_IsScriptingAvailable as i see no scenario where it won't be true. (it can only be false before the scripting plug-in has been loaded during the AEGP loading sequence)
though that doesn't explain the crashes...
can it be some buffer overrun or stack overflow? this is all very fishy...
Copy link to clipboard
Copied
Ok I won't worry about the isScriptingAvailable.
It's strange because I don't get an err code even though it's wrapped in the ERR macro.
I think it may have something to do with the script I'm executing (although the script itself works fine if I run it from the file->scripts menu)
(function()
{
app.beginUndoGroup("Shape");
var activeItem,
shapeLayer,
shapeGroup,
shape,
fill,
layers;
activeItem = app.project.activeItem;
if(!activeItem instanceof CompItem){alert("Active Item not comp"); return;}
layers = activeItem.layers;
shapeLayer = layers.addShape();
shapeGroup = shapeLayer.property("ADBE Root Vectors Group");
shapeGroup.addProperty("ADBE Vector Shape - Group");
fill = shapeGroup.addProperty("ADBE Vector Graphic - Fill");
shape = new Shape();
shape.vertices = [[0,0],[50,0],[50,50],[0,50]];
shape.inTangents = [[0,0],[0,0],[0,0],[0,0]];
shape.outTangents = [[0,0],[0,0],[0,0],[0,0]];
shape.closed = true;
shapeGroup.property(1).property("ADBE Vector Shape").setValue(shape);
var myRGBColor = [0, 255, 255, 255]/255;
fill.property("color").setValue(myRGBColor);
fill.property("opacity").setValue(50);
})();
Copy link to clipboard
Copied
looks like it should work...
a simple eliminations would do the trick from this point on.
my wild guess is the anonymous function. try just calling the commands.
(perhaps with the curly block, if you wish to scope your variables)
On Thu, Jan 10, 2019 at 3:16 PM JamesWhiffin <forums_noreply@adobe.com>
Copy link to clipboard
Copied
I've done some trial and error. Even with this as the only line it crashes:
app.project.activeItem.layers.addShape();
This is in userChangedParam, would that make a difference?
Copy link to clipboard
Copied
ah... perhaps it's an operation that changes the plug-in's reference while
it's executing. (it's changing it's layer index)
for the sake of testing, can you try doing some operations in javascript
that don't change the project's structure? (i.e. rename something, sent an
alert ect)
On Fri, Jan 11, 2019 at 7:15 AM JamesWhiffin <forums_noreply@adobe.com>
Copy link to clipboard
Copied
A simple alert works fine, no issues. Is it possible to specify the index of the layer you create so as to not change the index of the plugin layer?
Copy link to clipboard
Copied
i don't think it's possible to create a layer at an index immediately.
in any case, i was just theorizing about the index change as the cause of
the crash. were you able to confirm it?
On Sat, Jan 12, 2019 at 5:22 AM JamesWhiffin <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Unfortunately I can't confirm it though, if I'm unable to create it at a different index. I'll put this in the too hard basket for now. Thanks for your help.
Copy link to clipboard
Copied
Hi, I know it's an old question, but probably the answer is still required. I experienced the same problem. The simple scripts run fine, but the complex ones crash AE. The solution is to execute the main script function through app.scheduleTask.
E.g.:
function main()
{
app.scheduleTask("workingRoutine()", 1000, false);
}
main();