Hello everyone.
I'm brand new to scripting (a few hours),
and I have a script I need help with.
Basically I want to make new comps from selected layers and have the start timecode to begin on 0,
I think I've made that one correct.
However... I'm getting this line "Undefined is not an object" when running the script.
The script does what I want it to do, but this error is bugging me and I want to learn how
to correct that error.
Hopefully some gently souls will help me out!
Thanks in advance,
StanTheMan
Script:
var selectedItems = app.project.selection;
for (var i=0; i <= selectedItems.length; i++) {
var myComp = app.project.items.addComp(selectedItems.name, selectedItems.width, selectedItems.height, selectedItems.pixelAspect, selectedItems.duration, selectedItems.frameRate);
myComp.layers.add(selectedItems);
myComp.displayStartTime = 0;
}
Need help about a script! (New to scripting)
Moderator: Paul Tuersley
Luckily this is a simple fix! Change from this--
to--
The issue is that selectedItems is an array counting from 0; if there were 3 elements, you would access them by array[0], array[1], array[2]. So, you want the 'for' loop to count one less than the array length.
What's happening now is that it's doing array[0], array[1], array[2], and then it's trying to do array[3] but there isn't any! Because of the <=.
Check out this link for more info on arrays in javascript.
Code: Select all
for (var i=0; i <= selectedItems.length; i++) {
Code: Select all
for (var i=0; i < selectedItems.length; i++) {
What's happening now is that it's doing array[0], array[1], array[2], and then it's trying to do array[3] but there isn't any! Because of the <=.
Check out this link for more info on arrays in javascript.
-
- Posts: 2
- Joined: July 5th, 2017, 3:56 am
Thank you!
Much appreciated!
The start to learn scripting begins.
/Stan
Much appreciated!
The start to learn scripting begins.
/Stan