Functions for shortcuts

Next
 From:  vector illustrator (QUARITEXA)
9687.1 
Where I can store functions for calling it from shortcuts? I need couple functions which will be calling from many shortcuts.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
9687.2 In reply to 9687.1 
Hi Quaritexa, do you also need to store some data between function calls so you're looking for a type of persistent storage area, or is it that you want to just package up the code into a separate file so it can be shared?

For the second one, if you put your code into a .js file you should then be able to use #include "library_file.js" at the top of the .js file which will insert that library file into the script before running it.

Then to run it as "instant script" same as inline script code rather than as a command, in your keyboard shortcut put the full path and filename of your .js file into the key board shortcut. Or you can put just the filename with .js file extesion and no path if you put the file into a "scripts" folder which you can make alongside of the commands folder (either in the install folder or appdata).

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  vector illustrator (QUARITEXA)
9687.3 In reply to 9687.2 
I want to describe several functions to call it from shortcuts inline scripts like that:
code:
script:#include "moi://scripts/test.js"; testfunc("display text");

How to implement it right?
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
9687.4 In reply to 9687.3 
Hi Quaritexa,

> I want to describe several functions to call it from shortcuts inline scripts like that:
> code:
>
> script:#include "moi://scripts/test.js"; testfunc("display text");

#include is not supported in direct inline script code like you have there.

It is supported when the script is loaded from a .js file.

So like I described above, you will need to put your script code into 2 different .js files, one for your script and one for the library and place those files in a "scripts" directory that you will make in the install folder as a sibling to "commands".

So for example, create a file named test.js , which contains this content:
code:
#include "test_lib.js"

testfunc( 'display this' );


Then create a second file named test_lib.js also located in the "scripts" directory. Put this inside of it:
code:
function testfunc( val )
{
	moi.ui.alert( val );
}


Now for your shortcut key put in "test.js" note the .js file extension is included here.

Then when the shortcut key is executed, it will load the content of the test.js file and process the includes (includes must be at the top of the file) and then run it as immediate executed script the same as how inline script code is run.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  vector illustrator (QUARITEXA)
9687.5 In reply to 9687.4 
I got that. But I need case like this:
code:
1=script: hint('first string'); some code;
2=script: hint('second string'); another code;
3=script: hint('third string'); some more code;

The function 'hint' must be common for the keys.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
9687.6 In reply to 9687.5 
Hi Quaritexa, so for something like that:

code:
1=script: hint('first string'); some code;
2=script: hint('second string'); another code;
3=script: hint('third string'); some more code;

You would create 4 text files, something like this:

File hint.js will contain:
  function hint( val )
  {
     // Do something
  }

File Key1.js will contain:
  #include "hint.js"
  hint('first string');
  some code;

File Key2.js will contain:
  #include "hint.js"
  hint('second string');
  another code;

File Key3.js will contain:
  #include "hint.js"
  hint('third string');
  some more code;

Your shortcut keys setup would go like this:
  1=Key1.js
  2=Key2.js
  3=Key3.js

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  vector illustrator (QUARITEXA)
9687.7 In reply to 9687.6 
=D
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All