Skip to main content
Inspiring
September 17, 2021
解決済み

JSX script UI popping up when i call my custom function thru extension after effects.

  • September 17, 2021
  • 返信数 1.
  • 1726 ビュー

I have my custom jsx script(myJSXScript_UI.jsx) with UI and custom functions written for after effects to run from File > Script >run script.

 

Now am trying out writing an extension for after effects where i can call some function from above jsx script directly using CSInterface.

 

So, i have added my jsx script path in manifest file and i have setup a button onClick() event in index.html and am calling my custom function using CSInterface. Please find the attachment for index.html and manifest file snapshots for your reference.

Now my problem is, when i click that button in extension, my functions are running fine and executed, but UI of the jsx script is opening as well. What is the reason? 

Currently, i have removed panel.show() in jsx script to avoid UI, but that's not ideal solution.

If am calling some function() why entire script is opening with UI.

Whats wrong and whats the other way to do this?

Please help! 

 

 

 

 

このトピックへの返信は締め切られました。
解決に役立った回答 Mathias Moehl

Since all Ae scripts share the same global space, you could do the following:

Your jsx script checks if a global variable "showUserInterfaceOfMyAfxScript" exists and has the value false. If that is the case, it does not create the user interface AND sets the showUserInterfaceOfMyAfxScript to true again.

 

When you execute your script from the CEP panel, first execute this script
showUserInterfaceOfMyAfxScript = false;

then execute your myAfxScript.jsx

 

Note that it is crucial that myAfxScript.jsx sets

showUserInterfaceOfMyAfxScript = true;

again after not creating the user interface. Because otherwise if the user decides to execute myAfxScript.jsx himself later in the session, the variable is still false and the UI won't show up.

 

That's kind of what I do in the API's of my After Effects tools:
https://mamoworld.com/article/kbar-and-scripting-apis

except that I use variable

kbar = { button:{argument:"getAPI"}};

 instead of a variable

showUserInterfaceOfMyAfxScript = false;
such that the script functions can also be executed by the tool Kbar easily.

 

返信数 1

Mathias Moehl
Community Expert
Community Expert
September 17, 2021

When you add the script to your manifest, I would assume that it is executed when your CEP panel is launched (so the jsx script UI should appear at the point in time where also your CEP panel UI appears). But from what you say it seems that Ae is only executing the jsx script lazily when the first actual jsx code is executed from the panel (just a guess, not sure if this is really what is happening behind the scenes).

 

In general, if you want your CEP panel to use code from your jsx script but you don't want the UI of the jsx script to show up, removing the part of the code that creates the UI (like panel.show()) is the only thing that makes sense, right? Why would you want to execute code that says "please show this panel" if you don't want it to be shown?

 

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
manjunath MK作成者
Inspiring
September 17, 2021

Thank you for ur reply!My idea is to just use functions in my existing jsx file and get returned results without modifying jsx file...So tat, jsx file can be used as a script to launch from File > script > run and also used for extension to only use its existing functions and get returned results..

 

I ll put in this way briefly..

 

MyAfxScript.jsx

--------------------------

var p= new window ();

P.add(button1,2,3 );

P.show();

 

button1.onClick = run function A();

button 2.onClick= run function B();

button3 .onClick=run function C();

 

function A(){do something and  return result}

function B(){do something and  return result}

function C(){do something and  return result}

--–---------------

 

 

My extension(index.html)

---------------

<body>

<script src=MyAfxScript.jsx>

 

<button onClick=function A()>

<button onClick=function B()>

<button onClick=function C()>

</body>

 

Hope u understood my problem?

 

Mathias Moehl
Community Expert
Mathias MoehlCommunity Expert解決!
Community Expert
September 20, 2021

Since all Ae scripts share the same global space, you could do the following:

Your jsx script checks if a global variable "showUserInterfaceOfMyAfxScript" exists and has the value false. If that is the case, it does not create the user interface AND sets the showUserInterfaceOfMyAfxScript to true again.

 

When you execute your script from the CEP panel, first execute this script
showUserInterfaceOfMyAfxScript = false;

then execute your myAfxScript.jsx

 

Note that it is crucial that myAfxScript.jsx sets

showUserInterfaceOfMyAfxScript = true;

again after not creating the user interface. Because otherwise if the user decides to execute myAfxScript.jsx himself later in the session, the variable is still false and the UI won't show up.

 

That's kind of what I do in the API's of my After Effects tools:
https://mamoworld.com/article/kbar-and-scripting-apis

except that I use variable

kbar = { button:{argument:"getAPI"}};

 instead of a variable

showUserInterfaceOfMyAfxScript = false;
such that the script functions can also be executed by the tool Kbar easily.

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects