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:
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?
Comments
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:
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.
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:
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! 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.