Adding CustomAction to a *.duf file via script

Had enough of losing custom action menu, so I wrote a script that reads a CSV file to create a Scripts menu. The script is heavily based on the example from Daz Studio here:

http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/actions/action_custom_create/start

But noticed something weird... CustomActions pointing to *.dse and *.dsa files launch from the menu. However, if the CustomAction points to a *.duf file... the custom action will be added to the menu, yet it does nothing when launched from the menu.

This can be tested by using the example above script above, and editing the variables to point to a Materials setting (using the absolute path to *.duf file, such as a Material preset):

sActionMenu = "&Scripts/Testing";sActionToolbar = "Metal - Aluminum - Brushed";sActionText = "Metal - Aluminum - Brushed";sActionDesc = "Content Library - /Shader Presets\Iray/DAZ Uber/Metal - Aluminum - Brushed.duf";sActionFilePath = "E:/DAZContent/Studio/My Library/Shader Presets\Iray/DAZ Uber/Metal - Aluminum - Brushed.duf";sActionIconPath = "E:/DAZContent/Studio/My Library/Shader Presets\Iray/DAZ Uber/Metal - Aluminum - Brushed.png";sActionName = createCustomAction( sActionText, sActionDesc, sActionFilePath, sActionIconPath, true );

Then, if I highlight an object, and clicking the Menu shortcut that the script created - nothing happens.

HOWEVER, if I create a CustomAction to "Metal - Aluminum - Brushed" using the right click method, it works.

Something seems different with *.duf files and inserting the CustomAction using oMenu.insertCustomAction( sAction, nIndex ); vs. *.dse/*.dsa files; or using the Right Click method.

Any ideas?

Post edited by gripper4hire on

Comments

  • OmnifluxOmniflux Posts: 363

    DzActionMgr::addCustomAction takes a script as an argument, not just any file.

    If you use the right click method, and then examine the action it creates, you will see that it added a script to the action that loads the duf file. With minor modification you can reuse this script and use addCustomAction with isFile=False to do what you want.

  • Ah, thanks! 

    I'll try using something like:

    var oContentMgr = App.getContentMgr();oContentMgr.openFile("<abspath_to_duf_file>.duf", true);

    As the source of the customaction using the isFile=False *if* the file extension returned from the line in the CSV file has a ".duf" extension. I'll report back if this works when I next have a chance to implement the change.

  • gripper4hiregripper4hire Posts: 7
    edited October 2022

    And... it works! Although the code I had tried initially (just using openFile) didn't work.

    As an FYI, the custom action script DAZ studio wraps around a DUF file when using Right-Click -> Create CustomAction... is the following:

    //Example Custom Action script that is created when Right-Click->Create Custom Action on G8F DUF file.//In the example, the DAZ Library is located in "D:\Daz Studio Content\My Library"//This works for adding to the menu, after passing the code below as a string, //  and using the bFile=False(function(){	var sRelativePath = '/People/Genesis 8 Female/Genesis 8 Basic Female.duf';	var sPreferredPath = 'D:/Daz Studio Content/My Library/People/Genesis 8 Female/Genesis 8 Basic Female.duf';	var oScript = new DzScript();	var sSupportPath = String('%1/support/DAZ/dzCustomActionLoadFile').arg(App.getScriptsPath());	var sScriptPath = oScript.getScriptFile(sSupportPath);	var oFileInfo = new DzFileInfo(sScriptPath);	var sTitle = qsTr('Critical Error');	var sMesssage = '';	var sButton = qsTr('&OK');	if (oFileInfo.exists()){		if(oScript.loadFromFile(oFileInfo.absFileName())){			oScript.execute([sRelativePath, sPreferredPath]);			} else {				sMessage = qsTr('An error occurred loading the support script.%1').arg(sSupportPath);				MessageBox.critical(sMessage, sTitle, sButton);			}		} else {			sMessage = qsTr('The support script could not be found.%1').arg(sSupportPath);			MessageBox.critical(sMessage, sTitle, sButton);		}	oFileInfo.deleteLater();})();

    I had to use MainWindow.getActionMgr().getCustomActionScript( index ) to get the above, after using the right-click method on G8F.duf.

    Then... when I use bFile=false, and turn the above code snippet into a string, and pass this as the parameter to MainWindow.getActionMgr().addCustomAction for a DUF file... it works!

    After some cleanup, I'll post the code I wrote that will recreate the Scripts Menu from a CSV file.

    No more spending an hour (or more) recreating the Scripts Menu if it disappears after an upgrade, or DAZ Studio crash! smiley And no more fear of creating a huge Custom Action menu with lots of links that might disappear unexpectedly! It takes seconds to recreate a Scripts menu with hundreds of shortcuts.

    Post edited by gripper4hire on
Sign In or Register to comment.