This forum has been permanently closed and archived; you can still access all content but can't post anymore.

Of course, you can still join us in other places!
To get support and talk about RxLaboratory and with the team, come here: https://rainboxlab.org/support/

"Click" Buttons in Duik in a Script

General help and tips
Locked
schwarzer kater

"Click" Buttons in Duik in a Script

Post by schwarzer kater » Wed Aug 28, 2019 12:04 pm

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
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");
	DuAEF.DuAE.Project.setProgressMode(true);
	DuAEF.Duik.Structure.createSpine(1,2,1,true);
	DuAEF.DuAE.Project.setProgressMode(false);
	app.endUndoGroup();
}
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

ui_spineValidButton_clicked(true);
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";
try{
    groupLayersShortcut.pressed = true;
}catch(err){  
}
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. :-)

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Wed Aug 28, 2019 12:25 pm

Hi!

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:
https://www.youtube.com/watch?v=0Zc4_XF1YeM


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.

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Wed Aug 28, 2019 12:26 pm

Duik is already split into several files, for modularity, I'm just extending this concept:

https://github.com/Rainbox-dev/DuAEF_Du ... k_required

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Wed Aug 28, 2019 12:28 pm

This is what allows me to develop these kind of features:

https://www.youtube.com/watch?v=8-qkyofGL2Q

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.

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Sat Aug 31, 2019 5:24 pm

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:
https://github.com/Rainbox-dev/DuAEF_Du ... 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
    Duik.structures.mammal();

})(this);

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Sat Aug 31, 2019 5:24 pm

All the available methods are documented there:
http://duaef-docs.rainboxlab.org/Duik-API/Duik.html

Utam7623

Re: "Click" Buttons in Duik in a Script

Post by Utam7623 » Tue Sep 17, 2019 6:27 am

Wow.. Find something new.. Nice thread...

schwarzer kater

Re: "Click" Buttons in Duik in a Script

Post by schwarzer kater » Sun Oct 27, 2019 8:16 am

Hi Nicolas,

thank you so much for your replies and for making this available to everyone!

Unfortunately I didn't have time to try it until now. So far I had only partial success.

When I use the example code you provided I run into
Unable to execute script at line 3897. Execution halted
the debugger shows the following line to be the culprit:

Code: Select all

3897: tempL.applyPreset(DuAEF.DuAE.Presets.MAGIC);
and complains that
undefined is not an object
I also tried a different function with similar results:

Code: Select all

Duik.automation.spring();
Only this time it's line 18154:

Code: Select all

else layer.applyPreset(DuAEF.Duik.PseudoEffects.MULTID_SPRING);
Both times the presets seem to be the culprit. Is there maybe a preparation or init step I need to take before using the API? Somehow generate all the pseudo effects files maybe?

I also thought I'd try something that doesn't need presets to work and was met with success :-)

Code: Select all

Duik.structures.edit();

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Sun Oct 27, 2019 3:13 pm

My bad, the pseudo effects are missing in the API...

I'll fix this in a few days, thanks for the feedback!

Duduf
Posts: 915
Joined: Mon Jun 20, 2016 2:59 pm

Re: "Click" Buttons in Duik in a Script

Post by Duduf » Tue Nov 05, 2019 2:22 pm

Hi!

I'm sorry to be a bit late on this, but the API is fixed. Actually, it already worked, it's just my example which was wrong.......

Anyway, get the latest version here https://github.com/Rainbox-dev/DuAEF_Du ... API/16.2.0

And use this example. What was missing was the DuAEF initialization, sorry!

Code: Select all

//encapsulate everything to avoid global variables !important!
(function(thisObj) {
    //include the API
    #include 'Duik16_api.jsxinc'
    //Now the Duik API is available in the Duik object, and DuAEF is also available.

    //We need to initialize DuAEF before using it. You must provide a script name and version.
    DuAEF.init("Your Awesome Script Name", "1.0.2");

    //Now you can create your UI if any, and initialize what you need.
    //DuAEF can be of great help, it has a lot of methods for creating the UI, handle After Effects, and more.
    //Read the reference at duaef-reference.rainboxlab.org

    //When everything is ready and before using the Duik API,
    //We need to tell DuAEF we're entering run state so it can finish to prepare its stuff.
    DuAEF.enterRunTime();

    // Create a hominoid structure
    // The whole API is contained in the Duik object
    Duik.structures.mammal();
    // Select all Structures
    Duik.structures.select();
    // Run the Autorig
    Duik.constraints.autorig();
    // Select all controllers
    Duik.controllers.select();
    // Make the character walk!
    Duik.automation.walk();
    //Have Fun!
})(this);

Locked