Page 1 of 1

"Click" Buttons in Duik in a Script

Posted: Wed Aug 28, 2019 12:04 pm
by schwarzer kater
Hi everyone! :-)

TLTR: I'm looking for a way to "click Duik buttons" with a jsx script.

At the moment I work on creating a custom macro keyboard for use with AfterEffects and of course Duik.
custom keyboard.jpg
custom keyboard.jpg (102.73 KiB) Viewed 94 times
My knowlegde of extendscript is limited, though I figured out that I can use DuAEF to include/reproduce Duik functionality in my script.

For example I have a key to create a spine structure. I want to mimic Duik's behaviour as close as possible, so I dug a bit into the code and basically tried to copy the code for what Duik does when creating a spine.

Here's my solution so far:

Code: Select all

#include DuAEF_no_bin.jsxinc
function spine()
	var comp = DuAEF.DuAE.Project.getActiveComp();
	if (!comp) return;
	app.beginUndoGroup('Duik | ' + "Create spine structure");
While this 'kinda works', the original function is more sophisticated, and takes into consideration spine options and other stuff. Also if the code changed with a new release I would have to manually update every function I create this way to reflect the changes.

So what (I think) I'm looking for is a way to call for example

Code: Select all

inside the active duik panel and have it do its thing while respecting the corresponding settings.

Any insight on how this could be achieved is highly appreciated.

PS: I have another plugin (SortIt by EyeDesyn) that allows to execute functionality via a keyboard shortcut. There is one .jsx file per shortcut (and the shortcut gets added in AE to execute the corresponding script). Each .jsx contains only a few lines of code like this:

Code: Select all

#targetengine "sort-it";
    groupLayersShortcut.pressed = true;
To my understanding the "targetengine" allows the script to have access to the same variables and objects as the main script that has the panel and functionality. Unfortunately I haven't figured out how the "action side" of this works since the main script is in binary format.

Maybe if I figured out how it works for this plugin it might bring me closer to do it for Duik. :-)

Re: "Click" Buttons in Duik in a Script

Posted: Wed Aug 28, 2019 12:25 pm
by Duduf

You've come at the right moment ;)
I'm working on this kind of stuff, not for shortcuts, but for a command line, like this:

For this functionnality, I have the same needs as you, i.e. a function for each button. And As soon as I have this, I'll think of a way to pass options and not just 'click' buttons, but that's a second milestone.

So, where I am:
I'm not going to "expose" the functions or anything else from Duik itself, because I don't want to "pollute" the global namespace. I have another approach which is to store the functions used by Duik in a separate file, which could be included in any other script, which will provide all these functions to be reused.

I'm in the middle of this process, and it will be testable/available quite soon, I hope.
The idea will just to

Code: Select all

#include Duik_functions.jsxinc
at the beginning of your script, something like that. That just means when a new version of Duik is released, you'll have to get the new versions of these files, that's all.

Re: "Click" Buttons in Duik in a Script

Posted: Wed Aug 28, 2019 12:26 pm
by Duduf
Duik is already split into several files, for modularity, I'm just extending this concept: ... k_required

Re: "Click" Buttons in Duik in a Script

Posted: Wed Aug 28, 2019 12:28 pm
by Duduf
This is what allows me to develop these kind of features:

where each panel is a stand-alone one and does not even actually need the main Duik panel, but all panels do share the same source anyway.

Re: "Click" Buttons in Duik in a Script

Posted: Sat Aug 31, 2019 5:24 pm
by Duduf
I have some very fresh news!

I've made an API available (it's really fresh, let me know if anything goes wrong or if you find any bug)

It's quite simple:
Just download the library there: ... e/Duik-API

Then you can include it in your script, and have an easy access to Duik methods. For example, this is how to create a Hominoid Structure (what the hominoid button does):

Code: Select all

//encapsulate everything to avoid global variables !important!
(function(thisObj) {

    //include the API
    #include 'Duik16_api.jsxinc'

    // Create a hominoid structure
    // The whole API is contained in the 'Duik' object
    // but the DuAEF framework is also made available in its own object


Re: "Click" Buttons in Duik in a Script

Posted: Sat Aug 31, 2019 5:24 pm
by Duduf
All the available methods are documented there:

Re: "Click" Buttons in Duik in a Script

Posted: Tue Sep 17, 2019 6:27 am
by Utam7623
Wow.. Find something new.. Nice thread...