I have a script (.jsx) that runs correctly when I load the project and run it myself. However, when I run it on start up by putting it in the StartUp folder it gives me this error:
"Unable to execute script at line 1. After Effects error: Unable to call "item" because of parameter 1. The range has no values"
Here is my script:
var compToBeOutput = app.project.item(35);
var comp1 = app.project.item(1);
var numGames = 7;
var p = 3;
compToBeOutput.duration = (90*numGames)/30;
compToBeOutput.layers.add(comp1);
for (i = 0; i<numGames-1; i++) {
var newComp = comp1.duplicate();
var newLayer = compToBeOutput.layers.add(newComp);
newLayer.startTime = p;
p = p + 3;
}
Thanks,
Greg
That is because item here is undefined. app.project.item is only accessible when project is open. so you need to open project first in the script itself.
For example.
var myPath = new File("you file path here");
if(myPath.exists){
app.open(myPath );
}
then paste your script underneath.
Related
I'm writing a small website for a newspaper and I'm trying to make the home page to show the latest news and a photo for each. I use Firebase Realtime Database and Firestorage to store the news and the photos. When getting the data and showing it I save all the data first in an object array and then displaying it (so it remains in order).
The problem is that when I'm calling the function to display it the links to the photos don't appear.
I tried outputting the array with console.log(arrayName) and everything looks like it should. But when I try console.log(arrayName[1].sos) it shows nothing.
db.collection("articole").orderBy("data", "asc").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
articolTmp = {
titlu: doc.data().titlu,
subtitlu: doc.data().subtitlu,
id: doc.id,
poza: doc.data().poza,
data: doc.data().data,
sos: ""
};
articole.push(articolTmp);
});
show();
});
function show(){
for(let i = 1; i < articole.length; ++i){
var pathReference = storage.ref('pozeArticole/' + articole[i].poza);
pathReference.getDownloadURL().then(function(url){
articole[i].sos = url;
});
}
showw();
}
function showw(){
// this is the console.log I was talking about
console.log(articole);
for(let i = 1; i < articole.length; ++i){
console.log(articole[i].sos);
var div = document.createElement("div");
var titlu = document.createElement("h3");
var subtitlu = document.createElement("p");
var link = document.createElement("a");
var poza = document.createElement("img");
poza.src = articole[i].sos;
poza.alt = "alt";
link.href = "viz.html?id=" + articole[i].id;
titlu.innerHTML = articole[i].titlu;
subtitlu.innerHTML = articole[i].subtitlu;
document.getElementById("main").appendChild(div);
link.appendChild(titlu);
div.appendChild(link);
div.appendChild(subtitlu);
div.appendChild(poza);
}
Your problem is in the show function. The last line of code which calls showw is executed before the line "above it" which is articole[i].sos = url;. Why is that? Because you are using an asynchronous operation. The code that gets the download url is executed in a different thread. Whenever that code finished, the block you provided (articole[i].sos = url;) will get executed. I recommend reading about asynchronous operations and promises.
So, to solve your problem, you have ti move the showw call inside the block above it. The block should be:
pathReference.getDownloadURL().then(function(url){
articole[i].sos = url;
showw();
});`
So to start, I am using the fancybox library here.
http://fancyapps.com/fancybox/
My end goal is to create a photoalbum that downloads images stored on Amazon S3 via Cloudfront. Right now it is setup to where there is a main page and each page has a single image. Click that image and it opens an album.
The problem is that if my album has 75 items or whatever large amount, the browser will timeout and crash or cause my computer to run out of memory (I am running this locally as I dev it).
here is some sample code
function photoDL(){
var num = 0;
var batch = 0;
for(i = 1; i < 62; i++){
var myphoto = 'https://MYCODEFRONTSTUFF/'+i+'.jpg';
var albumpic = new Array();
albumpic.push(myphoto);
for(batch = 1; batch < 5; batch++){
$.fancybox.open([
{
src : albumpic[num],
opts : {
caption : 'First caption'
}
},
], {
loop : false,
hash : "album3"
});
setTimeout(photoDL(), 10000);
num += 1;
}
}
}
I know there is some stuff in there that doesn't look right. I was thinking I could set the SetTimeout to buffer and give it some time to download each image but that didn't help. It still tries to download them all at once. I was playing with the idea of creating batches but hit a deadend. Any help is greatly appreciatd.
Your code loops 61 time and inside each of the loop, you have inner loop that runs 5 times. And inside each inner loop - you open new fancyBox instance (over the existing one) and then you call main loop!
So, you open fancyBox 243 times and after 10000ms you open 58,806 new instances and you are wondering why your browser crashes? :)
Thank for the insights, I did manage to figure this one out. Introducing the fixed code
function photoDL(batch, url, ftype){
var num = 0;
var fArr = [];
var albumpic = new Array();
var fboxOpen = '';
for(i = 1; i < batch; i++){
var myphoto = url+i+ftype;
albumpic[i] = myphoto;
//console.log(albumpic[i]);
var fboxOpen =
{
src : albumpic[i],
opts : {
caption : 'First caption'
}
};
fArr[i] = fboxOpen;
}
fArr.shift();
var jsonString = JSON.stringify(fArr);
console.log(jsonString);
$.fancybox.open(
fArr
, {
loop : false,
hash : "album3"
});
}
A little slow but it's definitely working!
I am getting the following error when trying to run my Javascript file:
"Uncaught TypeError: Object function (a){"undefined"==typeof a&& a=0);this.m_PolyOuts=null;this.m_ClipType= d.ClipType.ctIntersection;this.m_IntersectNodeComparer=this.m_IntersectList=this.m_SortedEdges=this.m_ActiveEdges=this.m_Scanbeam=null;this.m...<omitted>...y'"
Relevant code:
<script>
// Geolocation
var stateData;
var states = new Object();
d3.json("states.json", function (data) {
stateData = data;
data.features.forEach(function (datum) {
// Populate data for each entry in states[__]...
});
var pt = new ClipperLib.IntPoint(67.007915, -152.002047);
for (var i = 0; i < states["Alaska"].length; ++i) {
var done = 0;
for (var j = 0; j < states["Alaska"][i].length; ++j) {
var poly = states["Alaska"][i][j];
if (ClipperLib.Clipper.PointInPoly(pt, poly) == 1) {
done = 1;
break;
}
...
}
}
...
});
</script>
When I try running the command on the console in Chrome, I do not receive an error:
https://www.dropbox.com/s/cm29oaxgr5rjz2d/Screenshot%202014-02-28%2011.42.19.png
I am using ClipperJS and have at the top of my file included it as a src as such:
< script src="clipper.js" charset="utf-8">< /script>
(No spaces before "script" or "/script" - they are here because it would not display otherwise.)
I thought it might have been because of a type mismatch but I then tried:
...
var poly = [{X:10,Y:10},{X:110,Y:10},{X:110,Y:110},{X:10,Y:110}];
if (ClipperLib.Clipper.PointInPoly(pt, poly) == 1) {
done = 1;
break;
}
...
And I still got the same error.
Any help is appreciated!
Relevant link for where I got the idea to use ClipperJS (answer by "Timo")
Without seeing the rest of your code, it seems like a bootstrapping issue. Try ensuring that your code is run after everything on the page has run already.
Also: D3's json request calls its callback with error as the first parameter, and data as the second. I suspect this is causing the Poly configurations for each state to be misconfigured or, not configured at all, so when you're querying them for point inclusion it's failing.
https://github.com/mbostock/d3/wiki/Requests
I'm using something similar to NodeJS called bondi, it's build on the Firefox js engine.. Basically i'm getting this error and I believe it's due to the way i'm referencing "this" in the .Get function below.
Basically there is a tool called SFtpClient. It has the method of "Get", to list the contents of a folder, but I want to change the prototype for this with a drop in include file. I need to change it so that it
a/ retries several times when it fails, and b/ it has a recursive folder listing function.
So I used the prototype to change it - moved .Get to ._Get.
Can anyone see why I would be getting the error:
Jan 23 04:51:34 beta bondi: === this._Get is not a function --- Prio(6) Result(0x0) File(/home/nwo/approot/include/sftpclientenh
when I run the code below?
Thanks
SFtpClient.prototype._Get = SFtpClient.prototype.Get;
SFtpClient.prototype.Get = function(Folder, Retries){
//defaults
if(!Retries) Retries = 5;
if(!Folder) Folder = "~/";
//vars
var FileListing = [];
var connect = function(){
//TODO JRF 19.01.2012 : re-enable this when bondi is fixed
// this.HomeDirectory.replace(/\/?$/, "/");
FileListing = this._Get(Folder);
return true;
}
var i = 1;
do{
var res = false;
try {
res = connect();
}catch(e){
Debug.LogInfo(e.message);
}
i++;
Server.Sleep(i*2000);
} while(res==false && i < Retries);
return FileListing;
}
Try res = connect.call(this) instead of res = connect().
I am calling a batch file from Javascript in this fashion:
function runBatch(){
var exe = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("C:\\test.bat");
var run = Components.classes['#mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = ["hi"];
run.run(false, parameters,parameters.length);
}
my test batch file is:
echo on
echo %1
pause
exit
Each time I call a batch file, however, the command prompt is not displayed, as it would be if I simply ran the batch file from the desktop. How can I remedy this and display a command prompt for the batch file?
Edit
To be clear, the cmd.exe process is launched - I can see it in the task bar. But no window gets displayed. This snippet behaves similarly:
function runCmd(){
var exe = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("C:\\WINDOWS\\system32\\cmd.exe");
var run = Components.classes['#mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
run.run(false, null,0);
}
The only solution I've heard so far (that should work, although I haven't done it yet, comes from Mook in the Mozilla xulrunner IRC channel:
create a temporary batch file, writing in the batch file to call and arguments to pass it. then execute the temporary batch file.
e.g psuedocode:
f = fopen("temp.bat");
fprintf(f, "other.bat 1 2 3 4 5");
fclose(f);
exec("temp.bat");
not very elegant but it should work.
Did you try using the launch method of nsiLocalFile?
function runBatch(){
var exe = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("C:\\test.bat");
exe.launch();
}
This should have "the same effect as if you double-clicked the file."
This code snippet seems to work fine. Of course, you have to change D:\Windows\system32\ to path to cmd.exe in your operation system.
const FileFactory = new Components.Constructor("#mozilla.org/file/local;1","nsILocalFile","initWithPath");
var str_LocalProgram = "D:\\Windows\\system32\\cmd.exe";
var obj_Program = new FileFactory(str_LocalProgram);
var process = Components.classes["#mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(obj_Program);
var args = ["/C", "regedit.exe"];
process.run(true, args, args.length);
I had to launch a batch file and pass in an argument. This is how I did it:
let file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
let run = Components.classes['#mozilla.org/process/util;1']
.createInstance(Components.interfaces.nsIProcess);
let path = file.path;
if(file.exists())
{
// quick security check
if(file.isExecutable())
{
// show error message
return;
}
let localfile = file.QueryInterface(Components.interfaces.nsILocalFile);
if(localfile != null)
{
if (app == "app1")
{
localfile.initWithPath("C:\\app1.bat");
}
else
{
localfile.initWithPath("C:\\app2.bat");
}
run.init(localfile);
var parameters = [path];
run.run(false, parameters, parameters.length);
}
else
{
// show error message
}
}
else
{
// show error message
}
and in my Window batch file I did:
#ECHO OFF
START "application.exe" %1
using START, allowed me to launch the application and close the command line window
You are doing right but repair this:
function runBatch(){
var exe = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("***C:\ \test.bat***");
var run = Components.classes['#mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = ["hi"];
run.run(false, parameters,parameters.length);
}
If you do this???
function runBatch(){
var exe = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("***C:\test.bat***");
var run = Components.classes['#mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = ["hi"];
run.run(false, parameters,parameters.length);
}
An put #echo off at init???
Thanks
Pfft, very ugly code..
A much nicer trick is to use Win.com to spawn a 16bit subsystem of the command prompt.
Win.com will send the console to the right virtual terminal, showing you the output.
var lPath = getWorkingDir.path + "\\..\\..\\WINDOWS\\system32\\win.com";
lFile.initWithPath(lPath);
var process = Components.classes["#mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(lFile);
var args = ["cmd.exe"];
process.run(false, args, args.length);
Nicer, and works :)
For Linux:
<script>
function callLight2()
{
netscape.security.PrivilegeManager.enablePrivilege(
'UniversalXPConnect'
);
var exe = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
// exe.initWithPath(C:\\Windows\\system32\\cmd.exe"");
exe.initWithPath("/usr/bin/gnome-terminal");
var run = Components.classes['#mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
var parameters = ["-e", "/usr/bin/ip_connect_up.sh 2 2 3 4 5 6"];
// var parameters = ["/C", "regedit.exe"];
// var parameters = ["hi"];
run.run(true, parameters,parameters.length);
}
</script>
start